# Does Elastic support six month date histogram?

**URL:** <https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540>\
**Category:** Elasticsearch\
**Created:** [May 4, 2018, 12:58am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540 "2018-05-04T00:58:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)\
**Post date:** [May 4, 2018, 12:58am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/1 "2018-05-04T00:58:19Z")

</div>

We use ES 5.4.

Per [Date Histogram](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html) article, there does not seem to be an option to request six months histogram.

> Available expressions for interval: year (1y), quarter (1q), month (1M), week (1w), day (1d), hour (1h), minute (1m), second (1s)

> Also note that time intervals larger than than days do not support arbitrary values but can only be one unit large (e.g. 1y is valid, 2y is not).

Scripting also does not seem to support this since it uses DateFields mentioned on the [website](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-expression.html#_date_field_api)

I was wondering if there is a workaround for this. Thanks so much.

---

<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:** [May 4, 2018, 3:43am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/2 "2018-05-04T03:43:29Z")

</div>

What I'm doing in such case is using approximation in days. Like 10years is around 3652 days...

---

<div class="post-metadata">

**Author:** ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)\
**Post date:** [May 4, 2018, 4:40am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/3 "2018-05-04T04:40:57Z")

</div>

works well for approximations. I am not sure our clients will like that. There could be many corner cases (e.g. leap year, DST, etc...). Also, does not account for the year. Its just 182d relative to today's date if I understand this right.

---

<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:** [May 4, 2018, 5:20am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/4 "2018-05-04T05:20:07Z")

</div>

Corner cases are the reason why this has not be implemented for now.

See

> <https://github.com/elastic/elasticsearch/issues/8939>

---

<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:** [May 4, 2018, 5:23am UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/5 "2018-05-04T05:23:48Z")

</div>

A workaround could be to index a keyword field like:

"2018-1st-half"  
"2018-2nd-half"

And run a terms agg on it.

---

<div class="post-metadata">

**Author:** ![animageofmine](https://avatars.discourse-cdn.com/v4/letter/a/7feea3/32.png) [@animageofmine](https://discuss.elastic.co/u/animageofmine)\
**Post date:** [May 4, 2018, 3:02pm UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/6 "2018-05-04T15:02:00Z")

</div>

Thank you David. I read that thread you shared yesterday (see my comment in that 🙂).

The pre-processing workaround is a smart idea, but unfortunately not feasible for us. What we attempted to do was to run a script that calculates whether it is 1st or last 6 months of the year. This takes forever if the index is large and leads to OOM error since the query performs a linear scan on the index along with some processing.

---

<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:** [May 4, 2018, 5:19pm UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/7 "2018-05-04T17:19:52Z")

</div>

Of course it is. That's why you should do that index time.

---

<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:** [June 1, 2018, 5:19pm UTC](https://discuss.elastic.co/t/does-elastic-support-six-month-date-histogram/130540/8 "2018-06-01T17:19:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
