Skip to content

Instantly share code, notes, and snippets.

@mykoweb
Created December 20, 2016 07:59
Show Gist options
  • Save mykoweb/9121016f0d7f331b02c8e18e39997fb3 to your computer and use it in GitHub Desktop.
Save mykoweb/9121016f0d7f331b02c8e18e39997fb3 to your computer and use it in GitHub Desktop.
def raw_put(path, body)
conn = Faraday.new url: 'http://localhost:9200'
conn.put(path) do |req|
req.body = body.to_json
req.headers['Content-Type'] = 'application/json'
end
end
# Create primary index
req_body = {
settings: {
index: {
number_of_shards: 5, # In production, this number would be much larger
number_of_replicas: 1
}
},
mappings: {
patient_type: {
properties: {
patient_name: { index: 'not_analyzed', type: 'string' },
content: { index: 'not_analyzed', type: 'string' }
}
}
}
}
raw_put 'patients', req_body
client.indices.exists? index: 'patients' # => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment