# Will Grok fail if the grok field does not exist?

**URL:** <https://discuss.elastic.co/t/will-grok-fail-if-the-grok-field-does-not-exist/58300>\
**Category:** Logstash\
**Created:** [August 17, 2016, 11:03pm UTC](https://discuss.elastic.co/t/will-grok-fail-if-the-grok-field-does-not-exist/58300 "2016-08-17T23:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [August 17, 2016, 11:03pm UTC](https://discuss.elastic.co/t/will-grok-fail-if-the-grok-field-does-not-exist/58300/1 "2016-08-17T23:03:13Z")

</div>

Given that I have the following grok

```auto
filter {
  grok { match => { "my_abc" => "Duration: %{NUMBER:duration}" } }
}

```

Will grok fail if the `my_abc` field does not exist in the message?  
Would it be necessary to check for field existence first as in

```auto
filter {
  if [my_abc] {
      grok { match => { "my_abc" => "Duration: %{NUMBER:duration}" } }
  }
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [August 18, 2016, 5:35pm UTC](https://discuss.elastic.co/t/will-grok-fail-if-the-grok-field-does-not-exist/58300/2 "2016-08-18T17:35:59Z")

</div>

Easy enough to test, right?

```nohighlight
$ echo '' | /opt/logstash/bin/logstash -e 'filter { grok { match => { "does not exist" => "does not match" } } }'
Settings: Default pipeline workers: 8
Pipeline main started
{
       "message" => "",
      "@version" => "1",
    "@timestamp" => "2016-08-18T17:34:39.876Z",
          "type" => "stdin",
          "host" => "bertie",
          "tags" => [
        [0] "_grokparsefailure"
    ]
}
Pipeline main has been shutdown
stopping pipeline {:id=>"main"}

```

---

<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:** [July 6, 2017, 4:42am UTC](https://discuss.elastic.co/t/will-grok-fail-if-the-grok-field-does-not-exist/58300/3 "2017-07-06T04:42:43Z")

</div>


