# IS it possible to use "nested else if" in logstash.conf

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342>\
**Category:** Logstash\
**Created:** [January 3, 2023, 6:43am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342 "2023-01-03T06:43:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjacksonrkk](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jjacksonrkk](https://discuss.elastic.co/u/jjacksonrkk)\
**Post date:** [January 3, 2023, 6:43am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342/1 "2023-01-03T06:43:13Z")

</div>

hello~

Is it possible to use "nested else if" in filter section inside logstash.conf  
logstash 7.10.2

example  
else if ... {  
if ...{  
else if .... {  
....  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Rios](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rios/32/95745_2.png) [@Rios](https://discuss.elastic.co/u/Rios)\
**Post date:** [January 3, 2023, 8:32am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342/2 "2023-01-03T08:32:46Z")

</div>

Yes, it's possible in 7.x, check [documentation](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals). Pay attention on curly brackets, with too many IFs, things can be messy.

```auto
if [field1]=="something"{
   if ( [field2]=="value1" or [field2]=="valu2" ){
   ...
   }
}
else if "value" in [tags]{
 ...}
else {
...
}

```

Also you can use IFs in the output section.

---

<div class="post-metadata">

**Author:** ![jjacksonrkk](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jjacksonrkk](https://discuss.elastic.co/u/jjacksonrkk)\
**Post date:** [January 3, 2023, 10:17am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342/3 "2023-01-03T10:17:35Z")

</div>

oh thanks but that means,  
\*\* else if inside if \* becuase it's not working

```auto
if [field1] == "somthing"{
    ...
}
else if [field1]=="something"{
   if ( [field2]=="value1" or [field2]=="valu2" ){
   ...
    }
  }

```

---

<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:** [January 31, 2023, 10:17am UTC](https://discuss.elastic.co/t/is-it-possible-to-use-nested-else-if-in-logstash-conf/322342/4 "2023-01-31T10:17:53Z")

</div>

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