# Mutate rename using field value

**URL:** https://discuss.elastic.co/t/mutate-rename-using-field-value/292014
**Category:** Logstash
**Created:** [December 15, 2021, 3:55pm UTC](https://discuss.elastic.co/t/mutate-rename-using-field-value/292014 "2021-12-15T15:55:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sirReeall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sirreeall/32/94713_2.png) [@sirReeall](https://discuss.elastic.co/u/sirReeall)
#### Post date: [December 15, 2021, 3:55pm UTC](https://discuss.elastic.co/t/mutate-rename-using-field-value/292014/1 "2021-12-15T15:55:55Z")

</div>

Hello,

I'm trying to rename a field using the value of another metadata field, here is what I have tried:

```auto
filter {
  grok {
    match => {
      "path" => "%{GREEDYDATA}/%{GREEDYDATA:[@metadata][metric_name]}\.csv"
    }
  }

  csv {
    skip_header => true
    columns => ["t","value"]
  }

  mutate {
    rename => {
      "value" => "%{metric_name}"
    }
  }
}

```

Which basically uses grok to pull out the filename, excluding it's extension as `metric_name`. Then later on I'm trying to this in mutate to rename `value` to the value of `metric_name`.

Is this possible with mutate?

---

<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: [December 15, 2021, 4:08pm UTC](https://discuss.elastic.co/t/mutate-rename-using-field-value/292014/2 "2021-12-15T16:08:53Z")

</div>

> [@sirReeall](#):
>
> Is this possible with mutate?

I believe it is. The [code](https://github.com/logstash-plugins/logstash-filter-mutate/blob/d45bfb7211fc0a11afd7dc917cefa295752cc63d/lib/logstash/filters/mutate.rb#L284) sprintf's both the old and new values. But [metric\_name] and [@metadata][metric\_name] do not match.

---

<div class="post-metadata">

### Author: ![sirReeall](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sirreeall/32/94713_2.png) [@sirReeall](https://discuss.elastic.co/u/sirReeall)
#### Post date: [December 15, 2021, 6:27pm UTC](https://discuss.elastic.co/t/mutate-rename-using-field-value/292014/3 "2021-12-15T18:27:13Z")

</div>

I managed to figure this out by using `%[@metadata][metric_name]` in mutate

---

<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 12, 2022, 6:27pm UTC](https://discuss.elastic.co/t/mutate-rename-using-field-value/292014/4 "2022-01-12T18:27:14Z")

</div>

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