# Check if string is in field

**URL:** <https://discuss.elastic.co/t/check-if-string-is-in-field/269479>\
**Category:** Logstash\
**Created:** [April 7, 2021, 2:00pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479 "2021-04-07T14:00:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 2:00pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/1 "2021-04-07T14:00:18Z")

</div>

Hi,

I need some help checking if a string is contained within the value of a field.

my json has a key  
"log.file.path.keyword":["myfolder/mypath/mylog.log"

I tried to parse it with

```auto
filter{
if "mylog.log" in [log.file.path.keyword] {do something{}}
}

```

I tried also with

```auto
filter{
if "mylog.log" in [log][file][path][keyword] {do something{}}
}

```

In the table view I can see it named as `log.file.path` with the right value, but under that value there is a field called "Multi fields" with a log.file.path.keyword item having the same value as above.  
Is this correct? How can i parse it correctly?

Thank you!

---

<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 7, 2021, 2:34pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/2 "2021-04-07T14:34:06Z")

</div>

keyword is an elasticsearch construct, it does not exist in logstash. Use

```
if "mylog.log" in [log][file][path] {do something{}}
```

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 5:15pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/3 "2021-04-07T17:15:06Z")

</div>

Thank you Badger! Still doesn’t seem to find the string. In discover the field name is “log.file.path” should I try [log.file.path] ?

---

<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 7, 2021, 5:33pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/4 "2021-04-07T17:33:39Z")

</div>

If you expand an event in the Kibana discover interface and click on the JSON tab, what does that field look like?

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 5:55pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/5 "2021-04-07T17:55:30Z")

</div>

It has

```auto
“fields”:{
 ...
 “log.file.path”:[“mydirs/mydir/myfile.log”],
“agent.type”: [“filebeat”]
...
}

```

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 5:58pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/6 "2021-04-07T17:58:04Z")

</div>

What is strange is that there is no tag field

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 6:07pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/7 "2021-04-07T18:07:11Z")

</div>

When i do

```auto
If ![local][file][path]{
  mutate {add_field => {“myfield” => “notthere”}}}

```

I receive an extra field with the value ` not there`  
😇

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 6:20pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/8 "2021-04-07T18:20:28Z")

</div>

The field `log.file.path` is visible under available fields also

---

<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 7, 2021, 6:33pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/9 "2021-04-07T18:33:50Z")

</div>

> [@Automation\_Scripts](#):
>
> `“log.file.path”:[“mydirs/mydir/myfile.log”]`

That is an array. Use

```
if "mylog.log" in [log][file][path][0] {do something{}}

```

---

<div class="post-metadata">

**Author:** ![Automation\_Scripts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/automation_scripts/32/85374_2.png) [@Automation\_Scripts](https://discuss.elastic.co/u/Automation_Scripts)\
**Post date:** [April 7, 2021, 7:20pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/10 "2021-04-07T19:20:18Z")

</div>

Man u rock! You’re really awesome!!!

---

<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 5, 2021, 7:20pm UTC](https://discuss.elastic.co/t/check-if-string-is-in-field/269479/11 "2021-05-05T19:20:46Z")

</div>

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