# Filter by only month of date field in \_search

**URL:** https://discuss.elastic.co/t/filter-by-only-month-of-date-field-in-search/129902
**Category:** Elasticsearch
**Created:** [April 28, 2018, 4:52am UTC](https://discuss.elastic.co/t/filter-by-only-month-of-date-field-in-search/129902 "2018-04-28T04:52:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Paddy\_Mahadeva](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paddy_mahadeva/32/44225_2.png) [@Paddy\_Mahadeva](https://discuss.elastic.co/u/Paddy_Mahadeva)
#### Post date: [April 28, 2018, 4:52am UTC](https://discuss.elastic.co/t/filter-by-only-month-of-date-field-in-search/129902/1 "2018-04-28T04:52:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [May 26, 2018, 4:52am UTC](https://discuss.elastic.co/t/filter-by-only-month-of-date-field-in-search/129902/2 "2018-05-26T04:52:39Z")

</div>

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