# “Day Of Month” aggregation

**URL:** <https://discuss.elastic.co/t/day-of-month-aggregation/51750>\
**Category:** Elasticsearch\
**Created:** [June 3, 2016, 1:03am UTC](https://discuss.elastic.co/t/day-of-month-aggregation/51750 "2016-06-03T01:03:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paulo\_Henrique\_PH](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paulo_henrique_ph/32/14831_2.png) [@Paulo\_Henrique\_PH](https://discuss.elastic.co/u/Paulo_Henrique_PH)\
**Post date:** [June 3, 2016, 1:03am UTC](https://discuss.elastic.co/t/day-of-month-aggregation/51750/1 "2016-06-03T01:03:29Z")

</div>

Ive been trying to get an Elasticsearch date histogram aggregation of the "Day Of Month" (buckets must be from 1 to 31).

For example, when I'm aggreghating by "Month and Year" I just use:

```
GET /index_sample/_search?search_type=count
{
    "aggs" : {
        "Test" : {
            "date_histogram" : {
                "field" : "LAST_MODIFIED_DATE",
                "interval" : "month",
                "format" : "yyyyMM",
                "time_zone": "-02:00"
            }
        }
    }
}

```

Does anybody knows how to achieve it using Date Histogram approach?

As the application here needs Time Zone support for all date dimensions, seems like the best way to go.

Thanks

---

<div class="post-metadata">

**Author:** ![knights](https://avatars.discourse-cdn.com/v4/letter/k/7c8e57/32.png) [@knights](https://discuss.elastic.co/u/knights)\
**Post date:** [June 3, 2016, 8:44am UTC](https://discuss.elastic.co/t/day-of-month-aggregation/51750/2 "2016-06-03T08:44:13Z")

</div>

Hello,

You will not do it with a date histogram, but with a scripted terms aggregation

Something like :

```
 "myAgg" : {
      "terms" : {
           "script" : "doc['LAST_MODIFIED_DATE'].date.dayOfMonth",
           "size" : 31
      }
 }

```

The script's syntax depends on the langage. Here, it's groovy.

Alternatively, you can reindex your data to have a new field containing the day of the month. No script needed, that way.

Hope it helps

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 4, 2016, 8:02am UTC](https://discuss.elastic.co/t/day-of-month-aggregation/51750/3 "2016-06-04T08:02:26Z")

</div>

I think this is something that we are working on adding in future releases 🙂

---

<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:** [July 5, 2017, 10:46pm UTC](https://discuss.elastic.co/t/day-of-month-aggregation/51750/4 "2017-07-05T22:46:12Z")

</div>


