elasticsearch - 覆盖 @timestamp 以在索引名称中获得正确的 %{+yyyy.MM.dd}
问题描述
我让 Filebeat 逐行读取 json 文件,在每个 json 事件中,我已经有了timestamp
字段(格式:2021-03-02T04:08:35.241632)
处理后,有一个新字段@timestamp
(可能添加了元字段 Filebeat,等于当前时间),并且似乎是索引模式%{+yyyy.MM.dd}
(https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output。 html#index-option-es ) 被配置到该字段。我想@timestamp
用时间戳处理器覆盖:https ://www.elastic.co/guide/en/beats/filebeat/current/processor-timestamp.html但不起作用,可能是布局设置不正确?
- timestamp:
field: timestamp
layouts:
- '2021-03-02T03:29:29.787331'
2021-03-07T11:29:39.382+0700 DEBUG [processor.timestamp] timestamp/timestamp.go:173 Failure parsing time field. {"error": "failed parsing time field timestamp='2021-03-02T03:29:29.787331'", "errorCauses": [{"error": "failed using layout [2021-03-02T03:29:29.787331] cannot parse [-03-02T03:29:29.787331] as [1]"}]}
我还尝试了另一种使用Date.parse
但不起作用的解析时间戳的方法,不确定在 Filebeat 中实现的 ECMA 5.1 是否缺少某些内容:
var date = new Date.parse('2021-03-02T03:29:29.787331');
event.Put('@metadata.index_suffix', date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());
"error": {
"message": "TypeError: Not a constructor at process (/Users/thoong/Projects/shodan/shodan-trends/transform.js:25:16(106))"
},
所以我的timestamp
格式是2021-03-02T03:29:29.787331
,我想问一下layouts
处理器或解析的正确方法是什么Date.parse
?
解决方案,这是来自@Val 答案的正确布局
- timestamp:
field: timestamp
layouts:
- '2006-01-02T15:04:05.000000'
解决方案
如果您的字段已具有 ISO8601 格式,则无需指定layouts
参数。timestamp
但是,如果您的timestamp
字段有不同的布局,您必须在布局部分指定一个非常具体的参考日期,Mon Jan 2 15:04:05 MST 2006
您也可以提供一个test
日期。(更多信息)
因此,在您的情况下,它将是:
- timestamp:
field: timestamp
ignore_missing: true
ignore_failure: true
layouts:
- '2006-01-02T15:04:05.000000'
test:
- '2021-03-02T03:29:29.787331'
推荐阅读
- javascript - 击中空格后如何在 Sublime Text 3 中的括号之间自动插入空格
- python - /provider/'providers' 处的 Django NoReverseMatch 不是已注册的命名空间
- git - 将巨大的 SVN 存储库迁移到 GIT,并且 SVN 存储库上的冻结时间最短
- node.js - NodeJs - 接近堆限制分配失败 - JavaScript堆内存不足
- c# - 无法在 C# 中使用 RSA256 验证 json 有效负载中数据字段的签名
- c++ - 是否可以在“if”语句中声明变量?
- c++ - 如何在循环中随机化不同的值?C++
- c# - C# Automapper.Map 方法有什么区别?
- kotlin - Koin - 如何泛化 Singleton 创作?
- r - ggplot :绘制两条条和一条线?