sc5283
(Servando)
April 28, 2020, 6:04pm
1
logstash 7.6.2
From mutate filter
specifies float 1.0 is converted to boolean true
but this is not the case, all others work (0, 0.0, "0", etc).
I have tried also the translate filter with no success
input : ---> {"isBool":1.0}
input { stdin { } }
filter {
translate {
field => "[isBool]"
dictionary => [
"0.0", false,
0, false,
"1.0", true,
1, true,
1.0, true,
"1", true
]
}
## or only the mutate/convert
mutate { convert => { "isBool" => "boolean" } }
}
output { stdout { codec => rubydebug } }
--debug provides the following:
[WARN ] .... [[main]>worker10] mutate - Failed to convert 0.1e1 into boolean.
Badger
April 28, 2020, 6:16pm
2
Interesting. The code tries to match the value against the regexp /^(true|t|yes|y|1|1.0)$/i and 0.1e1 would indeed not match that.
sc5283
(Servando)
April 28, 2020, 6:40pm
3
Any suggestions to workaround the issue? How do I compare the float/scientific notation value?
Badger
April 28, 2020, 7:15pm
4
You might be able to write a ruby filter that compares your field to 1 and makes it an integer if it is equal to one, or maybe even
k = "someField"
v = event.get(k)
if v.to_i.to_f == v
v = v.to_i
event.set(k, v)
end
sc5283
(Servando)
April 28, 2020, 7:32pm
5
Thank you
I found this easier :
mutate { convert => { "isBool" => "integer" } }
mutate { convert => { "isBool" => "boolean" } }
Badger
April 28, 2020, 10:19pm
6
Yes, that would work if it is always 1.0, my code handles 1.1 as well (by not changing it). If you do not need that then your code is simpler, which generally means better.
system
(system)
Closed
May 26, 2020, 10:19pm
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.