# Date Histogram Aggregation - decade interval

**URL:** <https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578>\
**Category:** Elasticsearch\
**Created:** [January 7, 2016, 8:34am UTC](https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578 "2016-01-07T08:34:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)\
**Post date:** [January 7, 2016, 8:34am UTC](https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578/1 "2016-01-07T08:34:59Z")

</div>

Can anybody explain how and if it is possible to build a decade interval with date histogram aggregation?

I tried interval 10y which isn't supported. As possible solution used 3650d as interval which seems to work but not completely.

Here is my agg:

```
"decades": {
       "date_histogram": {
         "field": "bc_dat",
         "interval": "3650d",
         "format": "dd.MM.yyyy"
       }
 }

```

and here are some results:

```
  "decades": {
     "buckets": [
        {
           "key_as_string": "06.01.1950",
           "key": -630720000000,
           "doc_count": 20
        },
        {
           "key_as_string": "04.01.1960",
           "key": -315360000000,
           "doc_count": 100
        },
        {
           "key_as_string": "01.01.1970",
           "key": 0,
           "doc_count": 166
        },
        {
           "key_as_string": "30.12.1979",
           "key": 315360000000,
           "doc_count": 547
        },
        {
           "key_as_string": "27.12.1989",
           "key": 630720000000,
           "doc_count": 669
        },
        {
           "key_as_string": "25.12.1999",
           "key": 946080000000,
           "doc_count": 842
        },
        {
           "key_as_string": "22.12.2009",
           "key": 1261440000000,
           "doc_count": 108
        }
     ]
  }

```

as you can see it works until 01.01.1970 but afterwards ist gets e.g. 1979 and 1989 instead of 1980 and 1990. Any ideas how to solve this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 7, 2016, 9:45am UTC](https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578/2 "2016-01-07T09:45:11Z")

</div>

It's sadly not doable ATM: [https://github.com/elastic/elasticsearch/issues/8939](https://github.com/elastic/elasticsearch/issues/8939)

What I'm doing in that case is doing that on the client side. So I build aggs per year and aggregate on client.  
Works well but if you need to have sub aggs that becomes tricky...

---

<div class="post-metadata">

**Author:** ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)\
**Post date:** [January 7, 2016, 10:13am UTC](https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578/3 "2016-01-07T10:13:42Z")

</div>

😔

anyway thank's for your fast response

---

<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, 11:26pm UTC](https://discuss.elastic.co/t/date-histogram-aggregation-decade-interval/38578/4 "2017-07-05T23:26:26Z")

</div>


