# How to : Using Ruby filter, Perform db lookup while iterating the array

**URL:** <https://discuss.elastic.co/t/how-to-using-ruby-filter-perform-db-lookup-while-iterating-the-array/217570>\
**Category:** Logstash\
**Created:** [February 3, 2020, 7:53am UTC](https://discuss.elastic.co/t/how-to-using-ruby-filter-perform-db-lookup-while-iterating-the-array/217570 "2020-02-03T07:53:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![inhinyera16](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/inhinyera16/32/61625_2.png) [@inhinyera16](https://discuss.elastic.co/u/inhinyera16)\
**Post date:** [February 3, 2020, 7:53am UTC](https://discuss.elastic.co/t/how-to-using-ruby-filter-perform-db-lookup-while-iterating-the-array/217570/1 "2020-02-03T07:53:30Z")

</div>

My jdbc\_streaming produce an array like this

```
"attachment": [
{
	"departmentid" : "2"
}]

```

now i would like to lookup my db using the departmentid, and get the equivalent department name and put it as below

```
"attachment": [
{
	"departmentid" : "2",
	"department" : [
     {
           "department": "dept2"
           "other_details_here": ""
     }
     ]
}}

```

I can do this query if my attachment is flat,  
Select departmentName as department from Department where id = :departmentid

---

<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:** [March 2, 2020, 7:53am UTC](https://discuss.elastic.co/t/how-to-using-ruby-filter-perform-db-lookup-while-iterating-the-array/217570/2 "2020-03-02T07:53:43Z")

</div>

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