I am using MongoId with ruby on rails. For my search I am using elasticsearch.
I have a date field. It is optional field and I use it as a stop date. In my search I would like to know if my stop date is greater than the search stop date. Example
{
"range": {
"stop_date": {
"gt": "#{search_stop}"
}
}
}
The issue when the stop date is null I need it to be returned in this query, but it is not as the stop date is null or not in the document.
I need when the stop date is null or not in the document the search to be set as a default value like 21/31/2100.
Any advice will be really appreciated...
There are two approaches to this.
Second approach would be to change the query
{ "query": { "filtered": { "filter": { "or": [ { "range": { "stop_date": { "gt": "#{search_stop}" } } }, { "missing": { "field": "stop_date" } } ] } } } }
Here a document is matched if the stop_date field is missing or when the date range filter matched.
My recommendation would be to use second one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.