# Logstash jdbc plugin input for mutliple table joins of one to many relationships

**URL:** https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933
**Category:** Logstash
**Created:** [September 7, 2016, 12:50am UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933 "2016-09-07T00:50:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Syed\_Ather](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syed_ather/32/11778_2.png) [@Syed\_Ather](https://discuss.elastic.co/u/Syed_Ather)
#### Post date: [September 7, 2016, 12:50am UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/1 "2016-09-07T00:50:44Z")

</div>

HI All,  
I have two tables linked in a one to many relationship , i.e for each row in first table there will be multiple rows in second table .  
One employee can have many orders assigned to them .  
ex :  
 ![](https://us1.discourse-cdn.com/elastic/original/2X/9/9fa0714bece06eb3a84c8ed19079d247aa5af135.png)

* * *

how can i achieve the data upload to elastic for a single index to have all orders in the form of an array of orders inside the main JSON object?

like..

 ![](https://us1.discourse-cdn.com/elastic/original/2X/2/23e5d3e6fadb6f172da7aa312d71cc3da2811cf5.png)

* * *

I also want to add that i have read about custom mappings and templates for elastic , but i need the logstash way of pushing data in the format i have shown .

Thanks !

---

<div class="post-metadata">

### Author: ![Syed\_Ather](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syed_ather/32/11778_2.png) [@Syed\_Ather](https://discuss.elastic.co/u/Syed_Ather)
#### Post date: [September 7, 2016, 5:04pm UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/2 "2016-09-07T17:04:48Z")

</div>

@magnusbaeck Can you please offer some assistance on this ?

---

<div class="post-metadata">

### Author: ![sureshadapa](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sureshadapa](https://discuss.elastic.co/u/sureshadapa)
#### Post date: [September 9, 2016, 1:59pm UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/3 "2016-09-09T13:59:52Z")

</div>

############## Nested Objects ###  
PUT employee\_orders  
{  
"mappings": {  
"employee": {  
"properties": {  
"\_id": { "type": "long" },  
"name": { "type": "string" },  
"orders": { "type": "nested",  
"properties": {  
"orderid": { "type": "string" },  
"description": { "type": "string" }  
}  
}  
}  
}  
}  
}

GET employee\_orders

POST employee\_orders/employee/1  
{  
"name": "Suresh"  
}

PUT employee\_orders/employee/2  
{  
"name": "Sudha"  
}

GET employee\_orders/employee/1  
GET employee\_orders/employee/2

DELETE employee\_orders/employee/1  
GET employee\_orders/\_search

POST employee\_orders/employee/1/\_update  
{  
"doc":{  
"orders":{  
"orderid": "0001",  
"description": "Leather Jacket"  
}  
}  
}

########Dynamic Mapping #######

GET emporders/\_search

PUT /emporders  
{  
"mappings": {  
"empid": {  
"dynamic": "strict",  
"properties": {  
"orderid": { "type": "string"},  
"orderdetails": {  
"type": "object",  
"dynamic": true  
}  
}  
}  
}  
}

PUT /emporders/empid/1  
{  
"orderid": "order1",  
"orderdetails": {  
"item1": "Jacket",  
"item2": "Shaving kit"  
}  
}

PUT /emporders/empid/2  
{  
"orderid": "order2",  
"orderdetails": {  
"item1": "Cooking Gas Stove"  
}  
}

---

<div class="post-metadata">

### Author: ![aymanm](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@aymanm](https://discuss.elastic.co/u/aymanm)
#### Post date: [February 25, 2017, 6:41pm UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/4 "2017-02-25T18:41:27Z")

</div>

I know this is an older question and you probably have resolved it by now. But I came across a similar issue and took me a while to figure out.  
One way is to use a JOIN in your sql query and then use the aggregate filter. Please see this reference example #4  
[https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html#\_example\_4\_no\_end\_event\_and\_tasks\_come\_one\_after\_the\_other](https://www.elastic.co/guide/en/logstash/current/plugins-filters-aggregate.html#_example_4_no_end_event_and_tasks_come_one_after_the_other)

---

<div class="post-metadata">

### Author: ![bsadagopan0107](https://avatars.discourse-cdn.com/v4/letter/b/aca169/32.png) [@bsadagopan0107](https://discuss.elastic.co/u/bsadagopan0107)
#### Post date: [April 13, 2017, 2:42pm UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/5 "2017-04-13T14:42:28Z")

</div>

Hi @Syed_Ather : I am having a similar requirement and would like to know if this was resolved and if so, through what approach ? Please explain.  
Thanks,

---

<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: [July 6, 2017, 4:27am UTC](https://discuss.elastic.co/t/logstash-jdbc-plugin-input-for-mutliple-table-joins-of-one-to-many-relationships/59933/6 "2017-07-06T04:27:04Z")

</div>


