Reputation: 5107
I have a query that looks like this (using Elasticsearch DSL v0.0.11)
s = s.filter(
'or',
[
F('term', hide_from_search=False),
F('not', filter=F('exists', field='hide_from_search')),
]
)
How would I write that using v2.x? When the F
function has gone?
With the Q
function somehow?
Upvotes: 1
Views: 105
Reputation: 217354
You can do it like this:
q = Q('bool',
should=[
Q('term', hide_from_search=False),
~Q('exists', field='hide_from_search'),
],
minimum_should_match=1
)
s = Search().query(q)
Or even simpler like this:
q = (Q('term', hide_from_search=False) | ~Q('exists', field='hide_from_search'))
q.minimum_should_match = 1
s = Search().query(q)
Upvotes: 1