问题
In my data table I have a Start date column and an end date column. And I need to filter out the data in the table between the start and end dates. And using this post , I was able to write the filter Predicate. But it only filters the exact start date and exact end date. The API returns the date in a string format like "2018-08-30". So, how to filter out the data between the start and end dates ?
回答1:
First, you need to add the Range filter, or Range must in your query to get the result set between the required dates. Once you got the correct result set, then you can aggregation and filter the data according to you requirement.
POST _search
{
"query": {
"bool": {
"filter": [
{
"range": {
"endDate": {
"gte": "2018-07-30",
"format": "yyyy-MM-dd"
}
}
},
{
"range": {
"startDate": {
"lte": "2018-08-30",
"format": "yyyy-MM-dd"
}
}
}
]
}
}
}
Hope this will solve you problem.
来源:https://stackoverflow.com/questions/52144473/how-to-filter-out-the-data-between-a-start-and-end-date-using-filterpredicate-in