# Problem with conditional in output definition

**URL:** <https://discuss.elastic.co/t/problem-with-conditional-in-output-definition/74302>\
**Category:** Logstash\
**Created:** [February 7, 2017, 11:47pm UTC](https://discuss.elastic.co/t/problem-with-conditional-in-output-definition/74302 "2017-02-07T23:47:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 7, 2017, 11:47pm UTC](https://discuss.elastic.co/t/problem-with-conditional-in-output-definition/74302/1 "2017-02-07T23:47:12Z")

</div>

I started experimenting with metricbeat and wanted the data in the index that the sample dashboards expect, so I tried settting the index conditionally on the input type. logstash complains that it is an invalid configuration, but I think I am doing what the documentation says. Here is how I define the output

```
elasticsearch {
hosts => "localhost"
if [type] == "metricsets" {
index => "metricbeat-%{+YYYY.MM.dd}"
} else {
index => "logstash-%{+YYYY.MM.dd}"
}
}
```
Is it broken or did I miss something in the documentation? "bin/logstash --version" tells me I am running "logstash 5.1.1". The error message I get ends with 

:reason=\>"Expected one of #, =\> at line 22, column 6 (byte 586) after output {\n\t# stdout { codec =\> "rubydebug" }\n\telasticsearch {\n\t\thosts =\> "localhost"\n\t\tif "}

I don't want to post the entire error message because it contains the SSL keystore and truststore passwords unobfuscated, which is a whole other problem.

---

<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:** [February 8, 2017, 11:05am UTC](https://discuss.elastic.co/t/problem-with-conditional-in-output-definition/74302/2 "2017-02-08T11:05:42Z")

</div>

You can't have conditionals inside the plugin definitions. Do this instead:

```nohighlight
if [type] == "metricsets" {
  elasticsearch {
    hosts => "localhost"
    index => "metricbeat-%{+YYYY.MM.dd}"
  }
} else {
  elasticsearch {
    hosts => "localhost"
    index => "logstash-%{+YYYY.MM.dd}"
  }
}

```

---

<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:** [March 8, 2017, 11:05am UTC](https://discuss.elastic.co/t/problem-with-conditional-in-output-definition/74302/3 "2017-03-08T11:05:42Z")

</div>

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