使用 Logstash 1.4.2,我的 JSON 文档中有一个字段 myfield
,它是一个 bool 值。
检查它是否存在(不关心 bool 值)我使用:
if[myfield] { ...exists... } else { ...doesn't exist... }
测试此条件语句的结果是:
[myfield] does not exist --> false
[myfield] exists, is true --> true
[myfield] exists, is false --> false //expected true because the field exists
它正在检查 bool 值,而不是它的存在。
如何检查 bool 字段是否存在?
最佳答案
有点蹩脚,它不能直接工作,但你可以像这样破解它——添加 bool 值的字符串表示,与字符串进行比较,然后删除添加的字段:
filter {
mutate {
add_field => { "test" => "%{boolean}" }
}
if [test] == 'true' or [test] == 'false' {
// field is present and set right
} else {
// field isn't present or set to something other than true/false
}
mutate {
remove_field => [ "test" ]
}
}
关于Logstash配置: check if boolean field exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26287082/