I thought it must obviously be
s=Search(using=client).filter("missing", field="year")
but that gives me
elasticsearch_dsl.exceptions.UnknownDslObject: DSL classmissingdoes not exist in query.
I am new to the DSL search API, so I probably misunderstood something.
The problem I'm trying to solve is simply returning all hits which have a null in the year field. Should I be doing something differently?
I found this: https://github.com/elastic/elasticsearch-dsl-py/issues/757 but I don't understand where I would insert the negation. I have only been working with the Search object and I don't know when one would use a Query object.
Update:
Ah, I just ran across the .exclude(), which seems to do the trick. I have not run across that in the ElasticSearch DSL as I've been reading, but I guessed based on how it would work for the Django ORM.
It gets you documents with a null for that field, but it does not recover documents which the field "does not exist" in the sense the key isn't there. I suppose that would be unnecessarily broad, so it makes sense!
I hope this post helps someone later.
the missing query has been removed from elasticsearch so the correct way is indeed to use .exclude('exists', field='year') or just the underlying .filter(~Q('exists', field='year')).
Hope this helps!
Most helpful comment
the
missingquery has been removed from elasticsearch so the correct way is indeed to use.exclude('exists', field='year')or just the underlying.filter(~Q('exists', field='year')).Hope this helps!