# How to write mutate for nested field as array in config file?

**URL:** <https://discuss.elastic.co/t/how-to-write-mutate-for-nested-field-as-array-in-config-file/230655>\
**Category:** Logstash\
**Created:** [May 1, 2020, 2:19am UTC](https://discuss.elastic.co/t/how-to-write-mutate-for-nested-field-as-array-in-config-file/230655 "2020-05-01T02:19:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apremgeorge](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@apremgeorge](https://discuss.elastic.co/u/apremgeorge)\
**Post date:** [May 1, 2020, 2:19am UTC](https://discuss.elastic.co/t/how-to-write-mutate-for-nested-field-as-array-in-config-file/230655/1 "2020-05-01T02:19:15Z")

</div>

I have written the logstash config file to upload a csv,

```auto
filter {
	csv {
		separator => ","
		skip_header => true
		columns => [LoanID,Applicant_Income1,Occupation1,Time_At_Work1,Date_Of_Join1,Gender,LoanAmount,Marital_Status,Dependents,Education,Self_Employed,Applicant_Income2,Occupation2,Time_At_Work2,Date_Of_Join2,Applicant_Income3,Occupation3,Time_At_Work3,Date_Of_Join3]
	}
	mutate { 
		convert => {
			"Applicant_Income1" => "float"
			"Time_At_Work1" => "float"
			"LoanAmount" => "float"
			"Applicant_Income2" => "float"
			"Time_At_Work2" => "float"
			"Applicant_Income3" => "float"
			"Time_At_Work3" => "float"
			}
		} 
	mutate{
		rename => {
			"Applicant_Income1" => "[Applicant][0][Applicant_Income]"
			"Occupation1" => "[Applicant][0][Occupation]"
			"Time_At_Work1" => "[Applicant][0][Time_At_Work]"
			"Date_Of_Join1" => "[Applicant][0][Date_Of_Join]"
			"Applicant_Income2" => "[Applicant][1][Applicant_Income]"
			"Occupation2" => "[Applicant][1][Occupation]"
			"Time_At_Work2" => "[Applicant][1][Time_At_Work]"
			"Date_Of_Join2" => "[Applicant][1][Date_Of_Join]"
			"Applicant_Income3" => "[Applicant][2][Applicant_Income]"
			"Occupation3" => "[Applicant][2][Occupation]"
			"Time_At_Work3" => "[Applicant][2][Time_At_Work]"
			"Date_Of_Join3" => "[Applicant][2][Date_Of_Join]"
			}
		}	
    date {
        match => ["Date_Of_Join1", "yyyy-MM-dd'T'HH:mm:ss.SSZZ"]
        }	
    date {
        match => ["Date_Of_Join2", "yyyy-MM-dd'T'HH:mm:ss.SSZZ"]
      }	
    date {
        match => ["Date_Of_Join3", "yyyy-MM-dd'T'HH:mm:ss.SSZZ"]		
      }		  
	}

```

So i got as

![image](https://us1.discourse-cdn.com/elastic/original/3X/a/a/aa7848e6de8b52cc80e3d995bf7734668c70e636.png)

I need the nested field to be an array of dictionaries.  
like  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/c/f/cf63c73897b4a36277c6408f8555614c93160fa4.png)  
Can i have help to write the config file, 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 1, 2020, 1:26pm UTC](https://discuss.elastic.co/t/how-to-write-mutate-for-nested-field-as-array-in-config-file/230655/2 "2020-05-01T13:26:16Z")

</div>

You could do that using a ruby filter

```
ruby {
    code => '
        applicants = event.get("Applicant")
        a = []
        applicants.each { | k, v|
            a << v
        end
        event.set("Applicant", a)
   '
}
```

---

<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:** [May 29, 2020, 1:26pm UTC](https://discuss.elastic.co/t/how-to-write-mutate-for-nested-field-as-array-in-config-file/230655/3 "2020-05-29T13:26:19Z")

</div>

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