Created
June 22, 2015 13:15
-
-
Save willf/5f36c2cfb8512acabb24 to your computer and use it in GitHub Desktop.
Simple elastic search calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From http://marcobonzanini.com/2015/02/02/how-to-query-elasticsearch-with-python/