# How to iterate for loop in logstash

**URL:** https://discuss.elastic.co/t/how-to-iterate-for-loop-in-logstash/109892
**Category:** Logstash
**Created:** [December 1, 2017, 8:23am UTC](https://discuss.elastic.co/t/how-to-iterate-for-loop-in-logstash/109892 "2017-12-01T08:23:32Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Shekhar\_Pandey](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@Shekhar\_Pandey](https://discuss.elastic.co/u/Shekhar_Pandey)
#### Post date: [December 1, 2017, 8:23am UTC](https://discuss.elastic.co/t/how-to-iterate-for-loop-in-logstash/109892/1 "2017-12-01T08:23:32Z")

</div>

I have created two array in logstash..which code are given below:  
filter{  
ruby {  
code =\> '  
event['ids'] = [1100,1101,1102,1103,1104]  
event['value'] = ["apple","dell","mi","lenovo","nokia"]  
if event[ids][i] == 1100  
{  
mutate { replace =\> { event["ids"] =\> values[i] } }  
}  
end  
'  
}

}

I created two array ids and values and comparing if any ids value with 1100 then it replace with corresponding value like 1100 replace with apple.

Kindly tell me correct way..

---

<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 29, 2017, 8:23am UTC](https://discuss.elastic.co/t/how-to-iterate-for-loop-in-logstash/109892/2 "2017-12-29T08:23:33Z")

</div>

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