# Setup parent/child using rivers

**URL:** <https://discuss.elastic.co/t/setup-parent-child-using-rivers/15184>\
**Category:** Elasticsearch\
**Created:** [January 9, 2014, 9:04pm UTC](https://discuss.elastic.co/t/setup-parent-child-using-rivers/15184 "2014-01-09T21:04:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsp/32/73057_2.png) [@jsp](https://discuss.elastic.co/u/jsp)\
**Post date:** [January 9, 2014, 9:04pm UTC](https://discuss.elastic.co/t/setup-parent-child-using-rivers/15184/1 "2014-01-09T21:04:09Z")

</div>

I am reading data from Sql Server database/table using jdbc-river  
currently. As of now I have created a type for each table in my database.  
As next step in my implementation I would like to use parent/child types so  
that I can translate the relationship between my sql tables and store them.

Table1  
Col\_id| name| prop1|prop2|prop3

child\_table1  
col\_id| table\_id| child\_prop1|child\_prop2|child\_prop3

curl -XPUT 'localhost:9200/\_river/parent/\_meta' -d '{  
"type" : "jdbc",  
"jdbc" : {  
"driver" : "com.mysql.jdbc.Driver",  
"url" : "jdbc:mysql://localhost:3306/test",  
"user" : "",  
"password" : "",  
"sql" : "select \* from table1",  
"index" : "index1",  
"type" : "parent"  
}  
}'

curl -XPUT 'localhost:9200/\_river/child/\_meta' -d '{  
"type" : "jdbc",  
"jdbc" : {  
"driver" : "com.mysql.jdbc.Driver",  
"url" : "jdbc:mysql://localhost:3306/test",  
"user" : "",  
"password" : "",  
"sql" : "select \* from child\_table1",  
"index" : "index1",  
"type" : "child"  
}  
}'

curl -XPOST 'localhost:9200/\_river/child/\_mapping' -d '{  
"child":{  
"\_parent": {"type": "parent"}  
}  
}'

I would like to store my data in the following format

{  
"id": "1",  
"name": "name1",  
"prop1": "data",  
"prop2": "data",  
"prop3": "data",

"child": [  
{  
"child\_prop1": "data",  
"child\_prop2": "data",  
"child\_prop3": "data",  
}  
{  
"child\_prop1": "data1",  
"child\_prop2": "data1",  
"child\_prop3": "data1",  
}  
]}

Can anyone comment on how can I use jdbc-rivers to store my data as  
parent/child type for above scenario.

thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/de9ede70-45f2-45d5-bdfb-143d95852262%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/de9ede70-45f2-45d5-bdfb-143d95852262%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Maarten\_Roosendaal](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@Maarten\_Roosendaal](https://discuss.elastic.co/u/Maarten_Roosendaal)\
**Post date:** [January 11, 2014, 1:00pm UTC](https://discuss.elastic.co/t/setup-parent-child-using-rivers/15184/2 "2014-01-11T13:00:30Z")

</div>

Hi,

What you can do is include the 'parent' in the sql and give it the value of  
the parentId. I think you have to do this in 2 runs, first all the parents,  
second all the children.

see  
[http://elasticsearch-users.115913.n3.nabble.com/JDBC-River-amp-amp-parent-td4029976.html](http://elasticsearch-users.115913.n3.nabble.com/JDBC-River-amp-amp-parent-td4029976.html) for  
another discussion

Good luck,  
Maarten

Op donderdag 9 januari 2014 22:04:09 UTC+1 schreef jsp:

> I am reading data from Sql Server database/table using jdbc-river  
> currently. As of now I have created a type for each table in my database.  
> As next step in my implementation I would like to use parent/child types so  
> that I can translate the relationship between my sql tables and store them.
> 
> Table1  
> Col\_id| name| prop1|prop2|prop3
> 
> child\_table1  
> col\_id| table\_id| child\_prop1|child\_prop2|child\_prop3
> 
> curl -XPUT 'localhost:9200/\_river/parent/\_meta' -d '{  
> "type" : "jdbc",  
> "jdbc" : {  
> "driver" : "com.mysql.jdbc.Driver",  
> "url" : "jdbc:mysql://localhost:3306/test",  
> "user" : "",  
> "password" : "",  
> "sql" : "select \* from table1",  
> "index" : "index1",  
> "type" : "parent"  
> }  
> }'
> 
> curl -XPUT 'localhost:9200/\_river/child/\_meta' -d '{  
> "type" : "jdbc",  
> "jdbc" : {  
> "driver" : "com.mysql.jdbc.Driver",  
> "url" : "jdbc:mysql://localhost:3306/test",  
> "user" : "",  
> "password" : "",  
> "sql" : "select \* from child\_table1",  
> "index" : "index1",  
> "type" : "child"  
> }  
> }'
> 
> curl -XPOST 'localhost:9200/\_river/child/\_mapping' -d '{  
> "child":{  
> "\_parent": {"type": "parent"}  
> }  
> }'
> 
> I would like to store my data in the following format
> 
> {  
> "id": "1",  
> "name": "name1",  
> "prop1": "data",  
> "prop2": "data",  
> "prop3": "data",
> 
> "child": [  
> {  
> "child\_prop1": "data",  
> "child\_prop2": "data",  
> "child\_prop3": "data",  
> }  
> {  
> "child\_prop1": "data1",  
> "child\_prop2": "data1",  
> "child\_prop3": "data1",  
> }  
> ]}
> 
> Can anyone comment on how can I use jdbc-rivers to store my data as  
> parent/child type for above scenario.
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8269dd11-dd60-4c09-918e-055786f0807a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8269dd11-dd60-4c09-918e-055786f0807a%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:57am UTC](https://discuss.elastic.co/t/setup-parent-child-using-rivers/15184/3 "2017-07-06T01:57:18Z")

</div>


