# Extended\_bounds causes extra bucket

**URL:** <https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816>\
**Category:** Elasticsearch\
**Created:** [June 14, 2019, 9:22am UTC](https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816 "2019-06-14T09:22:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lonzodc](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lonzodc](https://discuss.elastic.co/u/lonzodc)\
**Post date:** [June 14, 2019, 9:22am UTC](https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816/1 "2019-06-14T09:22:27Z")

</div>

Hi,

I am using date\_histogram to get data in buckets grouped by time. Interval is weekly with offset of -1d, and time\_zone is +08:00. The min value is equal to the "gte". When using extended\_bounds, I get an extra bucket for the week before if the query starts on Sunday.

My guess is the offset is not being accounted for in the extended bounds. Is this the case?

Thanks.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [June 21, 2019, 2:15pm UTC](https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816/2 "2019-06-21T14:15:05Z")

</div>

Can you paste the query and response? What are you setting the extended\_bounds to?

---

<div class="post-metadata">

**Author:** ![lonzodc](https://avatars.discourse-cdn.com/v4/letter/l/f08c70/32.png) [@lonzodc](https://discuss.elastic.co/u/lonzodc)\
**Post date:** [July 15, 2019, 7:22am UTC](https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816/3 "2019-07-15T07:22:31Z")

</div>

Hi,

Sorry for the late reply. Here it is:

```
POST my_index/my_type/_search
{
  "query": {
"bool": {
  "must": [
    {
      "range": {
        "transactionTime": {
          "gte": "2018-10-28T00:00:00+08:00",
          "lte": "2018-12-30T23:53:53+08:00",
          "time_zone": "+08:00"
        }
      }
    },
    {
      "match": {
        "name": "John.Doe"
      }
    },
    {
      "terms": {
        "action": [
          "CHECKIN",
          "CHECKOUT",
          "CANCELLED"
        ]
      }
    }
  ]
    }
  },
  "aggs": {
"group_by_action": {
  "terms": {
    "field": "action",
    "min_doc_count": 0
  },
  "aggs": {
    "group_by_interval": {
      "date_histogram": {
        "field": "transactionTime",
        "offset": "-1d",
        "interval": "1w",
        "time_zone": "+08:00",
        "min_doc_count": 0,
        "extended_bounds": {
          "min": 1540656000000,
          "max": 1546185233000
        }
      }
    }
  }
}
  }
}

```

The output will have a bucket that includes October 21, 2018 instead of starting with October 28.

---

<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:** [August 12, 2019, 7:31am UTC](https://discuss.elastic.co/t/extended-bounds-causes-extra-bucket/185816/4 "2019-08-12T07:31:27Z")

</div>

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