# Removing prefix from field names

**URL:** https://discuss.elastic.co/t/removing-prefix-from-field-names/339674
**Category:** Logstash
**Created:** [July 31, 2023, 10:12am UTC](https://discuss.elastic.co/t/removing-prefix-from-field-names/339674 "2023-07-31T10:12:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![VirusProtect](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/virusprotect/32/127766_2.png) [@VirusProtect](https://discuss.elastic.co/u/VirusProtect)
#### Post date: [July 31, 2023, 10:12am UTC](https://discuss.elastic.co/t/removing-prefix-from-field-names/339674/1 "2023-07-31T10:12:34Z")

</div>

Hi, I have fields in Kibana such as `fw.ip`, `fw.name`, `fw.test.old`, and so on. I am trying to remove the "fw" prefix from all these fields using a Ruby filter in Logstash. Here's the code I'm using:

```auto
ruby {
  code => "
    event.to_hash.keys.each do |key|
      if key.start_with?('fw.')
        new_key = key.sub('fw.', '')
        event.set(new_key, event.get(key))
        event.remove(key)
      end
    end
  "
}

```

Unfortunately, this is not working. How can I remove the prefix "fw." from all fields using Ruby?

Thank you!

---

<div class="post-metadata">

### Author: ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)
#### Post date: [July 31, 2023, 10:20am UTC](https://discuss.elastic.co/t/removing-prefix-from-field-names/339674/2 "2023-07-31T10:20:28Z")

</div>

Hi @VirusProtect,

Are you getting a particular error from your Ruby code?

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [July 31, 2023, 1:39pm UTC](https://discuss.elastic.co/t/removing-prefix-from-field-names/339674/3 "2023-07-31T13:39:33Z")

</div>

> [@VirusProtect](#):
>
> Hi, I have fields in Kibana such as `fw.ip`, `fw.name`, `fw.test.old`, and so on.

Is this a prefix or an object named `fw` with nested field? For example

This is a field with a dot in the name and the `fw` as a prefix

```auto
"{ "fw.ip": "8.8.8.8" }

```

And this is json object named `fw` with a nested field named `ip`

```auto
"{ "fw": { "ip": "8.8.8.8" } }

```

In kibana they will look the same in discover, you will only be able to know if it is a field with a prefix or a json object looking at the json tabe for the document.

Can you provide a sample of how your document looks like in Kibana looking at the json tab in the discover?

---

<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: [August 28, 2023, 1:40pm UTC](https://discuss.elastic.co/t/removing-prefix-from-field-names/339674/4 "2023-08-28T13:40:21Z")

</div>

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