# Grok filter if condition issue

**URL:** <https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619>\
**Category:** Logstash\
**Created:** [September 3, 2015, 2:33pm UTC](https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619 "2015-09-03T14:33:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navneet\_Mathpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet_mathpal/32/3677_2.png) [@Navneet\_Mathpal](https://discuss.elastic.co/u/Navneet_Mathpal)\
**Post date:** [September 3, 2015, 2:33pm UTC](https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619/1 "2015-09-03T14:33:55Z")

</div>

Hi All,

how we can use if command in grok  
some logs contain tag method  
ex : "method" =\> "get" // I am able to parse the log  
I want to add another field , if I am getting the log which is having tag called method  
**I was doing like** but I am not able to do it , any idea where I am doing wrong

filter{  
grok {  
patterns\_dir =\> "D:/log\_file/patterns"  
match =\> ["message", "%{MASTER\_LOG}"]  
}  
if["method" in [tags]]  
{

add\_field =\> ["newtag", "manualtag"]

}  
}

---

<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:** [September 3, 2015, 6:04pm UTC](https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619/2 "2015-09-03T18:04:26Z")

</div>

This isn't a grok question, it's a general filter question. This is probably what you're looking for:

```
filter {
  ...
  if "method" in [tags] {
    mutate {
      add_tag => ["newtag", "manualtag"]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Navneet\_Mathpal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/navneet_mathpal/32/3677_2.png) [@Navneet\_Mathpal](https://discuss.elastic.co/u/Navneet_Mathpal)\
**Post date:** [September 4, 2015, 9:01am UTC](https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619/3 "2015-09-04T09:01:47Z")

</div>

@magnusbaeck Thank you 🙂 Working fine ..

---

<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:** [July 6, 2017, 5:30am UTC](https://discuss.elastic.co/t/grok-filter-if-condition-issue/28619/4 "2017-07-06T05:30:05Z")

</div>


