Last active
August 29, 2015 13:58
-
-
Save phobos182/10431629 to your computer and use it in GitHub Desktop.
Example ES Client
This file contains 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
import elasticsearch | |
# Connect to cluster at search1:9200, sniff all nodes and round-robin between them | |
es = elasticsearch.Elasticsearch(["dataelasticsearch-a-master001:9200", "dataelasticsearch-b-master001:9200", | |
"dataelasticsearch-e-master001:9200"], sniff_on_start=True) | |
# Index a document: | |
es.index( | |
index="my_app", | |
doc_type="blog_post", | |
id=1, | |
body={ | |
"title": "Elasticsearch clients", | |
"content": "Interesting content...", | |
"date": "Thu Apr 10 16:26:10 PDT 2014", | |
} | |
) | |
# Get the document: | |
es.get(index="my_app", doc_type="blog_post", id=1) | |
# Search: | |
es.search(index="my_app", body={"query": {"match": {"title": "elasticsearch"}}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment