# Match field to string in IF statement

**URL:** <https://discuss.elastic.co/t/match-field-to-string-in-if-statement/124956>\
**Category:** Logstash\
**Created:** [March 21, 2018, 10:01am UTC](https://discuss.elastic.co/t/match-field-to-string-in-if-statement/124956 "2018-03-21T10:01:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![No\_Executable](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/no_executable/32/29075_2.png) [@No\_Executable](https://discuss.elastic.co/u/No_Executable)\
**Post date:** [March 21, 2018, 10:01am UTC](https://discuss.elastic.co/t/match-field-to-string-in-if-statement/124956/1 "2018-03-21T10:01:01Z")

</div>

I am trying to push different log types through the same logstash config file. I have managed to get the log type from the path and filename into a separate field and now I want it to run different sets of configurations depending on the new **logtype** field.

```
filter {
	grok {
		match => {"source" => "%{GREEDYDATA:path}\\%{GREEDYDATA:logtype}.w3wp.default.%{GREEDYDATA:filetimestamp}.log"}
	}
	xml {
        	source => 'message'
        	target => 'doc'
    }
	if ("[logtype]" == "Commandusage") {
		mutate {
			split => {"[doc][Message]" => "	"}
    	}
	}
	else if ("[logtype]" == "ClientErrors") {
		mutate {
			split => {"[doc][Message]" => ". "}
		}
	}
}

```

It runs without error but it ignores the if statements and doesn't split [doc][Message] in either way.

---

<div class="post-metadata">

**Author:** ![No\_Executable](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/no_executable/32/29075_2.png) [@No\_Executable](https://discuss.elastic.co/u/No_Executable)\
**Post date:** [March 21, 2018, 10:45am UTC](https://discuss.elastic.co/t/match-field-to-string-in-if-statement/124956/2 "2018-03-21T10:45:22Z")

</div>

Turns out I brainfarted real bad and missed that that's not how the **if** statements should look like.

Changed them to

```
if ("Commandusage" in [logtype]) {
	mutate {
		split => {"[doc][Message]" => "	"}
	}
}
else if ("ClientErrors" in [logtype]) {
	mutate {
		split => {"[doc][Message]" => ". "}
	}
}

```

and it works now

---

<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:** [April 18, 2018, 10:45am UTC](https://discuss.elastic.co/t/match-field-to-string-in-if-statement/124956/3 "2018-04-18T10:45:23Z")

</div>

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