# If condition in logstash filter

**URL:** <https://discuss.elastic.co/t/if-condition-in-logstash-filter/157369>\
**Category:** Logstash\
**Created:** [November 19, 2018, 1:45pm UTC](https://discuss.elastic.co/t/if-condition-in-logstash-filter/157369 "2018-11-19T13:45:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashok9177](https://avatars.discourse-cdn.com/v4/letter/a/edb3f5/32.png) [@ashok9177](https://discuss.elastic.co/u/ashok9177)\
**Post date:** [November 19, 2018, 1:45pm UTC](https://discuss.elastic.co/t/if-condition-in-logstash-filter/157369/1 "2018-11-19T13:45:06Z")

</div>

I have written if the condition for grok filter

```
filter {
if "id4444" in [fields][component] {
  grok {
    match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} (\[%{WORD:loglevel}\]) %{DATA} - %{DATA:method} processing time for transactionId : %{S3_REQUEST_LINE:transactionid} documentType : %{WORD:document type} is %{INT:duration:int}" }

  match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} (\[%{WORD:loglevel}\]) %{DATA} - %{DATA:method} processing time for transactionId : %{S3_REQUEST_LINE:transactionid} documentType : %{WORD:document type} merchant : %{HOSTNAME:merchant} is %{INT:duration:int}" }

 match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} \[%{WORD:loglevel}\] %{GREEDYDATA}" }
  }
}
else if "idt.512" or "idt.256" in [fields][component] {
 grok {

    match => ["message", "%{TIMESTAMP_ISO8601:timestamp} %{NUMBER} (\[%{WORD:loglevel}\])" ]
}
}
else if "id2fa" in [fields][component] {
 grok {

    match => ["message", "%{TIMESTAMP_ISO8601:timestamp} %{NUMBER} (\[%{WORD:loglevel}\])" ]
}
}

grok {

    match => ["message", "%{TIMESTAMP_ISO8601:timestamp} %{WORD:loglevel}"]
}

```

if condition is working but again all fields applying the last filter also, how exclude las grok filter to above fields ?

---

<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 17, 2018, 1:45pm UTC](https://discuss.elastic.co/t/if-condition-in-logstash-filter/157369/2 "2018-12-17T13:45:19Z")

</div>

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