# How the fixed\_interval time buckets were divided in date\_histogram aggregation?

**URL:** <https://discuss.elastic.co/t/how-the-fixed-interval-time-buckets-were-divided-in-date-histogram-aggregation/228646>\
**Category:** Elasticsearch\
**Created:** [April 18, 2020, 1:21pm UTC](https://discuss.elastic.co/t/how-the-fixed-interval-time-buckets-were-divided-in-date-histogram-aggregation/228646 "2020-04-18T13:21:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![STAR\_DEVX](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/star_devx/32/61000_2.png) [@STAR\_DEVX](https://discuss.elastic.co/u/STAR_DEVX)\
**Post date:** [April 18, 2020, 1:21pm UTC](https://discuss.elastic.co/t/how-the-fixed-interval-time-buckets-were-divided-in-date-histogram-aggregation/228646/1 "2020-04-18T13:21:30Z")

</div>

Hi, I'm puzzled with the how the time buckets are divided with the fixed\_interval in date\_histogram aggregations. I have the following simple query:

```auto
{
  "query": {
    "bool": {
      "filter": [
        {"range": {"startTime": {"gte": "2020-03-01", "lte": "2020-03-14" } } }
      ]
    }
  },
 "aggs": {
        "my_buckets": {
          "date_histogram": { "fixed_interval": "7d", "field": "startTime" }
        }
    }
}

```

As you can see I want the data from 2020-03-01 to 2020-03-14, then I want the aggregation to be 7 days. My intuitive feeling was that elastic should give me two 7 day buckets, (2020-03-01 -\> 2020-03-07), then (2020-03-08 -\> 2020-03-14).

However, it's not the case. Elastic gives me 3 buckets. (Thursday 2020-02-27 -\> Wednesday 2020-03-04), (Thursday 2020-03-05 -\> Wednesday 2020-03-11) and (Thursday 2020-03-12 -\> Wednesday 2020-03-19), the time bucket does NOT align with the start or end of my range, OR the calendar week.

I also tried different indexes, different query time ranges, but as long as my fixed\_interval gives 7d, it always returns Thursday to Wednesday time buckets.

This gives me the feeling that the data were probably pre-aggregated in the Thursday to Wednesday buckets in side elastic search. So elastic cannot give me dynamic 7 days time bucket based on my query time range. If my suspicion was true, this is quite a big limitation to my use cases

Much appreciate if some one can help me understand the logic of the elastic date\_histogram aggregation!

---

<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:** [May 16, 2020, 1:21pm UTC](https://discuss.elastic.co/t/how-the-fixed-interval-time-buckets-were-divided-in-date-histogram-aggregation/228646/2 "2020-05-16T13:21:33Z")

</div>

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