Skip to content

Instantly share code, notes, and snippets.

@mbrenig
Created December 2, 2016 12:14
Show Gist options
  • Save mbrenig/2f426b1900a63be14296df327123851b to your computer and use it in GitHub Desktop.
Save mbrenig/2f426b1900a63be14296df327123851b to your computer and use it in GitHub Desktop.
Elasticsearch Query Example.
import json
from pprint import pprint
from elasticsearch import Elasticsearch # pip install elasticsearch
host = 'corpus.metaswitch.com'
es = Elasticsearch(hosts=[host])
query = {
"_source": ["html", "id", "subject", "breadcrumbs.title", "replyCount" ],
"size" : 100,
"query": {
"bool": {
"must": [
{
"range": {
"replyCount": {
"gte": 1
}
}
},
{
"term": {
"archived": False
}
},
{
"nested": {
"path": "breadcrumbs",
"query": {
"match": {
"breadcrumbs.title": "Mosaic"
}
}
}
}
]
}
}
}
results = es.search(index="document", doc_type='communities', body=query)
for result in results['hits']['hits']:
print "%(replyCount)s\tDOC-%(id)s\t%(subject)s." % result['_source']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment