# Rename a field that has variable in name

**URL:** https://discuss.elastic.co/t/rename-a-field-that-has-variable-in-name/37284
**Category:** Logstash
**Created:** [December 15, 2015, 10:29pm UTC](https://discuss.elastic.co/t/rename-a-field-that-has-variable-in-name/37284 "2015-12-15T22:29:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![spuder](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spuder/32/44895_2.png) [@spuder](https://discuss.elastic.co/u/spuder)
#### Post date: [December 15, 2015, 10:29pm UTC](https://discuss.elastic.co/t/rename-a-field-that-has-variable-in-name/37284/1 "2015-12-15T22:29:49Z")

</div>

What would be the best way to remove a nested field that has a variable in its name?

For example, the logs I'm parsing as json

```
{
  "foo": {
    "bar(987234)": "derp"
  }
}

```

Represented as nested field

```
[foo][bar(2349871)]

```

I want to strip out the random numbers.

```
[foo][bar]

```

I'm ok to throw the numbers away, but I'd like to preserve them if possible.

Here is what I've tried.

```
  mutate {
    rename => { "[foo][bar*]" => "[foo][bar]" }
  }

```

or

```
  mutate {
    rename => { "[foo][bar%{*}]" => "[foo][bar]" }
  }

```

or

```
  mutate {
    rename => { "[foo][bar(*)]" => "[foo][bar]" }
  }

```

From the documentation it appears that these should work.

[https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-split)

---

<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 16, 2015, 6:55am UTC](https://discuss.elastic.co/t/rename-a-field-that-has-variable-in-name/37284/2 "2015-12-16T06:55:54Z")

</div>

You'll have to use a ruby filter for this. Iterate over the keys in `event['foo']`, see if they match somestring(somenumber) and if so add a new hash with just somestring as the key and delete the old entry.

> From the documentation it appears that these should work.

Where does the documentation indicate that wildcards are supported?

---

<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 6, 2017, 5:18am UTC](https://discuss.elastic.co/t/rename-a-field-that-has-variable-in-name/37284/3 "2017-07-06T05:18:15Z")

</div>


