# Alternate to multiple if..else-if in Logstash .conf file

**URL:** https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835
**Category:** Logstash
**Created:** [March 24, 2017, 4:59am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835 "2017-03-24T04:59:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anisen](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anisen](https://discuss.elastic.co/u/anisen)
#### Post date: [March 24, 2017, 4:59am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835/1 "2017-03-24T04:59:22Z")

</div>

Hi,

In my log file, there is a URI field.

Now, I have added another field named 'user\_operation' with a default value and want to assign different values to this 'user\_operation' field depending on the value of the URI field.

In the log file, there are around 100 different URIs and I want to assign different user\_operation values for each of them.

Currently I am using IF..ELSE-IF..ELSE-IF..ELSE-IF... and so on

if [uri] =~ "/\_mysite/login.asmx"{  
mutate {  
update =\> {  
"user\_operation" =\> "User Login"  
}  
}  
}  
else if [uri] =~ "/\_mysite/Pages/PlaceOrder.aspx"{  
mutate {  
update =\> {  
"user\_operation" =\> "Place Order"  
}  
}  
}  
else if [uri] =~ "/\_mysite/LogOut.asmx"{  
mutate {  
update =\> {  
"user\_operation" =\> "Logout"  
}  
}  
}  
.....  
..... and so on.

Its working.  
But, I am not sure how it will impact the performance if there are so many if..else-if conditions in the logstash conf file.

Is there any better way to do this?  
Please suggest.

---

<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: [March 24, 2017, 5:59am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835/2 "2017-03-24T05:59:46Z")

</div>

The translate filter should be helpful here.

---

<div class="post-metadata">

### Author: ![anisen](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anisen](https://discuss.elastic.co/u/anisen)
#### Post date: [March 24, 2017, 6:29am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835/3 "2017-03-24T06:29:15Z")

</div>

Thanks a lot. Will try it out.

---

<div class="post-metadata">

### Author: ![anisen](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@anisen](https://discuss.elastic.co/u/anisen)
#### Post date: [March 24, 2017, 11:20am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835/4 "2017-03-24T11:20:02Z")

</div>

Tried and it served my purpose. Thanks again @magnusbaeck . This is exactly something I was looking for.

---

<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 21, 2017, 11:20am UTC](https://discuss.elastic.co/t/alternate-to-multiple-if-else-if-in-logstash-conf-file/79835/5 "2017-04-21T11:20:15Z")

</div>

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