# How to add a field if the string matches a word in message

**URL:** <https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804>\
**Category:** Logstash\
**Created:** [November 18, 2020, 8:32am UTC](https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804 "2020-11-18T08:32:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guhan\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guhan_s/32/77692_2.png) [@Guhan\_S](https://discuss.elastic.co/u/Guhan_S)\
**Post date:** [November 18, 2020, 8:32am UTC](https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804/1 "2020-11-18T08:32:24Z")

</div>

{"level":30,"time":1605686969640,"pid":1,"hostname":"ip-100-91-70-500","name":"ZA-dev",  
this is my sample logs,  
here i am trying to achieve, if level:30 in message it has to create info log-level,  
i tired  
filter {  
if [level] == "30" {  
mutate { add\_field =\> ["log-level", "info"]  
}  
}  
}  
but not getting correct requirement. i am new to elk, can someone please tell me how to achieve this ![lo](https://us1.discourse-cdn.com/elastic/original/3X/1/f/1f10334d0db8dc813ce2fdb4b52d2f4700616d20.jpeg)

---

<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 18, 2020, 3:04pm UTC](https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804/2 "2020-11-18T15:04:40Z")

</div>

If the [message] field is valid JSON then you could use a json filter to parse it

```
json { source => "message" }

```

You will then have a [level] field that you can test

```
if [level] == 30
    ...
```

---

<div class="post-metadata">

**Author:** ![Guhan\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guhan_s/32/77692_2.png) [@Guhan\_S](https://discuss.elastic.co/u/Guhan_S)\
**Post date:** [December 1, 2020, 6:10am UTC](https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804/3 "2020-12-01T06:10:40Z")

</div>

thanks man, its works.

---

<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 29, 2020, 6:10am UTC](https://discuss.elastic.co/t/how-to-add-a-field-if-the-string-matches-a-word-in-message/255804/4 "2020-12-29T06:10:42Z")

</div>

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