# Grok Named capture group as metadata

**URL:** <https://discuss.elastic.co/t/grok-named-capture-group-as-metadata/288731>\
**Category:** Logstash\
**Created:** [November 9, 2021, 9:16am UTC](https://discuss.elastic.co/t/grok-named-capture-group-as-metadata/288731 "2021-11-09T09:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sirReeall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sirreeall/32/94713_2.png) [@sirReeall](https://discuss.elastic.co/u/sirReeall)\
**Post date:** [November 9, 2021, 9:16am UTC](https://discuss.elastic.co/t/grok-named-capture-group-as-metadata/288731/1 "2021-11-09T09:16:28Z")

</div>

Hello,

I was wondering if it is possible to set a named capture group as [metadata](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html?#metadata) rather then a field sent to Elastic?

I'm parsing some data that has these permutations for the same field:

```auto
1m 125s 345ms
125s 345ms
345ms

```

For this I have the following regex:

`(?<checkpoint_m_duration>[0-9?]*m)? ?(?<checkpoint_s_duration>[0-9?]*s)? ?(?<checkpoint_ms_duration>[0-9]*ms)?`

That give me three fields that I need to strip out the characters (m, s, ms) and then add up. I don't need these three fields (checkpoint\_m\_duration, checkpoint\_s\_duration, checkpoint\_ms\_duration) sent to Elastic and wanted them as metadata so I can process.

---

<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:** [November 9, 2021, 5:47pm UTC](https://discuss.elastic.co/t/grok-named-capture-group-as-metadata/288731/2 "2021-11-09T17:47:57Z")

</div>

Yes, you can use [@metadata], which most outputs ignore.

> [@sirReeall](#):
>
> (?\<[@metadata][checkpoint\_m\_duration]\>[0-9?]\*m)?

---

<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:** [December 7, 2021, 5:48pm UTC](https://discuss.elastic.co/t/grok-named-capture-group-as-metadata/288731/3 "2021-12-07T17:48:26Z")

</div>

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