Filebeat正在从文件中读取日志,其中日志采用以下格式:
{"logTimestamp":"2019-11-29T16:39:43.027Z","@version":"1","message":"Hello world","logger_name":"se.lolotron.App","thread_name":"thread-1","level":"INFO","level_value":40000,"application":"my-app"}
因此有一个以ISO 8601时间格式记录的字段logTimestamp。问题是该字段被映射为关键字。在Elasticsearch filebeat index
中"logTimestamp": {
"type": "keyword",
"ignore_above": 1024
},
另一方面,如果我在相同的Elasticsearch实例中为相似的文档建立索引,但例如在不同的索引中
POST /new_index/_doc/
{
"message": "hello world",
"logTimestamp":"2019-11-29T16:39:43.027Z"
}
映射是
"logTimestamp": {
"type": "date"
},
根据文档here和here默认情况下,如果用strict_date_optional_time格式化,Elastic应该检测到日期。并且strict_date_optional_time描述为
一个通用的ISO日期时间解析器,其中日期是必填的,时间是是可选的。
我假定是ISO 8601,并认为我通过在上面的示例中将新文档索引到new_index证明了这一点。
为什么在Filebeat中将logTimestamp保存为关键字?有什么想法吗?
我正在使用Filbeat 7.2.1,Elasticsearch 7.2.1。还使用默认的fields.yml。
我刚刚发现,date_detection默认情况下对文件信号索引禁用(文件信号版本7.2.1)。可以看到here
var (
// Defaults used in the template
defaultDateDetection = false
...
看起来好像不能被覆盖。
此问题的解决方法是使用实验性功能append_fields(至少在撰写本文时为实验性质。有关更多信息,请参见here。)并将以下内容添加到filebeat.yml配置中
setup.template.append_fields:
- name: logTimestamp
type: date
这将确保logTimestamp的映射是日期。