# 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:** 13

<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, 2:35pm UTC](https://discuss.elastic.co/t/split-array-fields-in-logstash/84546/13 "2017-05-09T14:35:23Z")

</div>

Thanks for pointing out the mistakes.  
ruby {  
code =\> "  
times = event['id'].split(',')  
times.each\_index { |i| event[i.to\_s] = times[i]  
if times[i] == '7'  
event['IndexValue'] = i}  
end  
"  
}

Now when I run this, I get foll exception

SyntaxError: (ruby filter code):5: syntax error, unexpected tRCURLY  
event['IndexValue'] = i}  
^  
eval at org/jruby/RubyKernel.java:1079  
register at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-filter-ruby-2.0.3/lib/logstash/filters/ruby.rb:29  
each at org/jruby/RubyArray.java:1613  
start\_filters at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.1.3-java/lib/logstash/pipeline.rb:171  
run at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.1.3-java/lib/logstash/pipeline.rb:101  
execute at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.1.3-java/lib/logstash/agent.rb:165  
run at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.1.3-java/lib/logstash/runner.rb:90  
call at org/jruby/RubyProc.java:281  
run at /data/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.1.3-java/lib/logstash/runner.rb:95  
call at org/jruby/RubyProc.java:281  
initialize at /data/logstash/vendor/bundle/jruby/1.9/gems/stud-0.0.22/lib/stud/task.rb:24

I looked up for the exception, found a solution given by you.

> [@Unexpected error in ruby code in logstash](https://discuss.elastic.co/t/unexpected-error-in-ruby-code-in-logstash/70264):
>
> Hi, An unexpected error in occuring for the following ruby code in logstash filter. SyntaxError: (ruby filter code):5: syntax error, unexpected tRCURLY \*\* }\*\* Following is the ruby code: ruby { code =\> ' allscores = event["score"] if allscores.length != '1' t = allscores.inject(:+) event["total\_score"] = t ' add\_tag =\> [sum\_score] } The error is as follows: SyntaxError: (ruby filter code):5: syntax error, unexpected tRCURLY } ^ eval at org/jruby/RubyKernel.java:1…

ruby {  
code =\> "  
times = event["id"].split(',')  
times.each\_index { |i| event[i.to\_s] = times[i]  
if times[i] == '7'  
event['IndexValue.to\_i'] = i}  
end  
"  
}

when change event['id'] from single quote to double quotes as mentioned above, it gives me foll exception

Error: Expected one of #, {, } at line 25, column 16 (byte 545)

If I comment out the complete ruby code, It works fine. Means again there is some prob with the ruby code.

Plz refer some link as well where I can study more detail on how to use ruby in logstash.

---

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