# How to add/rename fields recursively instead using mutate or instead doing one by one?

**URL:** <https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688>\
**Category:** Logstash\
**Created:** [May 18, 2019, 4:48pm UTC](https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688 "2019-05-18T16:48:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [May 18, 2019, 4:48pm UTC](https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688/1 "2019-05-18T16:48:59Z")

</div>

Hi All

How to add/rename fields recursively, instead doing one by one  
Here is my dataset with message value as

> [{  
> "Row ID" : 201,  
> "Order ID" : "CA-2017-105074",  
> "Order Date" : "6/24/2017",  
> "Segment" : "Consumer",  
> ..  
> ..  
> ..  
> ..  
> }, {  
> "Row ID" : 454,  
> "Order ID" : "CA-2017-147277",  
> "Segment" : "Test",  
> ..  
> ..  
> ..  
> ..
> 
> ```
> }
>   
> ]
> 
> ```

I am using this in conf file

```
		split { field => "[message]" }
mutate {  
 add_field => {"Row ID" => "%{[message][Row ID]}"}
 add_field => {"Order ID" => "%{[message][Order ID]}"}
 add_field => {"Segment" => "%{[message][Segment]}"}
 }  

```

With this filter, i get right result  
In my dataset i have close to 200 columns,  
its very difficult to define the column name for each and every mutate for each field

How we can do this recursively using Ruby? To define all the names for each field in one go

Thanks

---

<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:** [May 18, 2019, 4:59pm UTC](https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688/2 "2019-05-18T16:59:04Z")

</div>

Does [this](https://discuss.elastic.co/t/how-to-dynamically-move-nested-key-value-to-root-level/180006/2) help?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [May 18, 2019, 5:07pm UTC](https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688/3 "2019-05-18T17:07:14Z")

</div>

wow, it works. 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:** [June 15, 2019, 5:07pm UTC](https://discuss.elastic.co/t/how-to-add-rename-fields-recursively-instead-using-mutate-or-instead-doing-one-by-one/181688/4 "2019-06-15T17:07:15Z")

</div>

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