# In Operator Behaves Unexpectedly When Used in a Filter

**URL:** <https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449>\
**Category:** Logstash\
**Created:** [April 5, 2023, 3:27pm UTC](https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449 "2023-04-05T15:27:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![foxfire-auspex](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@foxfire-auspex](https://discuss.elastic.co/u/foxfire-auspex)\
**Post date:** [April 5, 2023, 3:27pm UTC](https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449/1 "2023-04-05T15:27:52Z")

</div>

Hello,

I just had a very strange experience debugging one of our Logstash filters and would like to know whether we could have anticipated this or encountered a known quirk or bug (we run Logstash v7.17).

Please see below simplified filter:

```auto
filter {
	if [type] == 'some_type' {
		if [some_field] in ["some_value1", "some_value2", "some_value3"] {
			mutate {
				add_tag => ["some_tag1"]
			}
		} else if [some_field] in ["another_value1"] {
			mutate {
				add_tag => ["another_tag1"]
			}
		} else {
			drop { }
		}
	}
}

```

If written like that, the middle else-if-block is never reached even though the docs regarding comparison operators and conditional statements led me to believe that it should.

The fix was simple enough:

```auto
		} else if [some_field] == "another_value1" {

```

but strangely, adding another item to the collection also made it work as expected:

```auto
		} else if [some_field] in ["another_value1", "another_value2"] {

```

Especially the latter fix has me thinking I might have stumbled upon a bug here.  
Is that true or am I missing something? Does this have something to do with some backend Ruby magic I'm unaware of?

---

<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 5, 2023, 4:17pm UTC](https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449/2 "2023-04-05T16:17:47Z")

</div>

It is a [known issue](https://github.com/elastic/logstash/issues/9932) which I doubt will ever be fixed. if ... in does not work for single member arrays.

---

<div class="post-metadata">

**Author:** ![foxfire-auspex](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@foxfire-auspex](https://discuss.elastic.co/u/foxfire-auspex)\
**Post date:** [April 6, 2023, 8:42am UTC](https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449/3 "2023-04-06T08:42:59Z")

</div>

Thank you very much for finding and linking that issue. I apologize for having missed this during my prior research.

---

<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 4, 2023, 8:43am UTC](https://discuss.elastic.co/t/in-operator-behaves-unexpectedly-when-used-in-a-filter/329449/4 "2023-05-04T08:43:43Z")

</div>

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