Skip to content

Instantly share code, notes, and snippets.

@phobos182
Last active August 29, 2015 13:58
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 phobos182/10431629 to your computer and use it in GitHub Desktop.
Save phobos182/10431629 to your computer and use it in GitHub Desktop.
Example ES Client
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