# Modify date key/key\_as\_string format

**URL:** <https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 1, 2022, 8:11pm UTC](https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557 "2022-03-01T20:11:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bsmith](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@bsmith](https://discuss.elastic.co/u/bsmith)\
**Post date:** [March 1, 2022, 8:11pm UTC](https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557/1 "2022-03-01T20:11:33Z")

</div>

Is there any way to modify the date format of the key? or provide maybe an additional key field in a format that I like for use later in Vega? Currently sorting by key\_as\_string but it's lengthy

```auto
{
  "size": 0,
  "aggs": {
    "wow": {
      "filter": {
        "range": {
          "date": {
            "gte": "2020-01-01",
            "lte": "2020-01-31"
          }
        }
      },
      "aggs":
      {
        "wow-er":
        {
          "date_histogram": {
            "field": "date",
            "interval": "month"
          }
        }
      }
    }
  }
}

```

The above returns the following. In a perfect world I would love to just get just MMM in the key as string.

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "wow" : {
      "doc_count" : 30693,
      "wow-er" : {
        "buckets" : [
          {
            "key_as_string" : "2020-01-01T00:00:00.000Z",
            "key" : 1577836800000,
            "doc_count" : 30693
          }
        ]
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [March 2, 2022, 5:24am UTC](https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557/2 "2022-03-02T05:24:38Z")

</div>

You may specify the `key_as_string` format by [`format`](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html#datehistogram-aggregation-keys) parameters in date\_histogram aggregation.

---

<div class="post-metadata">

**Author:** ![bsmith](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@bsmith](https://discuss.elastic.co/u/bsmith)\
**Post date:** [March 2, 2022, 1:25pm UTC](https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557/3 "2022-03-02T13:25:24Z")

</div>

Ugh. I tried format in the range section and it was giving me grief but of course it didn't cross my mind to try setting it in the dang date histogram. 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:** [March 30, 2022, 1:26pm UTC](https://discuss.elastic.co/t/modify-date-key-key-as-string-format/298557/4 "2022-03-30T13:26:01Z")

</div>

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