# How to add multiple grok pattern in one filter?

**URL:** https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622
**Category:** Logstash
**Created:** [April 19, 2018, 4:45am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622 "2018-04-19T04:45:12Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![RameshNagargoje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshnagargoje/32/30212_2.png) [@RameshNagargoje](https://discuss.elastic.co/u/RameshNagargoje)
#### Post date: [April 19, 2018, 4:45am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/1 "2018-04-19T04:45:12Z")

</div>

Hi,  
My use case is to match one of the regex using multiple grok in one filter.Tried using multiple filter but not matching one of the pattern even though that pattern is present in input.

Here is my filter

filter  
{

json  
{  
source =\> "message"  
target =\> "message"  
}

if[type] == 'dmesg'  
{

```
grok
  {
    match => { logs => "killed by TERM signal" }
  	add_field => {"tagName"=>"GENERIC_EMERGENCY"}
		  add_field => {"module" => "null"}
}
	
grok
{
  	match => { logs => "^<1>" }
    add_field => {"tagName"=>"GENERIC_ALERT"}
		  add_field => {"module" => "null"}
}

  grok
{
    match => { logs => "^<3>" }
    add_field => {"tagName"=>"GENERIC_ERROR"}
		  add_field => {"module" => "null"}
}

grok
{
    match => { logs => "^<4>" }
    add_field => {"tagName"=>"GENERIC_WARNING"}
		  add_field => {"module" => "null"}
}

}

```

if "\_grokparsefailure" in [tags]  
{  
drop { }  
}

}

---

<div class="post-metadata">

### Author: ![RameshNagargoje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshnagargoje/32/30212_2.png) [@RameshNagargoje](https://discuss.elastic.co/u/RameshNagargoje)
#### Post date: [April 19, 2018, 4:45am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/2 "2018-04-19T04:45:51Z")

</div>

@magnusbaeck please have look

---

<div class="post-metadata">

### Author: ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)
#### Post date: [April 19, 2018, 5:40am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/3 "2018-04-19T05:40:18Z")

</div>

Hi,  
This can be easily achieved by using multiple grok patterns. You need to do something like this:

```auto
grok
{
  match => { "message" => "killed by TERM signal" }
  add_field => 
  {
    "tagName"=> "GENERIC_EMERGENCY"  
    "module" => "null"
  }
}

```

It matches "message" with the pattern. Sorry If I am getting it wrong but what is "logs" in your case? Do you get it in json format as a field?

---

<div class="post-metadata">

### Author: ![RameshNagargoje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshnagargoje/32/30212_2.png) [@RameshNagargoje](https://discuss.elastic.co/u/RameshNagargoje)
#### Post date: [April 19, 2018, 5:41am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/4 "2018-04-19T05:41:49Z")

</div>

yes i get logs as input instead of message.

---

<div class="post-metadata">

### Author: ![MariumHassan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mariumhassan/32/30321_2.png) [@MariumHassan](https://discuss.elastic.co/u/MariumHassan)
#### Post date: [April 19, 2018, 5:51am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/5 "2018-04-19T05:51:52Z")

</div>

Try using this:

```auto
grok
{
  match => ["message" , "killed by TERM signal"]
  add_field => 
  {
    "tagName"=> "GENERIC_EMERGENCY"  
    "module" => "null"
  }
}

```

What you get as an input is stored in "message". Try to match it with one pattern just to see if it is working fine, and then you can add multiple grok patterns in your file.  
Can you share json of your logs simply using this?

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

```

---

<div class="post-metadata">

### Author: ![RameshNagargoje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rameshnagargoje/32/30212_2.png) [@RameshNagargoje](https://discuss.elastic.co/u/RameshNagargoje)
#### Post date: [April 19, 2018, 10:23am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/6 "2018-04-19T10:23:01Z")

</div>

thanks @MariumHassan

---

<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: [May 17, 2018, 10:23am UTC](https://discuss.elastic.co/t/how-to-add-multiple-grok-pattern-in-one-filter/128622/7 "2018-05-17T10:23:28Z")

</div>

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