# Logstash conf file if else condition is not working

**URL:** <https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111>\
**Category:** Logstash\
**Created:** [March 6, 2019, 12:35pm UTC](https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111 "2019-03-06T12:35:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suresh\_Pal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_pal/32/31571_2.png) [@Suresh\_Pal](https://discuss.elastic.co/u/Suresh_Pal)\
**Post date:** [March 6, 2019, 12:35pm UTC](https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111/1 "2019-03-06T12:35:25Z")

</div>

Team,

Vesrion 6.2

In my config file i'm trying to use different grok pattern for different prospector.

filter {  
if [type] == "db\_log" {  
grok {  
match =\> ["message", "%{TIMESTAMP\_ISO8601:timetamp}%{SPACE}%{NOTSPACE}%{SPACE}%{INT:line}%{SPACE}%{NOTSPACE}%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}(?:- Tenant Name :)%{SPACE}%{WORD:TENANT\_NAME}%{SPACE}(?:GlobalConnectionPool - Active Connections :)%{SPACE}%{WORD:Active\_Connections}%{SPACE}%{NOTSPACE}%{SPACE}(?:Idle Connections :)%{SPACE}%{WORD:Idle\_Connection}"]  
}  
}  
else if [type] == "user\_access" {  
grok {  
match =\> ["message", "%{NOTSPACE}%{SPACE}%{NOTSPACE}%{SPACE}%{WORD:USER}%{WORD}%{GREEDYDATA}"]  
}  
}

else{  
grok {  
match =\> { "message" =\> "%{TIMESTAMP\_ISO8601:timetamp}%{SPACE}%{NOTSPACE}%{SPACE}%{INT:line}%{SPACE}%{NOTSPACE}%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}(?:- Tenant Name :)%{SPACE}%{WORD:TENANT\_NAME}%{SPACE}%{GREEDYDATA:Message}"}  
}  
date {  
match =\> ["timestamp" , "dd/MMM/yyyy:HH:mm:ss Z"]  
}  
}  
}

output {  
elasticsearch { hosts =\> ["localhost:9200"] }

}

Note: fist If and last else condition is working fine but in between else if condition is not working.

Someone please help me to sort out this.

---

<div class="post-metadata">

**Author:** ![Suresh\_Pal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suresh_pal/32/31571_2.png) [@Suresh\_Pal](https://discuss.elastic.co/u/Suresh_Pal)\
**Post date:** [March 11, 2019, 6:17am UTC](https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111/2 "2019-03-11T06:17:25Z")

</div>

Hi team,

Any update ??

---

<div class="post-metadata">

**Author:** ![Ganesh2303](https://avatars.discourse-cdn.com/v4/letter/g/57b2e6/32.png) [@Ganesh2303](https://discuss.elastic.co/u/Ganesh2303)\
**Post date:** [March 11, 2019, 3:17pm UTC](https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111/3 "2019-03-11T15:17:27Z")

</div>

Share your log whether your type value gets match with log.

---

<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 8, 2019, 3:17pm UTC](https://discuss.elastic.co/t/logstash-conf-file-if-else-condition-is-not-working/171111/4 "2019-04-08T15:17:38Z")

</div>

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