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

**URL:** <https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331>\
**Category:** Logstash\
**Created:** [April 16, 2020, 1:35pm UTC](https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331 "2020-04-16T13:35:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [April 16, 2020, 1:35pm UTC](https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331/1 "2020-04-16T13:35:46Z")

</div>

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 !!

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [April 16, 2020, 2:50pm UTC](https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331/2 "2020-04-16T14:50:17Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/e/ae7bfdb0ecaf5d18a1837afb8bb3a31bd7e6954e.png)

---

<div class="post-metadata">

**Author:** ![Emna1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna1/32/64354_2.png) [@Emna1](https://discuss.elastic.co/u/Emna1)\
**Post date:** [April 16, 2020, 3:10pm UTC](https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331/3 "2020-04-16T15:10:55Z")

</div>

Thank you so much, it works!!!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 14, 2020, 3:16pm UTC](https://discuss.elastic.co/t/how-to-check-multiple-values-using-if-else-condition-in-field-and-add-new-values-to-another-field/228331/4 "2020-05-14T15:16:50Z")

</div>

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