# How to set week start day in elastic Aggregation

**URL:** https://discuss.elastic.co/t/how-to-set-week-start-day-in-elastic-aggregation/258226
**Category:** Elasticsearch
**Created:** [December 10, 2020, 7:32am UTC](https://discuss.elastic.co/t/how-to-set-week-start-day-in-elastic-aggregation/258226 "2020-12-10T07:32:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hyonee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hyonee/32/80562_2.png) [@hyonee](https://discuss.elastic.co/u/hyonee)
#### Post date: [December 10, 2020, 7:32am UTC](https://discuss.elastic.co/t/how-to-set-week-start-day-in-elastic-aggregation/258226/1 "2020-12-10T07:32:57Z")

</div>

I want to set Sunday as the first of the week....

request

```auto
{
   "size":0,
   "query":{
      "bool":{
      	         "filter":[
            {
               "range":{
                  "@timestamp":{
                     "from":1601478000000,
                     "to":1607698799998,
                     "include_lower":true,
                     "include_upper":true
                  }
               }
            }
         ]
      }
   },
      "aggregations":{
      "by_date":{
         "date_histogram":{
            "field":"@timestamp",
            "interval":"1w",
            "format":"yyyy-MM-d-W",
            "time_zone": "Asia/Seoul",
            "min_doc_count":0,
            	"offset": "-1d",
            "extended_bounds":{
               "min":1601478000000,
               "max":1607698799998
            }
         }
      }
   }
}

```

response

```auto
"aggregations": {
        "by_date": {
            "buckets": [
                {
                    "key_as_string": "2020-09-27-4",
                    "key": 1601132400000,
                    "doc_count": 0
                },
                {
                    "key_as_string": "2020-10-4-1",
                    "key": 1601737200000,
                    "doc_count": 0
                },
                {
                    "key_as_string": "2020-10-11-2",
                    "key": 1602342000000,
                    "doc_count": 0
                },
                {
                    "key_as_string": "2020-10-18-3",
                    "key": 1602946800000,
                    "doc_count": 0
                },
                {
                    "key_as_string": "2020-10-25-4",
                    "key": 1603551600000,
                    "doc_count": 123
                },
                {
                    "key_as_string": "2020-11-1-0",
                    "key": 1604156400000,
                    "doc_count": 168
                },
                {
                    "key_as_string": "2020-11-8-1",
                    "key": 1604761200000,
                    "doc_count": 143
                },
                {
                    "key_as_string": "2020-11-15-2",
                    "key": 1605366000000,
                    "doc_count": 149
                },
                {
                    "key_as_string": "2020-11-22-3",
                    "key": 1605970800000,
                    "doc_count": 168
                },
                {
                    "key_as_string": "2020-11-29-4",
                    "key": 1606575600000,
                    "doc_count": 167
                },
                {
                    "key_as_string": "2020-12-6-1",
                    "key": 1607180400000,
                    "doc_count": 42
                }
            ]
        }

```

- key\_as\_String : year-month-day-weekOfMonth

However, if you create the query as above, you will not be able to view it from the 1st as in October and December.  
Is there a solution?

---

<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: [January 7, 2021, 7:33am UTC](https://discuss.elastic.co/t/how-to-set-week-start-day-in-elastic-aggregation/258226/2 "2021-01-07T07:33:08Z")

</div>

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