我的日志中有一个日期,格式如下,
YYYY-M-dd and YYYY-MM-d and YYYY-M-d
2020-9-21
2020-11-1
2020-9-1日期筛选器插件与
date {
match => [ "event_date" ,"yyyy-MM-dd"]
}一些日志我得到日期解析异常,因为这个。有没有可能把这些都匹配上。我的意思是,如果不匹配另一个日期格式,则匹配此格式。
错误是
"failed to parse field [event_date] of type [date] in document with id '...'. Preview of field's value: '2017-11-2'", "caused_by"=>{"type"=>"illegal_argument_exception", "reason"=>"failed to parse date field [2017-11-2] with format [strict_date_optional_time||epoch_millis]", "caused_by"=>{"type"=>"date_time_parse_exception", "reason"=>"date_time_parse_exception: Failed to parse with all enclosed parsers"}}}}}} 我该怎么解决它呢?感谢您的回复
发布于 2021-01-13 19:27:51
我已经尝试了第一个答案,但没有解决我的问题。@YLR的方法也是改进的好方法。我已经解决了我的问题,将像M这样的字段更改为带有if条件的MM。下面是一个例子。
if [monthday] == "1"{
mutate {
update => { "monthday" => "01" }
}
}else if [monthday] == "2"{
mutate {
update => { "monthday" => "02" }
}
}else if [monthday] == "3"{
mutate {
update => { "monthday" => "03" }
}
}
....这解决了我的问题,但这有点难。
发布于 2021-01-13 18:42:08
一种解决方案是使用一种类似于开关的机制,该开关由具有tag_on_failure值的日期过滤器实现。它看起来是这样的:
filter{
date {
match => [ "event_date" ,"yyyy-MM-dd"]
tag_on_failure => [ "not_format_date1"]
}
if "not_format_date1" in [tags] {
date {
match => [ "event_date" ,"yyyy-MM-d"]
tag_on_failure => [ "not_format_date2"]
}
}
if "not_format_date2" in [tags] {
date {
match => [ "event_date" ,"yyyy-M-d"]
tag_on_failure => [ "no_format"]
}
}
}https://stackoverflow.com/questions/65699866
复制相似问题