# If statement in grok filter

**URL:** <https://discuss.elastic.co/t/if-statement-in-grok-filter/112186>\
**Category:** Logstash\
**Created:** [December 18, 2017, 9:18am UTC](https://discuss.elastic.co/t/if-statement-in-grok-filter/112186 "2017-12-18T09:18:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shwesinhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shwesinhan/32/78663_2.png) [@shwesinhan](https://discuss.elastic.co/u/shwesinhan)\
**Post date:** [December 18, 2017, 9:18am UTC](https://discuss.elastic.co/t/if-statement-in-grok-filter/112186/1 "2017-12-18T09:18:46Z")

</div>

hi everyone!

is there anyway to check aws logstream name in logstash grok filter?

eg:

```
filter {	
	if "cloudwatch_logs.log_stream" == "TEST1" {  
		grok {
			# type1			
			match => { "message" => ["^(?<log_timestamp>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{1,3}).*?PROJ1(?<threadno>\d+).*%{WORD:log_level}.*?(?<session_id>\w+)\s{0,}:::\s{0,}RECEIVED\sDATA\s{0,}:"]}
			add_field => { "project_type" => "PROJ1" }
			add_field => { "transaction_type" => "TYPE1" }
		}
		
		grok {
			# type2
			match => { "message" => ["^(?<log_timestamp>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{1,3}).*?(?<threadno>\d+).*%{WORD:log_level}.*?PROJ2\s+:\s+(?<session_id>\w+)\s{0,}:::\s{0,}\sRequest\s{0,}:"]}
			add_field => { "project_type" => "PROJ2" }
			add_field => { "transaction_type" => "TYPE2" }
		}	
	}
	
	else if [cloudwatch_logs.log_stream] == "TEST2" {  		
		.....	
	}

      else if [cloudwatch_logs.log_stream] == "TEST3" {  		
		.....	
	}
}
```

---

<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:** [December 18, 2017, 9:28am UTC](https://discuss.elastic.co/t/if-statement-in-grok-filter/112186/2 "2017-12-18T09:28:32Z")

</div>

Yes.

You're probably referencing the field name in the wrong way. See [https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#logstash-config-field-references](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#logstash-config-field-references) for how to reference nested fields.

---

<div class="post-metadata">

**Author:** ![shwesinhan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shwesinhan/32/78663_2.png) [@shwesinhan](https://discuss.elastic.co/u/shwesinhan)\
**Post date:** [December 18, 2017, 10:27am UTC](https://discuss.elastic.co/t/if-statement-in-grok-filter/112186/3 "2017-12-18T10:27:35Z")

</div>

thank you @magnusbaeck  
it works!

---

<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:** [January 15, 2018, 10:28am UTC](https://discuss.elastic.co/t/if-statement-in-grok-filter/112186/4 "2018-01-15T10:28:08Z")

</div>

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