# Adding prefex to the field extracted via KV plugin

**URL:** https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621
**Category:** Logstash
**Created:** [June 22, 2021, 8:39am UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621 "2021-06-22T08:39:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![frank\_rib](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frank_rib/32/104372_2.png) [@frank\_rib](https://discuss.elastic.co/u/frank_rib)
#### Post date: [June 22, 2021, 8:39am UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621/1 "2021-06-22T08:39:19Z")

</div>

Hello every body,

> Apr 1 15:00:01 pc-tst cft: 21/04/20 00:00:00 CFTC12I IDTU=A0007GK PART=LKOR STATE=Y PHASE=Y PHASESTEP=C DIRECT=S TYPE=F SENTINEL\_STATE=POST\_PROC Deleted

Is there a method to rename the fields extracted via the kv plugin by adding a prefex (example ctf): SENTINEL\_STATE by ctf.SENTINEL\_STATE?  
Best regards,

---

<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: [June 22, 2021, 4:51pm UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621/2 "2021-06-22T16:51:40Z")

</div>

You could do the rename in a ruby filter. I am not sure what condition you will need. An example would be

```
ruby {
    code => '
        event.to_hash.each { |k, v|
            if k.match?(/[A-Z_]+/)
                event.set("ctf.#{k}", v)
                event.remove(k)
            end
        }
    '
}

```

That will avoid renaming fields like @timestamp. If you want the fields nested in the ctf object then change that to use

```
                event.set("[ctf][#{k}]", v)

```

If the set of fields you need to rename is fixed then you might want to use

```
            if ["IDTU", "PART", "PHASE", ...].include? k

```

instead of the regexp.

---

<div class="post-metadata">

### Author: ![ErSumit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ersumit/32/88708_2.png) [@ErSumit](https://discuss.elastic.co/u/ErSumit)
#### Post date: [June 22, 2021, 5:26pm UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621/3 "2021-06-22T17:26:52Z")

</div>

You can achieve with filter

```auto
 kv {
     source => "message"
    field_split_pattern => " "
      value_split => "="
       prefix => "ctf"
       }
    }

```

make sure you are passing only part of string to kv filter  
as:  
IDTU=A0007GK PART=LKOR STATE=Y PHASE=Y PHASESTEP=C DIRECT=S TYPE=F SENTINEL\_STATE=POST\_PROC

Use dissect or grok parsing to separate the string for kv filter

Pls let us know if it works

Cheers!

---

<div class="post-metadata">

### Author: ![frank\_rib](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/frank_rib/32/104372_2.png) [@frank\_rib](https://discuss.elastic.co/u/frank_rib)
#### Post date: [June 23, 2021, 5:18pm UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621/4 "2021-06-23T17:18:55Z")

</div>

Hello,

Thanks badger and ErSumit for your help, i tested the kv with the prefix and it worked

Best regards

---

<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: [July 21, 2021, 5:19pm UTC](https://discuss.elastic.co/t/adding-prefex-to-the-field-extracted-via-kv-plugin/276621/5 "2021-07-21T17:19:08Z")

</div>

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