# How to create a logstash filter for index the logs with specific word only

**URL:** <https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948>\
**Category:** Logstash\
**Created:** [July 6, 2018, 3:20pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948 "2018-07-06T15:20:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rijinmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rijinmp/32/24634_2.png) [@rijinmp](https://discuss.elastic.co/u/rijinmp)\
**Post date:** [July 6, 2018, 3:20pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948/1 "2018-07-06T15:20:32Z")

</div>

I want to index only the logs contain the word "production" , anywhere in the log .

if the word " production" not present in log ... i dont want to index that line

---

<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:** [July 6, 2018, 3:33pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948/2 "2018-07-06T15:33:10Z")

</div>

> [@rijinmp](#):
>
> if the word " production" not present in log ... i dont want to index that line

```
if [message] !~ "production" { drop {} }

```

---

<div class="post-metadata">

**Author:** ![rijinmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rijinmp/32/24634_2.png) [@rijinmp](https://discuss.elastic.co/u/rijinmp)\
**Post date:** [July 6, 2018, 3:48pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948/3 "2018-07-06T15:48:02Z")

</div>

Thank you badger . It is working well . May i add one more word with this production .

Like Production or Deliver

I want to drop the lines those not contains Production or Deliver.

---

<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:** [July 6, 2018, 4:34pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948/4 "2018-07-06T16:34:33Z")

</div>

If you want to keep lines only if they contain both then

```
if [message] !~ "production" or [message] !~ "deliver" { drop {} }

```

If you want to keep lines that contain either then

```
if [message] =~ "production" or [message] =~ "deliver" {} else { 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:** [August 3, 2018, 4:45pm UTC](https://discuss.elastic.co/t/how-to-create-a-logstash-filter-for-index-the-logs-with-specific-word-only/138948/5 "2018-08-03T16:45:01Z")

</div>

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