# Help with logstash conditional filter

**URL:** <https://discuss.elastic.co/t/help-with-logstash-conditional-filter/322402>\
**Category:** Logstash\
**Created:** [January 3, 2023, 7:42pm UTC](https://discuss.elastic.co/t/help-with-logstash-conditional-filter/322402 "2023-01-03T19:42:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaonyO](https://avatars.discourse-cdn.com/v4/letter/r/5fc32e/32.png) [@RaonyO](https://discuss.elastic.co/u/RaonyO)\
**Post date:** [January 3, 2023, 7:42pm UTC](https://discuss.elastic.co/t/help-with-logstash-conditional-filter/322402/1 "2023-01-03T19:42:39Z")

</div>

Hello, I'm trying to create a filter to drop events that don't have Lateral attack or Vulnerability exploit attack in the message field. but it is giving error, I would like to know what is wrong and what is the correct way.  
here's the filter:

```auto
filter {
if 'Lateral attack' or 'Vulnerability exploit attack' not in [message] { mutate { drop { } } }

}

```

---

<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:** [January 3, 2023, 7:49pm UTC](https://discuss.elastic.co/t/help-with-logstash-conditional-filter/322402/2 "2023-01-03T19:49:48Z")

</div>

> [@RaonyO](#):
>
> `if 'Lateral attack' or 'Vulnerability exploit attack' not in [message] { mutate { drop { } } }`

That gets parsed as the `or` of two conditions. The first being `Lateral attack`, which will evaluate to true, and the second being `'Vulnerability exploit attack' not in [message]`. The or will always be true, so everything should be getting dropped.

Also drop {} is a filter by itself, not an option of the mutate filter (this will produce an error message).

Use a match to a regexp with alternation:

```
if [message] !~ /(Lateral attack|Vulnerability exploit attack)/ { drop { } }

```

---

<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 31, 2023, 7:49pm UTC](https://discuss.elastic.co/t/help-with-logstash-conditional-filter/322402/3 "2023-01-31T19:49:59Z")

</div>

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