# Conditional statement in logstash output doesn't work

**URL:** <https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977>\
**Category:** Logstash\
**Created:** [February 19, 2019, 9:28am UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977 "2019-02-19T09:28:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anonymous2](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Anonymous2](https://discuss.elastic.co/u/Anonymous2)\
**Post date:** [February 19, 2019, 9:28am UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977/1 "2019-02-19T09:28:26Z")

</div>

Hello I've made a conditional statement in the output of logstash, but the else statement doesn't work. When I send INFO logs they get into the if statement, but when I send logs different from these, they don't get into the else statement and they are not shown in tpms-system index.

Here is my output section:

```auto
output{
  stdout{
    codec => dots
  }

  if [message] =~ "\D\[INFO\s\]:.*\[ELASTICSEARCH\].*" or [message] =~ "\D\[INFO\]:.*\[ELASTICSEARCH\].*" {
   elasticsearch {
    hosts => ["https://localhost:9200"]
    user => logstash
    password => logstash
    ssl => true
    ssl_certificate_verification => false
    document_id => "%{fingerprint}"
    index => "beat-tpms"
   }
  }else{
   elasticsearch {
    hosts => ["https://localhost:9200"]
    user => logstash
    password => logstash
    ssl => true
    ssl_certificate_verification => false
    document_id => "%{fingerprint}"
    index => "tpms-system"
   }
 }
}

```

The regex expression is correct because I'm using the same in filebeat.yml file to recieve only these INFO logs and is working.

---

<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 19, 2019, 12:44pm UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977/2 "2019-02-19T12:44:36Z")

</div>

How many documents are there in the tpms-system index?

---

<div class="post-metadata">

**Author:** ![Anonymous2](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Anonymous2](https://discuss.elastic.co/u/Anonymous2)\
**Post date:** [February 19, 2019, 12:46pm UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977/3 "2019-02-19T12:46:42Z")

</div>

1. There're no documents and I don't know why.

---

<div class="post-metadata">

**Author:** ![Anonymous2](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@Anonymous2](https://discuss.elastic.co/u/Anonymous2)\
**Post date:** [February 19, 2019, 2:45pm UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977/4 "2019-02-19T14:45:50Z")

</div>

For some reason logstash doesn't send docs to tpms-system index. It turns out that it was a permission issue.

---

<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 19, 2019, 2:45pm UTC](https://discuss.elastic.co/t/conditional-statement-in-logstash-output-doesnt-work/168977/5 "2019-03-19T14:45:51Z")

</div>

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