Annual monthly aggregation


(Emmanuel Mathot) #1

Hello,

I'd like to perform an aggregation based on the month on the year.
Typically, it would like a date_histogram or a date_range but only based on
the month. In other words, I'd like to aggregate all the January's,
February's, March's ...
FYI, the field from which I perform the aggregation is a date.

Thanks for your help

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9b83aaac-2a44-4659-bd5e-bc8f3daae62d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Ramy) #2

Have you tried something like that:

...
"date_histogram" : {
"field" : "date",
"interval" : "month",
"format" : "M"
}
...

And the link for the date format:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern

Am Mittwoch, 20. August 2014 14:56:47 UTC+2 schrieb Emmanuel Mathot:

Hello,

I'd like to perform an aggregation based on the month on the year.
Typically, it would like a date_histogram or a date_range but only based on
the month. In other words, I'd like to aggregate all the January's,
February's, March's ...
FYI, the field from which I perform the aggregation is a date.

Thanks for your help

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/14d37f68-fdaf-4b00-8248-77efb5f17179%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Emmanuel Mathot) #3

I finally managed it with this

"aggregations": {
"time": {
"terms": {
"script": "new java.text.SimpleDateFormat('MM').format(new
Date(_doc.time.value))"
}
}
}
}

Thank you

On Wednesday, August 20, 2014 3:53:35 PM UTC+2, Ramy wrote:

Have you tried something like that:

...
"date_histogram" : {
"field" : "date",
"interval" : "month",
"format" : "M"
}
...

And the link for the date format:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern

Am Mittwoch, 20. August 2014 14:56:47 UTC+2 schrieb Emmanuel Mathot:

Hello,

I'd like to perform an aggregation based on the month on the year.
Typically, it would like a date_histogram or a date_range but only based on
the month. In other words, I'd like to aggregate all the January's,
February's, March's ...
FYI, the field from which I perform the aggregation is a date.

Thanks for your help

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/96a5f2a6-55ad-4037-bdcf-ab9331b8fba1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4