# Annual monthly aggregation

**URL:** <https://discuss.elastic.co/t/annual-monthly-aggregation/19367>\
**Category:** Elasticsearch\
**Created:** [August 20, 2014, 12:56pm UTC](https://discuss.elastic.co/t/annual-monthly-aggregation/19367 "2014-08-20T12:56:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emmanuel\_Mathot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emmanuel_mathot/32/1321_2.png) [@Emmanuel\_Mathot](https://discuss.elastic.co/u/Emmanuel_Mathot)\
**Post date:** [August 20, 2014, 12:56pm UTC](https://discuss.elastic.co/t/annual-monthly-aggregation/19367/1 "2014-08-20T12:56:47Z")

</div>

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/9b83aaac-2a44-4659-bd5e-bc8f3daae62d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ramy](https://avatars.discourse-cdn.com/v4/letter/r/8491ac/32.png) [@Ramy](https://discuss.elastic.co/u/Ramy)\
**Post date:** [August 20, 2014, 1:53pm UTC](https://discuss.elastic.co/t/annual-monthly-aggregation/19367/2 "2014-08-20T13:53:34Z")

</div>

Have you tried something like that:

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

And the link for the date format:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/14d37f68-fdaf-4b00-8248-77efb5f17179%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Mathot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emmanuel_mathot/32/1321_2.png) [@Emmanuel\_Mathot](https://discuss.elastic.co/u/Emmanuel_Mathot)\
**Post date:** [August 21, 2014, 6:59am UTC](https://discuss.elastic.co/t/annual-monthly-aggregation/19367/3 "2014-08-21T06:59:06Z")

</div>

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:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/96a5f2a6-55ad-4037-bdcf-ab9331b8fba1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:07am UTC](https://discuss.elastic.co/t/annual-monthly-aggregation/19367/4 "2017-07-06T01:07:18Z")

</div>


