Skip to content

Instantly share code, notes, and snippets.

@willf
Created June 22, 2015 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willf/5f36c2cfb8512acabb24 to your computer and use it in GitHub Desktop.
Save willf/5f36c2cfb8512acabb24 to your computer and use it in GitHub Desktop.
Simple elastic search calls
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.create(index="test", doc_type="articles", body={"content": "One more fox"})
res = es.search(index="test", doc_type="articles", body={"query": {"match": {"content": "fox"}}})
print("%d documents found" % res['hits']['total'])
for doc in res['hits']['hits']:
print("%s) %s" % (doc['_id'], doc['_source']['content']))
@willf
Copy link
Author

willf commented Jun 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment