# Remove part of field name in Logstash

**URL:** <https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062>\
**Category:** Logstash\
**Created:** [December 11, 2017, 10:22am UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062 "2017-12-11T10:22:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gasmi](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@gasmi](https://discuss.elastic.co/u/gasmi)\
**Post date:** [December 11, 2017, 10:22am UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062/1 "2017-12-11T10:22:05Z")

</div>

I am using Logstash 6.0.0

I am receiving metrics with different application Ids. How can I delete the application Id in the field name?

`application_1512057801087_0235.driver.BlockManager.memory.maxMem_MB => driver.BlockManager.memory.maxMem_MB`

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [December 11, 2017, 1:40pm UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062/2 "2017-12-11T13:40:48Z")

</div>

A quick solution would be some custom Ruby code, especially if you don't know the application id patterns beforehand, like

```auto
ruby {
    code => "
        event.set('fieldname', event.get('fieldname').split('.')[1..-1].join('.'))
    "
}
```

It's kinda overkill, but it works (unless there are dots in the application id itself).

---

<div class="post-metadata">

**Author:** ![gasmi](https://avatars.discourse-cdn.com/v4/letter/g/839c29/32.png) [@gasmi](https://discuss.elastic.co/u/gasmi)\
**Post date:** [December 11, 2017, 4:53pm UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062/3 "2017-12-11T16:53:29Z")

</div>

Ho w can I indicate that the ruby code applies only on field starting with "application\_..."

```
filter {
    if [type] == "spark" {
         ruby {
                code => "event.set('fieldname', event.get('fieldname').split('.')[1..-1].join('.')"
         }
    }
}
```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 12, 2017, 6:32am UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062/4 "2017-12-12T06:32:06Z")

</div>

With a dynamic field name you'll have to iterate over all fields.

```nohighlight
if event.to_hash.each { |k, v|
  if k.start_with? 'application_'
    event.set('application', v)
    event.remove(k)
    break
  end
}

```

---

<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 9, 2018, 6:32am UTC](https://discuss.elastic.co/t/remove-part-of-field-name-in-logstash/111062/5 "2018-01-09T06:32:41Z")

</div>

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