Combine elasticsearch search date range queries with null values

I would like to use a date range query as follows:

{ "range" : { "deadline" : { "gte" : "2016-12-14", } } } 

My index also contains empty values ​​for the deadline. I would like to get these zero documents in the search results along with dates in the range. How to combine date range with "must_not" query in elastic 5.x

+6
source share
1 answer

I think the bool request will do the trick.

 { "query": { "bool": { "should": [ { "range": { "deadline": { "gte": "2016-12-14" } } }, { "bool": { "must_not": { "exists": { "field": "deadline" } } } } ] } } } 

Null values ​​do not exist in Elasticsearch indexes, so we are using an existing query. Using a missing query would be less verbose, but deprecated since 2.2 .

I don’t have enough information, so my example works in the context of the request, but perhaps the filter context will be more convenient in this case.

+5
source

Source: https://habr.com/ru/post/1013145/


All Articles