# Need to use Aggregate Filer and custom ruby filter

**URL:** <https://discuss.elastic.co/t/need-to-use-aggregate-filer-and-custom-ruby-filter/208239>\
**Category:** Logstash\
**Created:** [November 17, 2019, 11:49pm UTC](https://discuss.elastic.co/t/need-to-use-aggregate-filer-and-custom-ruby-filter/208239 "2019-11-17T23:49:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Avinaba\_Ghosh\_Hajra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/avinaba_ghosh_hajra/32/57697_2.png) [@Avinaba\_Ghosh\_Hajra](https://discuss.elastic.co/u/Avinaba_Ghosh_Hajra)\
**Post date:** [November 17, 2019, 11:49pm UTC](https://discuss.elastic.co/t/need-to-use-aggregate-filer-and-custom-ruby-filter/208239/1 "2019-11-17T23:49:38Z")

</div>

DB join query with student and department where a student can be enlisted with multiple departments where each department can have multiple teachers. After query getting the following output

## student\_id student\_name department\_id department\_name teacher\_id

1 S1 d1 d1\_name t1   
1 S1 d1 d1\_name t2   
1 S1 d1 d1\_name t3   
1 S1 d2 d2\_name t4   
1 S1 d2 d2\_name t5   
1 S1 d2 d2\_name t6   
2 S2 d2 d2\_name t7   
2 S2 d1 d1\_name t1   
2 S2 d1 d1\_name t2   
2 S2 d1 d1\_name t3   
2 S2 d3 d3\_name t8   
2 S2 d3 d3\_name t9   
2 S2 d3 d3\_name t10   
2 S2 d3 d3\_name t11

Need the following output

{  
{  
"student\_id": 1,  
"student\_name": "s1\_name",  
"departments": [  
{  
"id": "d1",  
"name": "d1\_name",  
"teacher\_id": [  
"t1",  
"t2",  
"t3"  
]  
},  
{  
"id": "d2",  
"name": "d2\_name",  
"teacher\_id": [  
"t4",  
"t5",  
"t6"  
]  
}  
]  
},  
{  
"student\_id": 2  
"student\_name": "s2\_name",  
"departments": [  
{  
"id": "d1",  
"name": "d1\_name",  
"teacher\_id": [  
"t1",  
"t2",  
"t3"  
]  
},  
{  
"id": "d3",  
"name": "d3\_name",  
"teacher\_id": [  
"t7",  
"t8",  
"t9"  
]  
}  
]  
}  
}

Could you define the aggregate function

---

<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 15, 2019, 11:49pm UTC](https://discuss.elastic.co/t/need-to-use-aggregate-filer-and-custom-ruby-filter/208239/2 "2019-12-15T23:49:40Z")

</div>

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