# If condition working but not else

**URL:** https://discuss.elastic.co/t/if-condition-working-but-not-else/175385
**Category:** Logstash
**Created:** [April 4, 2019, 10:25am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385 "2019-04-04T10:25:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)
#### Post date: [April 4, 2019, 10:25am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/1 "2019-04-04T10:25:56Z")

</div>

I have a random log file which contain diff data, I have created fields in it using mutate filter, my if conditions are working but not my else conditions working.

log line : 90-50-31: ill ill you are You

if [ty] =~ "YOU" or "you" {  
mutate {  
gsub =\> ["field", "[a-zA-Z]+" , "" ]  
}  
} else {  
mutate { gsub =\> ["field", "[0-9]+" , "" ] }  
}

not any else is working, drop filter in else drops every thing and my data for next field becomes invisible

---

<div class="post-metadata">

### Author: ![shrikantgulia](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@shrikantgulia](https://discuss.elastic.co/u/shrikantgulia)
#### Post date: [April 4, 2019, 10:31am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/2 "2019-04-04T10:31:38Z")

</div>

can you please paste whole config file

---

<div class="post-metadata">

### Author: ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)
#### Post date: [April 4, 2019, 10:40am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/3 "2019-04-04T10:40:22Z")

</div>

log line : 90-50-31: ill ill you are You  
log line : 90-50-31: ill till you are You  
log line : 90-50-31: ill end you are You

filter {  
translate {  
field =\> "[message]"  
destination =\> "[matched]"  
dictionary =\> [ "till", "drop",  
"end", "drop" ]

```
exact => true
regex => true

```

}  
if [matched] !~ "drop" {  
drop {}

}  
mutate {  
copy =\> { "message" =\> "io" }  
convert =\> { "io" =\> "string" }  
add\_field =\> { "field" =\> "%{io}"}  
}

if [ty] =~ "YOU" or "you" {  
mutate {  
gsub =\> ["field", "[a-zA-Z]+" , "" ]  
}  
} else {  
mutate { gsub =\> ["field", "[0-9]+" , "" ] }  
}  
}

---

<div class="post-metadata">

### Author: ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)
#### Post date: [April 4, 2019, 10:41am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/4 "2019-04-04T10:41:37Z")

</div>

every thing is working fine except any else statement, or give em any else working statement with conf file other than drop filter to get an idea

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [April 4, 2019, 11:36am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/5 "2019-04-04T11:36:31Z")

</div>

> [@sana1](#):
>
> if [ty] =~ "YOU" or "you" {

I would expect to get an error for that. If you want to match either YOU or you then you can use

```
if [ty] =~ /YOU|you/ {

```

If you want it to be case insensitive you can use

```
if [message] =~ /(?i:foo)/ {

```

---

<div class="post-metadata">

### Author: ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)
#### Post date: [April 5, 2019, 7:15am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/6 "2019-04-05T07:15:05Z")

</div>

thanks it worked 🙂

---

<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 3, 2019, 7:15am UTC](https://discuss.elastic.co/t/if-condition-working-but-not-else/175385/7 "2019-05-03T07:15:17Z")

</div>

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