Custom date format on visualizations

Hello,
I' wondering if it's possible to have kibana (currently using 6.7.0 stack) to use the date format specified in "JSON Input"...

For example, in a Date Histogram X-Axis aggregation I could set:

  {
  "format": "E dd MMM YYYY"
  }

The request shows it:

  "aggs": {
    "2": {
      "date_histogram": {
        "field": "@timestamp",
        "interval": "1d",
        "time_zone": "Europe/Berlin",
        "format": "E dd MMM YYYY",
        "min_doc_count": 1
      },
      "aggs": {
        "1": {
          "sum": {
            "field": "Hit_Counter"
          }
        }
      }
    }
  }

and the response actually has the "key_as_string" correctly formatted:

 "aggregations": {
    "2": {
      "buckets": [
        {
          "1": {
            "value": 26153
          },
          "key_as_string": "Sat 01 Feb 2020",
          "key": 1580511600000,
          "doc_count": 41
        },
        {
          "1": {
            "value": 20099
          },
          "key_as_string": "Sun 02 Feb 2020",
          "key": 1580598000000,
          "doc_count": 48
        },

but the visualization keeps showing the format from the "Scaled date format" setting.

Is it possible to force Kibana to use the "key_as_string" values for the x-axis labels?

Regards,
Paolo

It is not possible to format date values in the way you described.

Use field formatters to format date fields

Thank you for the answer:

I didn't think to that possibility.

However, it seems not working for a DateHistogram aggregation:
the DateFormat is not applied to the bucket labels, and they default to the Scaled date format global setting, so that only one format is allowed throughout the application.

The effect is shown in this image:

the timestamp is correctly formatted in the second Metric column (Max @timestamp), but the bucket is labeled with a different format.

I've also tried the same with the flightData on https://demo.elastic.co/, so it's not related to my kibana version.

It'd be nice to have the possibility to set a Scaled date format within an index pattern in kibana, and not only globally.

1 Like

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