# If else in logstash throwin error

**URL:** <https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436>\
**Category:** Logstash\
**Created:** [August 25, 2021, 5:10am UTC](https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436 "2021-08-25T05:10:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![selin](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@selin](https://discuss.elastic.co/u/selin)\
**Post date:** [August 25, 2021, 5:10am UTC](https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436/1 "2021-08-25T05:10:17Z")

</div>

Below is my logstash configuration file

```auto
output {
  if "%{[fields][myvalue1]}" == "value" and "%{[fields][myvalue2]}" == "valu" {
    hosts => ["https://es1:9200","https://es2:9200","https://es3:9200"]
    ilm_enabled => true
    ilm_rollover_alias => "my_index"
    ilm_pattern => "{now/d}-00001"
    ilm_policy => "my_policy"
    user => "username"
    password => "mypassword"
  }
}

```

I am hitting below error

```auto
Expected one of [\\t\\r\\n], \"#\"

```

---

<div class="post-metadata">

**Author:** ![hunsw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hunsw/32/93637_2.png) [@hunsw](https://discuss.elastic.co/u/hunsw)\
**Post date:** [August 25, 2021, 9:02am UTC](https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436/2 "2021-08-25T09:02:06Z")

</div>

Erm... it seems you are missing the type of output in your config.

E.g.

```auto
output {
    elasticsearch {
        hosts => "hostname"
.....
    }
}

```

Also in the 2nd comparison, you have a typo ( **valu** instead of value).

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [August 25, 2021, 9:06am UTC](https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436/3 "2021-08-25T09:06:20Z")

</div>

Hi,

The if need to be like this :

```auto
if [fields][myvalue1] == "value" and [fields][myvalue2] == "valu"

```

---

<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:** [September 22, 2021, 9:07am UTC](https://discuss.elastic.co/t/if-else-in-logstash-throwin-error/282436/4 "2021-09-22T09:07:17Z")

</div>

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