How to filter out the data between a start and end date using filterPredicate in Angular Material Data Table?

北城余情 提交于 2020-01-03 03:27:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!