# How to create new logstash grok field

**URL:** https://discuss.elastic.co/t/how-to-create-new-logstash-grok-field/320722
**Category:** Logstash
**Created:** [December 7, 2022, 10:29pm UTC](https://discuss.elastic.co/t/how-to-create-new-logstash-grok-field/320722 "2022-12-07T22:29:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![anon74213320](https://avatars.discourse-cdn.com/v4/letter/a/d78d45/32.png) [@anon74213320](https://discuss.elastic.co/u/anon74213320)
#### Post date: [December 7, 2022, 10:29pm UTC](https://discuss.elastic.co/t/how-to-create-new-logstash-grok-field/320722/1 "2022-12-07T22:29:52Z")

</div>

I have an ELK stack Filebeat---\>Logstash----\>Elasticsearch\<----Kibana.

I m shipping the logs in a proper way, but I would need to add a custom fields available in Kibana, for searching puproses.

The Log file contains a source host and a destination host like in this format:

```auto
Source : \\abc123\xxx\xxx
Dest : \\def456\xxx\xxx

```

I need now to create two custom fields to being available in kibana

- source\_cluster: abc123
- destination\_cluster: def456

I tried with custom pattern in grok, creating a pattern directory like this:

filter {  
grok {  
patterns\_dir =\> ["/usr/share/logstash/pipeline/patterns"]

* * *

but it is not taken into account when I reference it so:

match =\> { "message" =\> "%{SOURCE\_CLUSTER:source\_cluster}"}

* * *

in pattern directory I created an extra file with this content:

SOURCE\_CLUSTER (Source...)(\\w+)

I tested it and regex is correct it is able to catch "Source : \abc123"  
I tried also with kv but no luck.

Many Thanks

---

<div class="post-metadata">

### Author: ![sai\_saran1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sai_saran1/32/116661_2.png) [@sai\_saran1](https://discuss.elastic.co/u/sai_saran1)
#### Post date: [December 27, 2022, 6:35pm UTC](https://discuss.elastic.co/t/how-to-create-new-logstash-grok-field/320722/2 "2022-12-27T18:35:57Z")

</div>

If you want to add a new field, try with mutate filter. As you already have source\_cluster and destination\_cluster coming from grok filters try something like below

```auto
mutate {
     add_field => {
        "source_cluster" => %{SOURCE_CLUSTER}
        "destination_cluster" => %{SOURCE_CLUSTER}
       }
  }

```

Hope this helps.

---

<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 24, 2023, 6:36pm UTC](https://discuss.elastic.co/t/how-to-create-new-logstash-grok-field/320722/3 "2023-01-24T18:36:25Z")

</div>

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