# How to make weekday start on Sunday in date histogram aggregation

**URL:** <https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621>\
**Category:** Elasticsearch\
**Created:** [May 12, 2017, 8:20pm UTC](https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621 "2017-05-12T20:20:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![data.dev](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@data.dev](https://discuss.elastic.co/u/data.dev)\
**Post date:** [May 12, 2017, 8:20pm UTC](https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621/1 "2017-05-12T20:20:48Z")

</div>

We need to have a date histogram aggregation with week interval, with week starting on Sunday instead of the Monday which Elasticsearch defaults to. I'm running Elasticsearch version 5.3.0.

I found this Github issue which added pre\_offset and post\_offset, but it does not seem to work for me: [https://github.com/elastic/elasticsearch/issues/1599](https://github.com/elastic/elasticsearch/issues/1599)

Here is the aggs portion of my query:

```
    "aggs": {
        "a1": {
            "date_histogram": {
                "field": "postedDate",
                "interval": "week",
                "pre_offset": "-1d",
                "post_offset": "-1d",
                "order": {
                    "_key": "asc"
                }
            }
        }
    }

```

Running the query fails with:  
`Error: [illegal_argument_exception] [date_histogram] unknown field [pre_offset], parser not found`

The query runs fine without the pre\_offset/post\_offset fields. Did I put those properties in the right place? They don't seem to be documented anywhere aside from the aforementioned GitHub issue. Is it still supported, and if not, how else can one set the week start to be Sunday instead of Monday?

---

<div class="post-metadata">

**Author:** ![Xavy](https://avatars.discourse-cdn.com/v4/letter/x/e0b2c6/32.png) [@Xavy](https://discuss.elastic.co/u/Xavy)\
**Post date:** [May 12, 2017, 8:44pm UTC](https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621/2 "2017-05-12T20:44:14Z")

</div>

Hello

Looking at [https://github.com/zombodb/zombodb/issues/51](https://github.com/zombodb/zombodb/issues/51), (I know it is not a ES repo but still valid here) which is referenced on the Github issue you mentioned, it looks that those options were not included or deprecated in favour of offset.

Additionally changes on the PR that closed the issue ou mentioned are no longer present on 5.3.0 [https://github.com/elastic/elasticsearch/tree/v5.3.0/core/src/main/java/org/elasticsearch/common/joda](https://github.com/elastic/elasticsearch/tree/v5.3.0/core/src/main/java/org/elasticsearch/common/joda)

Finally looking at doc:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-bucket-datehistogram-aggregation.html#\_offset](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/search-aggregations-bucket-datehistogram-aggregation.html#_offset)

You have the offset so you can do an offset of -1d and therefore it would go from sunday to sunday instead of from Monday to Monday. Does something like this make sense for you:

```auto
"aggs": {
        "a1": {
            "date_histogram": {
                "field": "postedDate",
                "interval": "week",
                "offset": "-1d",
                "order": {
                    "_key": "asc"
                }
            }
        }
    }
```

---

<div class="post-metadata">

**Author:** ![data.dev](https://avatars.discourse-cdn.com/v4/letter/d/c89c15/32.png) [@data.dev](https://discuss.elastic.co/u/data.dev)\
**Post date:** [May 12, 2017, 10:54pm UTC](https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621/3 "2017-05-12T22:54:45Z")

</div>

The offset works. Thanks!

---

<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:** [June 9, 2017, 11:02pm UTC](https://discuss.elastic.co/t/how-to-make-weekday-start-on-sunday-in-date-histogram-aggregation/85621/4 "2017-06-09T23:02:25Z")

</div>

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