# If condition not working in Output

**URL:** <https://discuss.elastic.co/t/if-condition-not-working-in-output/106849>\
**Category:** Logstash\
**Created:** [November 8, 2017, 10:35am UTC](https://discuss.elastic.co/t/if-condition-not-working-in-output/106849 "2017-11-08T10:35:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Telstra\_Aus](https://avatars.discourse-cdn.com/v4/letter/t/958977/32.png) [@Telstra\_Aus](https://discuss.elastic.co/u/Telstra_Aus)\
**Post date:** [November 8, 2017, 10:35am UTC](https://discuss.elastic.co/t/if-condition-not-working-in-output/106849/1 "2017-11-08T10:35:12Z")

</div>

Hi,

Below is my logstash.conf file content and if condition in output and is not working,

input {  
beats {  
type =\> beats  
port =\> 5044  
host =\> "XX.XX.XX.XX"  
}  
}  
filter {  
multiline {  
pattern =\> "^####"  
negate =\> true  
what =\> "previous"  
}  
}  
output {  
if ([fields][log\_type] == "CRM") {  
elasticsearch {  
action =\> "index"  
hosts =\> ["[http://XX.XX.XX.XX:9200/](http://XX.XX.XX.XX:9200/)"]  
index =\> "CRM\_index\_%{+YYYY.MM.dd}"  
document\_type =\> "system\_logs"  
}  
}

else{  
elasticsearch {  
action =\> "index"  
hosts =\> ["[http://XX.XX.XX.XX:9200/](http://XX.XX.XX.XX:9200/)"]  
index =\> "OMS\_index\_%{+YYYY.MM.dd}"  
document\_type =\> "system\_logs"  
}  
}  
}

-----------------------logs scanned in logstash output----------------------- Bold are the comparison parameters----------  
{  
"offset" =\> 657499,  
"input\_type" =\> "log",  
"source" =\> "/home/nftpoc/Vi  
"message" =\> "####\<Oct 31, 20e: 'weblogic.kernel.Default (self-tu-4f has been accessed from 626396347"  
"type" =\> "log",  
"tags" =\> [  
[0] "beats\_input\_codec\_plain  
],  
"@timestamp" =\> 2017-11-08T10:30  
"@version" =\> "1",  
"beat" =\> {  
"name" =\> "illin3922",  
"hostname" =\> "illin3922",  
"version" =\> "5.6.3"  
},  
"host" =\> "illin3922",  
"fields" =\> {  
"log\_type" =\> "CRM"  
}  
}

---------------------filebeat.yml-------------------------------

- input\_type: log  
paths: ["/home/nftpoc/Vineet/ELK/Logs/CRM/\*.log"]  
fields:  
log\_type: CRM

- input\_type: log  
paths: ["/home/nftpoc/Vineet/ELK/Logs/OMS/\*.log"]  
fields:  
log\_type: OMS

---

<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:** [November 8, 2017, 11:00am UTC](https://discuss.elastic.co/t/if-condition-not-working-in-output/106849/2 "2017-11-08T11:00:22Z")

</div>

You mean events end up in the OMS index when they should've ended up in the CRM index? Can you show an example of such a document (fetch it from the OMS index)?

---

<div class="post-metadata">

**Author:** ![Telstra\_Aus](https://avatars.discourse-cdn.com/v4/letter/t/958977/32.png) [@Telstra\_Aus](https://discuss.elastic.co/u/Telstra_Aus)\
**Post date:** [November 10, 2017, 3:02am UTC](https://discuss.elastic.co/t/if-condition-not-working-in-output/106849/3 "2017-11-10T03:02:08Z")

</div>

No Events are not ending any where, no index gets created when i run the above code.  
the only difference in OMS logs is in the last  
"fields" =\> {  
"log\_type" =\> "OMS"  
}

---

<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:** [December 8, 2017, 3:02am UTC](https://discuss.elastic.co/t/if-condition-not-working-in-output/106849/4 "2017-12-08T03:02:15Z")

</div>

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