# Help on Ruby required

**URL:** <https://discuss.elastic.co/t/help-on-ruby-required/208808>\
**Category:** Logstash\
**Created:** [November 21, 2019, 5:31am UTC](https://discuss.elastic.co/t/help-on-ruby-required/208808 "2019-11-21T05:31:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![varshesh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varshesh/32/57699_2.png) [@varshesh](https://discuss.elastic.co/u/varshesh)\
**Post date:** [November 21, 2019, 5:31am UTC](https://discuss.elastic.co/t/help-on-ruby-required/208808/1 "2019-11-21T05:31:25Z")

</div>

Hello Friends!

I have a db field, where the comma seperated ids are stored. I have setup an array of ID =\> VALUE.

Example:  
In DB field cityids , it contains value "2,3,4,5"

Array has  
[1=\>"Chicago", 2=\>"London",3=\>"Delhi",4=\>"LA",5=\>"Moscow",6=\>"Singaport"]

Now, I need to store "London,Delhi,LA,Moscow" in the elastic index using Logstash filter.

Can someone please advise how to achieve this.  
I am a PHP person, just have started with Logstash. But, I believe for this I need to use ruby filter, for which I have written the code as below.

filter {  
ruby{  
code =\>"  
strPA = event.get('paids')  
strPAIds = strPA.split(",")  
H = Hash["1" =\> "Practice Area 1",  
"2" =\> "Practice Area 2",  
"3" =\> "Practice Area 3",  
"4" =\> "Practice Area 4"]  
finalpa = ""  
strPAIds.each do |strPAIds|  
#puts abc  
#puts H.fetch(abc)  
finalpa = finalpa + H.fetch(strPAIds) + ", "  
end

```
finalpa = finalpa.chomp(" ")
finalpa = finalpa.chomp(",")
event.set('practice_areas',finalpa)
"
 }

```

}

Thank you in advance !

Varshesh

---

<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:** [December 19, 2019, 5:31am UTC](https://discuss.elastic.co/t/help-on-ruby-required/208808/2 "2019-12-19T05:31:35Z")

</div>

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