Skip to content

Instantly share code, notes, and snippets.

@toravir
Created April 4, 2020 03:03
Show Gist options
  • Save toravir/7706d662a697f9943adf5252d81370a2 to your computer and use it in GitHub Desktop.
Save toravir/7706d662a697f9943adf5252d81370a2 to your computer and use it in GitHub Desktop.
Python Client For Elasticsearch
from elasticsearch import Elasticsearch
indexName='tstidx1'
es = Elasticsearch([{'host':'sprint.cisco.com', 'port':9200}])
es.info()
indexBody= {
"settings" : {
"number_of_shards": 1,
"number_of_replicas" : 0
}
}
if not es.indices.exists(indexName):
es.indices.create(index=indexName, body=indexBody)
docBody = { "foo" : "bar", "price" : 100}
es.create(id=100, index=indexName, doc_type='people', body=docBody)
print (es.get(index=indexName, doc_type='people', id=100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment