I am using elasticsearch-py (es version is 2.3) and would like to return just the 'title' field from all documents in an index with the mapping: actors, director, genre, plot, title, year.
I'm currently trying messages = es.search(index="movies", _source=['hits.hits.title'])
and the resulting response is:
{u'hits': {u'hits': [{u'_score': 1.0, u'_type': u'movie', u'_id': u'tt0116996', u'_source': {}, u'_index': u'movies'}, {u'_score': 1.0, u'_type': u'movie', u'_id': u'1', u'_source': {}, u'_index': u'movies'}], u'total': 2, u'max_score': 1.0}, u'_shards': {u'successful': 1, u'failed': 0, u'total': 1}, u'took': 2, u'timed_out': False}
I've tried different versions of filter paths and source field lists but can't seem to get it right.
You can apply source filtering with:
messages = es.search(index="movies", _source=["title"])
but you'll still need to parse the response. For this you can do something like:
titles = [hit["title"] for hit in messages["hits"]["hits"]["_source"]]]
There is nothing in the elasticsearch-py API (as far as I know) that will flatten down the rather verbose response you get from Elasticsearch.