How to check multiple values using if else condition in field and add new values to another field?

HI, I want to add a code which contains if else conditions which helps me to add values ​​to a new field according to conditions on another field.
for example;

Blockquote

if [Duration] >= 360 {
mutate {
add_field => { "Price" => "50$" }
}
else if
duration between two values add to the same field " Price" another value like 25$ ....

Blockquote

Please i will appreciate any help and thanks !!

Hi there,

it is exactly as you wrote it. Try out this pipeline

input {
  stdin{
    codec => "json"
  }
}

filter {
  if [Duration] >= 360 {
    mutate {
      add_field => { "Price" => "50$" }
    }
  } else if [Duration] < 360 and [Duration] >= 100 {
    mutate {
      add_field => { "Price" => "25$" }
    }
  } else {
    mutate {
      add_field => { "Price" => "15$" }
    }
  }
}

output {
  stdout{}
}

Here's the result

Thank you so much, it works!!!!

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