如何从 Kibana 和 Elasticsearch 中的日期时间中提取月份?

How to extract month from datetime in Kibana and Elastisearch?

我将一些数据放入 Elasticsearch 以在 Kibana 中可视化。我的目标是最大限度地避免 Kibana 中的脚本化字段,因为它们的计算成本很高。

我想制作一个图表,在 X 轴上显示月份,在 Y 轴上显示计数。为此,我需要将 EventDate 格式化为月份。最好的方法是什么?

这是我的PUT声明:

PUT /test
{
    "mappings": {
      "registry": {
      "_source": {
        "enabled": true
      },
      "_all": {
        "enabled": true
      },
        "properties": {
          "Id": {
            "type":"text"
          },
          "Location": {
            "type":"geo_point"
          },
          "Country": {
            "type":"keyword"
          },
          "EventDate": {
            "type":"date",
            "format": "yyyy-MM-dd HH:mm:ss.SSS"
          },
        }
      }
    }
}

我不知道确切的用例,但您可以使用与 EventDate 中的月份匹配的直方图聚合或正则表达式查询。

这是 DateHistogramm 聚合的文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html