# How to use and in logstash filter

**URL:** <https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376>\
**Category:** Logstash\
**Created:** [November 25, 2019, 9:04pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376 "2019-11-25T21:04:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![srbhklkrn](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@srbhklkrn](https://discuss.elastic.co/u/srbhklkrn)\
**Post date:** [November 25, 2019, 9:04pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/1 "2019-11-25T21:04:23Z")

</div>

I want to check `if "domain" and "[100]" in [message] { drop { } }` but it is dropping only first "domain" and not "[100]".

What am I doing wrong?

---

<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:** [November 25, 2019, 9:43pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/2 "2019-11-25T21:43:39Z")

</div>

I believe that is testing is the field [domain] exists and whether the string [100] is a substring of [message]. What do you actually want to test?

---

<div class="post-metadata">

**Author:** ![srbhklkrn](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@srbhklkrn](https://discuss.elastic.co/u/srbhklkrn)\
**Post date:** [November 26, 2019, 1:50pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/3 "2019-11-26T13:50:13Z")

</div>

I need to test two conditions before dropping the log. If message has "domain" and "[100]" then drop it else not.

---

<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:** [November 26, 2019, 1:53pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/4 "2019-11-26T13:53:35Z")

</div>

Do you want to test whether it contains those two strings?

---

<div class="post-metadata">

**Author:** ![srbhklkrn](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@srbhklkrn](https://discuss.elastic.co/u/srbhklkrn)\
**Post date:** [November 26, 2019, 1:55pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/5 "2019-11-26T13:55:40Z")

</div>

Yes if those exists in one message.

---

<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:** [November 26, 2019, 1:57pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/6 "2019-11-26T13:57:45Z")

</div>

Then you need two substring matches. I think that would be

```
if "domain" in [message] and "[100]" in [message] { drop { } }
```

---

<div class="post-metadata">

**Author:** ![srbhklkrn](https://avatars.discourse-cdn.com/v4/letter/s/e480ec/32.png) [@srbhklkrn](https://discuss.elastic.co/u/srbhklkrn)\
**Post date:** [November 26, 2019, 2:08pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/7 "2019-11-26T14:08:56Z")

</div>

it works only with string or numbers I tried with just 100 and it worked but did not worked with "[100]". Just for curiosity does it have any limitations for certain charterers? like ""

---

<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:** [November 26, 2019, 2:24pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/8 "2019-11-26T14:24:28Z")

</div>

I am unable to explain that.

---

<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:** [December 24, 2019, 2:24pm UTC](https://discuss.elastic.co/t/how-to-use-and-in-logstash-filter/209376/9 "2019-12-24T14:24:50Z")

</div>

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