Date histogram 6 months interval

Hello,

I just wonder whether I can draw the vertical bar with 6 months interval. I see that it supports other units but I cannot find an example of having half a year interval.

Thank you!

You can type into the "Minimum interval" input the value 6M which is 6 months. quarter is not a valid date unit.

First of all, thank you for your reply!

I saw that quarter unit from this link. Date histogram aggregation | Elasticsearch Guide [7.12] | Elastic
Have I understand incorrectly? because the values come out with quarter interval as I expected.

And, minimum interval you suggested gives me an error as below...

If I use '183d'(which is round up days for 6 months period) as minimum interval, it works but I think minimum interval starts from the date of first value.

Would you possible to provide another suggestion that I can have interval from January to June and July to December regardless the values?

"Minimum" in this context refers to the fact that Kibana will scale up the interval if there would be too many buckets otherwise (by default more than 200). For your use case it doesn't seem relevant.

I believe the problem you hit with using 6M is alrareadz reported in this issue: Date histogram minimum interval cannot be multiple of weeks · Issue #97162 · elastic/kibana · GitHub

Thank you for your reply.

So if that is the case, is it correct that I cannot set the interval as 6 months(Jan-June, July-Dec) at the moment?

I stand corrected that quarter and 1q are valid calendar intervals, but you can't do 2q or 6M because the calendar intervals can't be multiplied.

As a workaround, here are your options:

  • Use the Filters or Date Range aggregation to manually create the 6 month intervals. For example, date >= 2021-01-01 AND date < 2021-07-01
  • Create a runtime or scripted field using Painless scripting to manually determine which half of the year you're in, for example if the date is in July you could return 2H as your scripted date. See the docs here for examples: Using Datetime in Painless | Painless Scripting Language [7.13] | Elastic
1 Like

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