Filter by only month of date field in _search

Hi,

I have a case where in I need to find all documents in my index that fall between given set of months irrespective of the year

_search
{
  "query": {
    "bool": {
          "filter" : {
          "range" : {
            "first_elig_date" : {
              "gte" : "2018||/y",
              "lte" : "2016||/y",
              "format" : "yyyy" 
            }
          }
        }
    }  
  }
}

The above piece of code works well to filter by year. But when I modify it to do the same by month it does not work.

_search
{
  "query": {
    "bool": {
          "filter" : {
          "range" : {
            "first_elig_date" : {
              "gte" : "01||/M",
              "lte" : "05||/M",
              "format" : "MM" 
            }
          }
        }
    }  
  }
}

Here the format of the field first_elig_date is yyyy-MM-dd. Why is it that this is not working?

Thanks
Paddy

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.