# Referencing captured groups inside yaml file

**URL:** <https://discuss.elastic.co/t/referencing-captured-groups-inside-yaml-file/303337>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [April 27, 2022, 1:36am UTC](https://discuss.elastic.co/t/referencing-captured-groups-inside-yaml-file/303337 "2022-04-27T01:36:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/draken/32/104710_2.png) [@Draken](https://discuss.elastic.co/u/Draken)\
**Post date:** [April 27, 2022, 1:36am UTC](https://discuss.elastic.co/t/referencing-captured-groups-inside-yaml-file/303337/1 "2022-04-27T01:36:23Z")

</div>

Hello, I'm running the `postgresql` module in `metricbeat` with the `statement` metricset active, i want to be able to determine the type of the query (insert, update, select or delete),  
so i add an `add_fields` processor with a `regexp` condition to match a certain pattern that includes a captured group and i want the captured string of that group to be add as a value for the created field, the problem is i don't know how to reference the captured group in the processor config, this is what i have tried:

```auto
processors:
    - add_fields:
        when:
          regexp:
             postgresql.statement.query.text: (?i)(?:\/\*.*\*\/)?(select|insert|update|delete)+.*
        target: postgresql
        fields:
            statement.query.type: "..." #here is where i want the captured group to be refrenced

```

I made these attempts but with no luck:

```auto
postgresql.statement.query.text: $1
postgresql.statement.query.text: %{$1}
postgresql.statement.query.text: %{1}
postgresql.statement.query.text: %{[1]}

```

Is this even possible ?

---

<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 25, 2022, 3:36am UTC](https://discuss.elastic.co/t/referencing-captured-groups-inside-yaml-file/303337/2 "2022-05-25T03:36:26Z")

</div>

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