2014-10-09 84 views
5

使用Logstash 1.4.2,我有一个字段myfield,它是我的JSON文档中的一个布尔值。Logstash config:检查是否存在布尔字段

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

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 

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

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

+0

链接到github问题https://github.com/elastic/logstash/issues/1867 – spuder 2015-04-20 18:01:51

回答

3

有点蹩脚,它不能正常工作,但是你可以像这样破解它 - 添加一个字符串表示形式的布尔值,然后删除添加的字段:

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" ] 
    } 
} 
+0

谢谢。我已经知道了;这只是混乱,并增加了一些额外的CPU周期。 – bradvido 2014-10-13 22:01:54

+0

说真的,没有更好的选择? – kev 2017-12-01 01:15:49

+0

https://stackoverflow.com/questions/30309096/logstash-check-if-field-exists似乎说有一个更好的方式布尔 – Alcanzar 2017-12-01 01:20:11