I would like to use date range query like the following :
{
"range" : {
"deadline" : {
"gte" : "2016-12-14",
}
}
}
My index contains empty values for deadline as well. I would like to get those null dated documents in search results along with the dates in range. How can I combine date range with "must_not" exist query in elastic 5.x
I think a bool query would do the trick.
{
"query": {
"bool": {
"should": [
{
"range": {
"deadline": {
"gte": "2016-12-14"
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "deadline"
}
}
}
}
]
}
}
}
In Elasticsearch indexes null values don't exist, so we use the exist query. Using the missing query would been less verbose, but it's deprecated since 2.2.
I don't have enough information so my example runs in query context, but maybe filter context would be more convenient in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With