[英]How to extract month from datetime in Kibana and Elastisearch?
I put some data into Elasticsearch to visualize it in Kibana. 我将一些数据放入Elasticsearch中以在Kibana中对其进行可视化。 My goal is to maximally avoid Scripted fields in Kibana, because they are computationally expensive. 我的目标是最大程度地避免Kibana中的脚本字段,因为它们在计算上很昂贵。
I want to make a chart showing months in the X axis and count in Y axis. 我想制作一个图表,在X轴上显示月份,在Y轴上计数。 For this I need to format EventDate
into month. 为此,我需要将EventDate
格式化为月份。 What is the best way to do it? 最好的方法是什么?
This is my PUT
statement: 这是我的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"
},
}
}
}
}
I don't know the exact usecase, but you can use Histogram aggregation or regex queries which match the month in EventDate. 我不知道确切的用例,但是您可以使用直方图聚合或正则表达式查询来匹配EventDate中的月份。
Here is the docu of the DateHistogramm Aggregation: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html 这是DateHistogramm聚合的文档: https ://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.