Created
December 2, 2016 12:14
-
-
Save mbrenig/2f426b1900a63be14296df327123851b to your computer and use it in GitHub Desktop.
Elasticsearch Query Example.
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 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