Skip to content

Instantly share code, notes, and snippets.

@mykoweb
Created December 20, 2016 08:02
Show Gist options
  • Save mykoweb/4e75c2fe2a18fa2fe3c2a8e3083283c0 to your computer and use it in GitHub Desktop.
Save mykoweb/4e75c2fe2a18fa2fe3c2a8e3083283c0 to your computer and use it in GitHub Desktop.
# It's a good idea to disable refresh when indexing documents to improve performance
client.indices.put_settings index: 'PatientA', body: { refresh_interval: -1 }
client.indices.put_settings index: 'PatientB', body: { refresh_interval: -1 }
# Now index (store) the documents
patient_a_doc1 = {
patient_name: 'PatientA',
content: 'The quick brown fox'
}
patient_a_doc2 = {
patient_name: 'PatientA',
content: 'It was a dark and stormy night'
}
patient_b_doc1 = {
patient_name: 'PatientB',
content: 'Two roads diverged in a yellow wood'
}
patient_b_doc2 = {
patient_name: 'PatientB',
content: 'Lorem ipsum dolor sit amet'
}
bulk_index_body = [
{ index: { _index: 'PatientA', _type: 'patient_type', data: patient_a_doc1 } },
{ index: { _index: 'PatientA', _type: 'patient_type', data: patient_a_doc2 } },
{ index: { _index: 'PatientB', _type: 'patient_type', data: patient_b_doc1 } },
{ index: { _index: 'PatientB', _type: 'patient_type', data: patient_b_doc2 } }
]
client.bulk body: bulk_index_body
# Don't forget to enable refresh
client.indices.put_settings index: 'PatientA', body: { refresh_interval: '30s' }
client.indices.put_settings index: 'PatientB', body: { refresh_interval: '30s' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment