# Grok then test nested field

**URL:** <https://discuss.elastic.co/t/grok-then-test-nested-field/193389>\
**Category:** Logstash\
**Created:** [August 1, 2019, 6:27pm UTC](https://discuss.elastic.co/t/grok-then-test-nested-field/193389 "2019-08-01T18:27:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paniccontrol](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@paniccontrol](https://discuss.elastic.co/u/paniccontrol)\
**Post date:** [August 1, 2019, 6:27pm UTC](https://discuss.elastic.co/t/grok-then-test-nested-field/193389/1 "2019-08-01T18:27:56Z")

</div>

Hello,

I'm encounter some issue on testing nested field after a grok.

`grok { match => { "message" => [".*(?<event.action>test) xxxx %{DATA:[name]}" ] } if ( "" in [event][action] ) { mutate { remove_field => "message" } }`  
But it never remove my message field, wheter [event][action] exist or 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:** [August 1, 2019, 6:39pm UTC](https://discuss.elastic.co/t/grok-then-test-nested-field/193389/2 "2019-08-01T18:39:21Z")

</div>

If you only want to remove the message field if the grok succeeds then use

```
grok {
    match => { "message" => "pattern" }
    remove_field => ["message"]
}

```

If the pattern does not match then [message] will not be removed.

---

<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 29, 2019, 6:39pm UTC](https://discuss.elastic.co/t/grok-then-test-nested-field/193389/3 "2019-08-29T18:39:24Z")

</div>

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