date字段被呈现为整数

我有一个Elastic Stack服务器(在Hyper-v ),它通过logstash exec命令摄取数据并对其执行分析。 除了显示为数字的date字段之外,一切都很好。

我如何获得logstashElasticsearchKibana识别字段sadate而不是数字?

数据是Unix epoch时间(以milliseconds


码:

python文件输出的数据是JSON格式。 在进行elasticsearch之前,没有真正的处理过程正在进行。

Logstashconfiguration:

 input { exec { command => "/home/elliot/BullhornConnector.py JobOrder isOpen,webResponses,submissions,sendouts,interviews,placements,address,numOpenings,employmentType,owner,title,clientCorporation" interval => 60 codec => json tags => ["JobOrder"] } exec { command => "/home/elliot/BullhornConnector.py Lead owner,leadSource,firstName,lastName,status,dateAdded" interval => 60 codec => json tags => ["Lead"] } exec { command => "/home/elliot/BullhornConnector.py Opportunity owner,isOpen,dealValue,weightedDealValue,clientCorporation,status" interval => 60 codec => json tags => ["Opportunity"] } } output { elasticsearch { hosts => ["localhost:9200"] } stdout { codec => rubydebug } } 

屏幕截图:

以下是原始数据的截图: 原始数据显示

索引模式概述页面: 索引模式页面上的数据概述

领域的详细的看法: 设置不允许我改变它。

谢谢!

如果我正确阅读ElasticSearch文档https://www.elastic.co/guide/en/elasticsearch/reference/current/date.html

 JSON doesn't have a date datatype, so dates in Elasticsearch can either be: strings containing formatted dates, eg "2015-01-01" or "2015/01/01 12:10:30". a long number representing milliseconds-since-the-epoch. an integer representing seconds-since-the-epoch. 

因此,表示为“数字”数据types的dateAdded字段是合乎逻辑的:Elasticsearch只是将JSON号码转换为ES号码。

如果我看看我自己的ELK实例,我发现“时间戳”字段被表示为“date”数据types。 它是由logstash自动完成的。

在幕后,logstashpipe理一个“映射模板”来定义ES字段的数据types。 在你的情况下,它天真地从JSON翻译datetypes,并在时间戳的情况下,它知道这是一个明确定义它的date。

所以你需要做的是定义一个映射模板,并使用logstash将其推送到ES与您的数据。

ES映射文档在这里https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html和Logstash可以在elasticsearch输出中使用manage_template和模板进行pipe理https://www.elastic.co/ guide / en / logstash / current / plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-template 。 AS映射介绍https://www.elastic.co/blog/found-elasticsearch-mapping-introduction

你也可以看看实际使用的映射

 curl -XGET 'localhost:9200/<index>/_mapping?pretty' 

我在这里猜测,因为我不熟悉你所谈论的平台和程序。 但是,在你的屏幕截图中,你曾经说过把数据types改为Duration,但是看起来数据types仍然是“数字”,“格式”是持续时间。 如果我不得不继续猜测,我会说你的平台仍然试图将你的字段作为一个数字序列化,因为它的数据types仍然是“数字”。 将该types更改为“date”,如截图顶部的@timestamp字段,然后查看是否修复了该问题。

我已经想通了:你需要做的是在logstash中使用filter插件,特别是date插件。

这里是我添加到我的logstashconfiguration的片段:

 filter { date { match => [ "dateAdded", "UNIX_MS" ] target => "dateAddedCorrected" } }