# Am I misunderstanding if/else statements?

**URL:** <https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931>\
**Category:** Logstash\
**Created:** [March 9, 2017, 4:49am UTC](https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931 "2017-03-09T04:49:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![helium](https://avatars.discourse-cdn.com/v4/letter/h/2acd7d/32.png) [@helium](https://discuss.elastic.co/u/helium)\
**Post date:** [March 9, 2017, 4:49am UTC](https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931/1 "2017-03-09T04:49:32Z")

</div>

Hi,

I have a bunch of logstash (2.4.0) nodes with this output config:  
`output {
if [environment] == "stage" {
elasticsearch {
hosts => ["elasticsearch-01"]
index => "logstash-stage-%{+YYYY.MM.dd}"
}
} else {
elasticsearch {
hosts => ["elasticsearch-01"]
index => "logstash-%{+YYYY.MM.dd}"
}
}
}`  
The idea is of course that logs with the environment field set to stage should go into the logstash-stage index. This is not working as intended because it goes to both indices i.e. the same event is found under both logstash-stage and logstash-. This only happens for events with environment == stage, other events only goes to logstash- as they should. What am I doing wrong?

Thanks,

---

<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:** [March 9, 2017, 2:22pm UTC](https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931/2 "2017-03-09T14:22:05Z")

</div>

Your configuration looks correct. If you're storing your configuration file(s) in /etc/logstash/conf.d, do you have any other files there (like one with an elasticsearch output)? Logstash will read _all_ files in that directory.

---

<div class="post-metadata">

**Author:** ![helium](https://avatars.discourse-cdn.com/v4/letter/h/2acd7d/32.png) [@helium](https://discuss.elastic.co/u/helium)\
**Post date:** [March 9, 2017, 10:41pm UTC](https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931/3 "2017-03-09T22:41:35Z")

</div>

I figured it out... it's in the right index but Kibana evaluates both indices since logstash-\* ofcourse matches logstash-stage-%{+YYYY.MM.dd} too. I renamed the stage one to logstage and all is good.

Thanks!

---

<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:** [April 6, 2017, 10:41pm UTC](https://discuss.elastic.co/t/am-i-misunderstanding-if-else-statements/77931/4 "2017-04-06T22:41:41Z")

</div>

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