Does Elastic support six month date histogram?

(Animageofmine) #1

We use ES 5.4.

Per Date Histogram 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

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

(David Pilato) #2

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

(Animageofmine) #3

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.

(David Pilato) #4

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


(David Pilato) #5

A workaround could be to index a keyword field like:


And run a terms agg on it.

(Animageofmine) #6

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

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.

(David Pilato) #7

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

(system) #8

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