Elasticsearch-dsl-py: Exists filter not being applied.

Created on 8 Nov 2016  路  1Comment  路  Source: elastic/elasticsearch-dsl-py

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.

Most helpful comment

.query and .filter methods are returning a modified copy of the Search object. You need to do search = search.filter(...).

>All comments

.query and .filter methods are returning a modified copy of the Search object. You need to do search = search.filter(...).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

berinhard picture berinhard  路  3Comments

barseghyanartur picture barseghyanartur  路  4Comments

abuzakaria picture abuzakaria  路  4Comments

quasiben picture quasiben  路  4Comments

vanzi picture vanzi  路  4Comments