Float 1.0 does not get converted to boolean true

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.

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.

Any suggestions to workaround the issue? How do I compare the float/scientific notation value?

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

Thank you
I found this easier :

    	mutate { convert => { "isBool" => "integer" }	}
    	mutate { convert => { "isBool" => "boolean" }   }

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.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.