# Multiple match option in grok

**URL:** <https://discuss.elastic.co/t/multiple-match-option-in-grok/83590>\
**Category:** Logstash\
**Created:** [April 25, 2017, 3:56pm UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590 "2017-04-25T15:56:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darya\_Semenova](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@Darya\_Semenova](https://discuss.elastic.co/u/Darya_Semenova)\
**Post date:** [April 25, 2017, 3:56pm UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/1 "2017-04-25T15:56:26Z")

</div>

I have a question about several matches in grok filter.  
Am I right to assume that with multiple matches, even if the log will be parsed successfully by one of them, it will still be \_grokparsefailure in tags, cause of mismatch with the other match expressions?

---

<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:** [April 25, 2017, 4:07pm UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/2 "2017-04-25T16:07:22Z")

</div>

To avoid misunderstandings, please use examples as much as possible instead of describing things in words. Are you talking about a single grok filter with multiple expressions?

```nohighlight
grok {
  match => {
    "message" => ["expr1", "expr2", ..., "exprN"]
  }
}

```

In this case you'll only get a `_grokparsefailure` if _none_ of the expressions matched.

---

<div class="post-metadata">

**Author:** ![Darya\_Semenova](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@Darya\_Semenova](https://discuss.elastic.co/u/Darya_Semenova)\
**Post date:** [April 26, 2017, 8:37am UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/3 "2017-04-26T08:37:50Z")

</div>

Oh, thank you for the answer! That's what I meant, sorry for being too vague.

---

<div class="post-metadata">

**Author:** ![Darya\_Semenova](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@Darya\_Semenova](https://discuss.elastic.co/u/Darya_Semenova)\
**Post date:** [April 26, 2017, 9:12am UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/4 "2017-04-26T09:12:59Z")

</div>

For some reason, though, code like this:

```
filter {
    if [type] == "syslog" {
        grok {
            match => {
                "message" => ["%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: Launching batch job %{NUMBER:job_id} for UID %{POSINT:slurm_user_id}","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: launch task %{NUMBER:job_id} request from %{PROG:slurm_host} (\(port %{POSINT:slurm_port}\))","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: _run_prolog: run job script took usec=%{NUMBER:slurm_usec}","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: _run_prolog: prolog with lock for job %{POSINT:job_id} ran for %{NUMBER:slurm_time}"]
       }
       add_field => ["received_at", "%{@timestamp}"]
       add_field => ["received_from", "%{host}"]
       }
   }

   syslog_pri { }

   if !("_grokparsefailure" in [tags]) {
        mutate {
           add_tag => "parsed_by_slurm_filter"
        }
    }
    mutate {
        rename => { "syslog_message" => "message" }
    }
}

```

gets logstash to stop working. Why?

---

<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:** [April 26, 2017, 9:17am UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/5 "2017-04-26T09:17:33Z")

</div>

What does "stop working" mean, exactly?

---

<div class="post-metadata">

**Author:** ![Darya\_Semenova](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@Darya\_Semenova](https://discuss.elastic.co/u/Darya_Semenova)\
**Post date:** [April 26, 2017, 9:30am UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/6 "2017-04-26T09:30:50Z")

</div>

That means that logstash doesn't compile, and therefore it is unable to send or parse logs in any way.

---

<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:** [April 26, 2017, 9:34am UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/7 "2017-04-26T09:34:50Z")

</div>

Seems to work fine here:

```nohighlight
$ cat test.config 
filter {
    if [type] == "syslog" {
        grok {
            match => {
                "message" => ["%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: Launching batch job %{NUMBER:job_id} for UID %{POSINT:slurm_user_id}","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: launch task %{NUMBER:job_id} request from %{PROG:slurm_host} (\(port %{POSINT:slurm_port}\))","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: _run_prolog: run job script took usec=%{NUMBER:slurm_usec}","%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\[%{POSINT:syslog_pid}\])?: _run_prolog: prolog with lock for job %{POSINT:job_id} ran for %{NUMBER:slurm_time}"]
       }
       add_field => ["received_at", "%{@timestamp}"]
       add_field => ["received_from", "%{host}"]
       }
   }

   syslog_pri { }

   if !("_grokparsefailure" in [tags]) {
        mutate {
           add_tag => "parsed_by_slurm_filter"
        }
    }
    mutate {
        rename => { "syslog_message" => "message" }
    }
}
$ /opt/logstash/bin/logstash -f test.config --configtest
Configuration OK

```

---

<div class="post-metadata">

**Author:** ![Darya\_Semenova](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@Darya\_Semenova](https://discuss.elastic.co/u/Darya_Semenova)\
**Post date:** [April 26, 2017, 12:01pm UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/8 "2017-04-26T12:01:26Z")

</div>

Yeah, everything works now, thanks. It was another software that stood in the way.

---

<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 24, 2017, 12:04pm UTC](https://discuss.elastic.co/t/multiple-match-option-in-grok/83590/9 "2017-05-24T12:04:06Z")

</div>

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