Modify date key/key_as_string format

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

{
  "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.

{
  "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
          }
        ]
      }
    }
  }
}

You may specify the key_as_string format by format parameters in date_histogram aggregation.

2 Likes

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.

1 Like

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