# Elasticsearch Datehistogram Interval

**URL:** <https://discuss.elastic.co/t/elasticsearch-datehistogram-interval/308367>\
**Category:** Elasticsearch\
**Created:** [June 28, 2022, 1:52pm UTC](https://discuss.elastic.co/t/elasticsearch-datehistogram-interval/308367 "2022-06-28T13:52:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soumen\_Das](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumen_das/32/107682_2.png) [@Soumen\_Das](https://discuss.elastic.co/u/Soumen_Das)\
**Post date:** [June 28, 2022, 1:52pm UTC](https://discuss.elastic.co/t/elasticsearch-datehistogram-interval/308367/1 "2022-06-28T13:52:27Z")

</div>

I am creating a date histogram aggregation like this, where min and max of extended\_bounds are unix epoch values.

```auto
    "aggs": {
        "0": {
          "date_histogram": {
            "field": "@timestamp",
            "fixed_interval": "30s",
            "time_zone": "Asia/Kolkata",
            "extended_bounds": {
              "min": 1656419435318,
              "max": 1656420335318
            }   
          }
        }
      }

```

Now I am using " **30s**" as hard-coded value for fixed\_interval value.

How can this value be dynamically generated depending on the duration of the bounds (min & max of extended bounds), if I want same number of buckets for each duration? Is there any function available from any kibana plugins for this purpose?

For example if I want 30 buckets:

> (a) for 1 hour duration, fixed\_interval will be 2 mins
> 
> (b) for 24 hours, fixed\_interval will be 45 mins

I can write code of own to do this calculation, but any existing api would be helpful.

Also, when to use **calendar\_interval** in place of **fixed\_interval**. I have checked **kibana lens** generated queries, where depending of search duration fixed\_interval or calendar\_interval is used.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 28, 2022, 11:47pm UTC](https://discuss.elastic.co/t/elasticsearch-datehistogram-interval/308367/2 "2022-06-28T23:47:54Z")

</div>

Welcome to our community! 😃

I don't think there is a way to do this automatically unfortunately, it's not something I have seen a lot of people ask for. It might make an interesting feature request if you wanted to raise it?

> [@Soumen\_Das](#):
>
> Also, when to use **calendar\_interval** in place of **fixed\_interval**

To quote the docs - [Date histogram aggregation | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#calendar_and_fixed_intervals);

> When configuring a date histogram aggregation, the interval can be specified in two manners: calendar-aware time intervals, and fixed time intervals.
> 
> Calendar-aware intervals understand that daylight savings changes the length of specific days, months have different amounts of days, and leap seconds can be tacked onto a particular year.
> 
> Fixed intervals are, by contrast, always multiples of SI units and do not change based on calendaring context.

---

<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 26, 2022, 11:48pm UTC](https://discuss.elastic.co/t/elasticsearch-datehistogram-interval/308367/3 "2022-07-26T23:48:50Z")

</div>

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