Answer the question
In order to leave comments, you need to log in
How to search by date in Elasticsearch?
Please tell me how to solve the problem.
There is such an entity plan:
{
"_id": "1",
"active_from": null,
}
{
"_id": "2",
"active_from": "2017-10-11"
}
{
"_id": "3",
"active_from": "2017-11-20"
}
Answer the question
In order to leave comments, you need to log in
I'll answer myself
1. The AND and OR conditions are replaced by the keywords MUST and SHOULD, respectively.
2. It is impossible to check the value specifically for NULL. Fields with this value are considered missing, so you need to check for the existence of the field through the EXISTS keyword, and not its value. It is also impossible to make the condition "the field is absent", but it is possible to wrap the "field is present" in "and not" through MUST_NOT.
Or you can set a default value through mapping, which will be substituted automatically if the field had a NULL value and then look for it.
The result is a query like this:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must_not": {
"exists" : { "field" : "active_from" }
}
}
},
{
"range": {
"active_from": {
"lte": "2017-10-24",
"format": "yyyy-MM-dd"
}
}
}
]
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question