Logstash config:检查是否存在布尔字段

bra*_*ido 7 logstash

使用Logstash 1.4.2,我的字段myfield是我的JSON文档中的布尔值.

要检查它是否存在(不关心布尔值)我用过:

if[myfield] { ...exists... } else { ...doesn't exist... } 
Run Code Online (Sandbox Code Playgroud)

测试此条件语句的结果是:

[myfield] does not exist   --> false
[myfield] exists, is true  --> true
[myfield] exists, is false --> false //expected true because the field exists
Run Code Online (Sandbox Code Playgroud)

它检查布尔值,而不是它的存在.

如何检查布尔字段是否存在?

Alc*_*zar 4

有点蹩脚的是它不能直接工作,但你可以像这样破解它——添加布尔值的字符串表示,与字符串进行比较,然后删除添加的字段:

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" ]
   }
}
Run Code Online (Sandbox Code Playgroud)