# Split array fields in logstash

**URL:** <https://discuss.elastic.co/t/split-array-fields-in-logstash/84546>\
**Category:** Logstash\
**Created:** [May 4, 2017, 11:43am UTC](https://discuss.elastic.co/t/split-array-fields-in-logstash/84546 "2017-05-04T11:43:24Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![Aditya\_Srivastava](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_srivastava/32/43287_2.png) [@Aditya\_Srivastava](https://discuss.elastic.co/u/Aditya_Srivastava)\
**Post date:** [May 9, 2017, 1:38pm UTC](https://discuss.elastic.co/t/split-array-fields-in-logstash/84546/11 "2017-05-09T13:38:53Z")

</div>

You are correct. It doesnt work for above ruby code.  
My logstash config file ran with by commenting few lines.

I took reference from below code written by you for some other post

> [@Iteration in Logstash](https://discuss.elastic.co/t/iteration-in-logstash/26123):
>
> I have a string data in Logstash that has been parsed as that looks like "id": "0,3,10" "value": "100,200,300" I would like to match the individual "id" to the corresponding "value" with respect to their order in the string. I want the field to look like "id0": "100" "id3": "200" "id10": "300" As of now, I have used the mutate field to separate the array into its individual values. I used the following code: mutate { add\_field =\> {"id%{[id][0]}" =\> "%{[value][0]}"} add\_field =\> {"id%…

filter {  
ruby {  
code =\> '  
ids = event["id"].split(",")  
values = event["value"].split(",")  
if ids.length == values.length  
ids.each\_index { |i| event["id#{ids[i]}"] = values[i] }  
end  
'  
}  
}

Could you please tell me what is wrong in the ruby code I wrote or help me with ruby code to solve the prob

---

_[View the full topic](https://discuss.elastic.co/t/split-array-fields-in-logstash/84546)._
