# Update/rename nested field

**URL:** <https://discuss.elastic.co/t/update-rename-nested-field/198057>\
**Category:** Logstash\
**Created:** [September 4, 2019, 1:43pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057 "2019-09-04T13:43:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvoros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bvoros/32/5246_2.png) [@bvoros](https://discuss.elastic.co/u/bvoros)\
**Post date:** [September 4, 2019, 1:43pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057/1 "2019-09-04T13:43:36Z")

</div>

Hello All,

What is the best way to rename a nested field?

I would like to do the following:

if [filed][subfield]  
rename it to [field]

Would it make sense to add a temporary field with the value of the original, drop the original then rename the temporary or is there a better way?

Any help appreciated,

---

<div class="post-metadata">

**Author:** ![bvoros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bvoros/32/5246_2.png) [@bvoros](https://discuss.elastic.co/u/bvoros)\
**Post date:** [September 4, 2019, 2:03pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057/2 "2019-09-04T14:03:44Z")

</div>

Does this make sense?

```auto
filter{
    if 'filebeat' in [tags] or 'beats_input_codec_plain_applied' in [tags] {
        if [name] in [host] {
            mutate {
                add_field => { "host_name" => %{[host][name]} }
            }
            drop {
                remove_field => ["host"]
            }
            mutate {
                rename => ["host_name", "host"]
            }

        }
    }
}

```

---

<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:** [September 4, 2019, 3:04pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057/3 "2019-09-04T15:04:59Z")

</div>

Yes, if you want to move [host][name] to [host] you will have to use a temporary field to store the value.

Note that you have the option of moving it the other way

```
if ! [host][name] { mutate { rename => { "[host]" => "[host][name]" } } }
```

---

<div class="post-metadata">

**Author:** ![bvoros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bvoros/32/5246_2.png) [@bvoros](https://discuss.elastic.co/u/bvoros)\
**Post date:** [September 4, 2019, 3:08pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057/4 "2019-09-04T15:08:14Z")

</div>

Thanks, the only thing is that the [host] field is already there.  
Could drop the index though, will ponder the benefit of going either way.  
Thanks a lot for your help once again.

---

<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:** [October 2, 2019, 3:08pm UTC](https://discuss.elastic.co/t/update-rename-nested-field/198057/5 "2019-10-02T15:08:19Z")

</div>

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