“Day Of Month” aggregation

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.



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

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