Logstash converting empty string into 0.0

Hi,
I am converting an amount value into float as follows.

mutate{
convert => {
 "AMT" => "float"

 }

if "AMT"="" empty spcae ,it give 0.0 as the conversion output. this may mislead people since it is an amount field.

is there a way to avoid this problem..?

thanks for reading and helping.

Yes, a mutate will do that. You could make the mutate conditional upon AMT not being blank.

if [AMT] != "" {
    [...]
1 Like

that works. Actually I have to convert more than 10 fields like this and checking each one of this doesnt look good to me. is there a way to do this using ruby filter with for loop on a list of fields to convert?

thanks for reading and helping.

Yes, you could do something like this:

    ruby {
        code => '
            [ "amount", "foo", "bar", "baz" ].each { |x|
                s = event.get(x)
                if s and (s.to_f.to_s == s) then
                    event.set(x, s.to_f)
                end
            }
        '
    }

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