0

I'm trying to get aggregated information from a datetime field:

  • Get how many documents are there by month (NOT YEAR/MONTH!, ONLY MONTH): So, a 'groupby(month(datetime_field))'.

Thanks for all.

Sumit
  • 2,190
  • 23
  • 31
Jordi
  • 20,868
  • 39
  • 149
  • 333

1 Answers1

1

You can use format parameter of date-histogram aggregation and chose only month field in that. Your aggregation would look like

{
  "aggs": {
    "documents_by_month": {
      "date_histogram": {
        "field": "date",
        "interval": "1M",
        "format": "MM"
      },
      "aggs": {
        "documents": {
          //... your sub aggregation
        }
      }
    }
  }
}
Sumit
  • 2,190
  • 23
  • 31
  • @Jordi May I know what was the reason for unaccepting the answer, is this not working for you? – Sumit Aug 11 '16 at 17:00