使用Logstash 1.4.2,我有一个字段myfield
这是我的 JSON 文档中的布尔值。
为了检查它是否存在(不关心布尔值),我使用了:
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
它正在检查布尔值,而不是它的存在.
如何检查布尔字段是否存在?
有点蹩脚的是它不能直接工作,但你可以像这样破解它——添加布尔值的字符串表示,与字符串进行比较,然后删除添加的字段:
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" ]
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)