# Having trouble assigning value from field A to field B

**URL:** https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546
**Category:** Logstash
**Created:** [June 12, 2018, 1:30pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546 "2018-06-12T13:30:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![JimP](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@JimP](https://discuss.elastic.co/u/JimP)
#### Post date: [June 12, 2018, 1:30pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546/1 "2018-06-12T13:30:49Z")

</div>

We have a field [env\_id] which is sent from filebeat. In logstash, I want to assign this value to field, [topic][env], but am failing miserably. Here's the latest that I've tried which doesn't work. This should be straightforward, but for some reason, I am completely baffled?

```
 mutate {
   replace => ["[topic][env]", "%{[env_id]}" ]
}
```

---

<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 12, 2018, 2:47pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546/2 "2018-06-12T14:47:50Z")

</div>

It works for me.

```auto
filter {
    mutate { add_field => { "env_id" => "foo" } }
    mutate { replace => ["[topic][env]", "%{[env_id]}" ] }
}

```

gets me

```auto
        "env_id" => "foo",
         "topic" => {
        "env" => "foo"
    },

```

What does it look like for you?

---

<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: [June 12, 2018, 2:48pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546/3 "2018-06-12T14:48:26Z")

</div>

What _do_ you get? Use a `stdout { codec => rubydebug }` output to dump a raw event (or copy/paste from Kibana's JSON tab).

---

<div class="post-metadata">

### Author: ![JimP](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@JimP](https://discuss.elastic.co/u/JimP)
#### Post date: [June 12, 2018, 4:38pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546/4 "2018-06-12T16:38:53Z")

</div>

It works. Not sure what bonehead thing I was doing. Thanks!

---

<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 10, 2018, 4:38pm UTC](https://discuss.elastic.co/t/having-trouble-assigning-value-from-field-a-to-field-b/135546/5 "2018-07-10T16:38:54Z")

</div>

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