# Logstash condition statement

**URL:** <https://discuss.elastic.co/t/logstash-condition-statement/109448>\
**Category:** Logstash\
**Created:** [November 28, 2017, 5:33pm UTC](https://discuss.elastic.co/t/logstash-condition-statement/109448 "2017-11-28T17:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saikrishnagaddipati](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@saikrishnagaddipati](https://discuss.elastic.co/u/saikrishnagaddipati)\
**Post date:** [November 28, 2017, 5:33pm UTC](https://discuss.elastic.co/t/logstash-condition-statement/109448/1 "2017-11-28T17:33:26Z")

</div>

Hi, Below is my logstash output config file, I am using too many if, else if conditional statements in the code. Is it possible to do a case statement like in ruby or something which will reduce the repetition.

output {  
if [type] == "my-report" {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
user =\> "myid"  
password =\> "mypassword"  
index =\> "my-reports-%{+YYYY.MM.dd}"  
}  
} else if [type] =~ "beat._" {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
user =\> "myid"  
password =\> "mypassword"  
index =\> "beat-%{+YYYY.MM.dd}"  
}  
} else if [type] =~ "kafka._" {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
user =\> "myid"  
password =\> "mypassword"  
index =\> "kafka-%{+YYYY.MM.dd}"  
}  
} else {  
elasticsearch {  
hosts =\> ["localhost:9200"]  
user =\> "logstash\_internal"  
password =\> "logstashpassword"  
index =\> "logs-%{type}-%{+YYYY.MM.dd}"  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [November 28, 2017, 7:13pm UTC](https://discuss.elastic.co/t/logstash-condition-statement/109448/2 "2017-11-28T19:13:32Z")

</div>

No, the `if` conditional is the only support control structure.

---

<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:** [December 26, 2017, 7:13pm UTC](https://discuss.elastic.co/t/logstash-condition-statement/109448/3 "2017-12-26T19:13:40Z")

</div>

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