Search code examples
logstashelastic-stack

How to compare float in logstash?


It's the pipeline config for test:

input {
  file {
    path => "/tmp/test1.log"
  }
}
filter {
  json {
    source => "message"
  }
}

output {
  if [a] == 1.1 {
    stdout {}
  }
}

I echo some test log to logfile:

echo '{"a": 1.1,"b": "test"}' >> /tmp/test1.log

But there isn't any output in console, and I try use the condition if [a] == "1.1" either not work.

Somebody know how to compare float?

thanks!


Solution

  • Alternatively you can use custom Ruby code to compare float:

    ruby {
        code=> '
            if event.get("[a]") == 1.1 
                event.set("isFloat", "true")
            end
            '
    }