Elasticsearch server 2.4.1
elasticsearch-py 2.4.0
elasticsearch-dsl-py 2.1.0
I am trying to filter all documents that do not have a thumbnails field.
# mapping is a DocType object
search = Search(index=mapping._index,
doc_type=mapping._doc_type.name)
# The query_list variable is a list of Q objects built
# from the query parameters of the request
query_list = [...]
search.query = Q('bool', must=query_list)
search.filter('exists', field='thumbnails')
res = search.execute(ignore_cache=True)
for hit in res.hits:
foo = hit.thumbnails
Using this filter syntax, all the documents matching the query are returned, even though none of the documents currently in my index have a thumbnails field.
The documentation is severely lacking. This syntax was taken from the library author's recommendation in another bug report.
.query and .filter methods are returning a modified copy of the Search object. You need to do search = search.filter(...).
Most helpful comment
.queryand.filtermethods are returning a modified copy of theSearchobject. You need to dosearch = search.filter(...).