# Can you share named captures between multiple grok processor patterns?

**URL:** <https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777>\
**Category:** Elasticsearch\
**Created:** [December 12, 2016, 9:23pm UTC](https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777 "2016-12-12T21:23:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luk3](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@luk3](https://discuss.elastic.co/u/luk3)\
**Post date:** [December 12, 2016, 9:23pm UTC](https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777/1 "2016-12-12T21:23:01Z")

</div>

Currently when I only include one grok processor pattern, all matching patterns correctly create the named attributes in the Elasticsearch document. However, if I use two or more patterns, and the any of the subsequent patterns match than it appears capture groups that share a name with one of the preceding patterns are not being set. Currently using Elasticsearch 5.0.

Is there a way to accomplish this? Am I doing something wrong?

Here is my example grok filter:

> ```
> {
> "grokv1": {
> "description": "Sample Grok Filter",
> "processors": [
> {
> "grok": {
> "field": "message",
> "patterns": [
> "%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} /%{SLUG:space}/app/apis%{URIPATH:apisPath}(?:%{URIPARAM:params})? %{NUMBER:duration}",
> "%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} /%{SLUG:space}/app/api%{URIPATH:apiPath}(?:%{URIPARAM:params})? %{NUMBER:duration}",
> "%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} %{URIPATH:path}(?:%{URIPARAM:params})? %{NUMBER:duration}"
> ],
> "pattern_definitions": {
> "SLUG": "[a-zA-Z0-9-]+"
> }
> }
> }
> ]
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![luk3](https://avatars.discourse-cdn.com/v4/letter/l/3e96dc/32.png) [@luk3](https://discuss.elastic.co/u/luk3)\
**Post date:** [December 16, 2016, 4:35pm UTC](https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777/2 "2016-12-16T16:35:47Z")

</div>

Just a follow up. I could not get multiple grok filters to work in Elasticsearch 5.0.1 if I follow the instructions in the [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/grok-processor.html). By this I mean, putting multiple grok patterns in a array for the field "patterns" as shown in my first post. I wonder if I was doing something wrong, or if this is a potential bug in an existing feature .

I could, however, use on\_failure to nest each grok pattern in a successive chain. This allows for each pattern to be included in the filter instead of just the first pattern, which was a solution to my original issue.

```
{
  "description": "Sample Grok Filter",
  "processors": [
    {
      "grok": {
        "field": "message",
        "patterns": ["%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} /%{SLUG:space}/app/apis%{URIPATH:apisPath}(?:%{URIPARAM:params})? %{NUMBER:duration}"],
        "pattern_definitions": {
          "SLUG": "[a-zA-Z0-9-]+"
        },
        "on_failure": [
          {
            "grok": {
              "field": "message",
              "patterns": ["%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} /%{SLUG:space}/app/api%{URIPATH:apiPath}(?:%{URIPARAM:params})? %{NUMBER:duration}"],
              "pattern_definitions": {
                "SLUG": "[a-zA-Z0-9-]+"
              },
              "on_failure": [
                {
                  "grok": {
                    "field": "message",
                    "patterns": ["%{TIMESTAMP_ISO8601:timestamp} %{WORD:method} %{URIPATH:path}(?:%{URIPARAM:params})? %{NUMBER:duration}"],
                    "pattern_definitions": {
                      "SLUG": "[a-zA-Z0-9-]+"
                    },
                     ...
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 16, 2016, 5:19pm UTC](https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777/3 "2016-12-16T17:19:53Z")

</div>

I think the initial snippet you posted is the way to go.  
If it does not work as expected, can you reproduce it with a simple script?

For example, just use the `_simulate` API. Then open an issue so this can be fixed?

And link to this discussion if you wish...

Thanks for reporting.

---

<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:** [January 13, 2017, 5:20pm UTC](https://discuss.elastic.co/t/can-you-share-named-captures-between-multiple-grok-processor-patterns/68777/4 "2017-01-13T17:20:09Z")

</div>

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