# Date historgram - forcing upper date bound

**URL:** <https://discuss.elastic.co/t/date-historgram-forcing-upper-date-bound/118826>\
**Category:** Elasticsearch\
**Created:** [February 7, 2018, 11:26am UTC](https://discuss.elastic.co/t/date-historgram-forcing-upper-date-bound/118826 "2018-02-07T11:26:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LazPix](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LazPix](https://discuss.elastic.co/u/LazPix)\
**Post date:** [February 7, 2018, 11:26am UTC](https://discuss.elastic.co/t/date-historgram-forcing-upper-date-bound/118826/1 "2018-02-07T11:26:05Z")

</div>

I am aggregating records where I have a field `samplingDate` and a field `users`.  
I want to get a weekly aggregation, where the last item in the bucket is from the last date in the range, but I cannot find a way to force it, because in the example below, the last bucket is from 2016-09-01. Thanks.

```
 {
   "query": {
     "range": {
      "samplingDate": {
        "gte": "2016-08-14",
        "lte": "2016-09-05"
      }
   }
  },
 "aggs": {
   "scannedPerMonth": {
  "date_histogram": {
    "field": "samplingDate",
    "interval": "7d"
  },
    "aggs": {
        "totalScanned": {
           "max": {
              "field": "users"
          }
      }
    }
  }
 }
 }
```

---

<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:** [March 7, 2018, 11:26am UTC](https://discuss.elastic.co/t/date-historgram-forcing-upper-date-bound/118826/2 "2018-03-07T11:26:23Z")

</div>

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