2

I'm searching a way to compare a Logstash field to a number in a conditional statement, but couldn't find anything in the documentation.

Something like this for example:

if [myfiels] => 1{
           mutate {
                   add_field => ["fild", "1"]
           }

or

if [myfiels] >= 1 and [myfiels] <= 3 {
               mutate {
                       add_field => ["fild", "2"]
               }

Thanks.

Kobayashi
  • 2,402
  • 3
  • 16
  • 25

1 Answers1

3

You first need to convert column type.

input {
   stdin{}
}

filter {
    grok {
        match => ["message","%{NUMBER:num}" ]
    }
    mutate {
        convert => { "num" => "integer" }
    }
    if [num] >= 5 {
        mutate { 
            add_field => { "xyz" => "123" }
        }
    }
}

output {
    stdout { codec => rubydebug }
}
Kobayashi
  • 2,402
  • 3
  • 16
  • 25
Mukrram Rahman
  • 426
  • 2
  • 14