# Check if nested field exists not working

**URL:** <https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100>\
**Category:** Logstash\
**Created:** [September 11, 2019, 3:10pm UTC](https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100 "2019-09-11T15:10:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdalexndr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cdalexndr/32/55274_2.png) [@cdalexndr](https://discuss.elastic.co/u/cdalexndr)\
**Post date:** [September 11, 2019, 3:10pm UTC](https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100/1 "2019-09-11T15:10:52Z")

</div>

I have the following code in my logstash configuration where gsub is not applied

```
    if[exception][stacktrace] {
        mutate {
            gsub => ["exception.stacktrace","\s*at\s(?!package).*", ""]
        }
    }

```

The `exception.stacktrace` field is set in a grok match above.  
Using the same message, if I remove the conditional, then the gsub is applied as expected, thus the conditional is not working!

I need to use the conditional because my grok matcher has two patterns, one with stacktrace other without it.

Is this a bug, or it's not the correct way to check a nested field existance?

_Logstash 7.3.0_

---

<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:** [September 11, 2019, 3:22pm UTC](https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100/2 "2019-09-11T15:22:51Z")

</div>

> [@cdalexndr](#):
>
> "exception.stacktrace"

If that is a nested field then you have to refer to it as "[exception][stacktrace]" in the gsub. If it has a period in its name then you need to refer to it as [exception.stacktrace] in the conditional.

---

<div class="post-metadata">

**Author:** ![cdalexndr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cdalexndr/32/55274_2.png) [@cdalexndr](https://discuss.elastic.co/u/cdalexndr)\
**Post date:** [September 11, 2019, 6:32pm UTC](https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100/3 "2019-09-11T18:32:26Z")

</div>

Removing only the conditional, and keeping the field name "exception.stacktrace" in gsub works, and my stacktrace is correctly processed, so the issue is not gsub field name:

```auto
 mutate {
            gsub => ["exception.stacktrace","\s*at\s(?!package).*", ""]
        }

```

---

<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:** [October 9, 2019, 6:32pm UTC](https://discuss.elastic.co/t/check-if-nested-field-exists-not-working/199100/4 "2019-10-09T18:32:31Z")

</div>

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