# When to use nested object vs parent child relation

**URL:** <https://discuss.elastic.co/t/when-to-use-nested-object-vs-parent-child-relation/225799>\
**Category:** Elasticsearch\
**Created:** [March 31, 2020, 7:02am UTC](https://discuss.elastic.co/t/when-to-use-nested-object-vs-parent-child-relation/225799 "2020-03-31T07:02:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ashish\_Mehta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashish_mehta/32/65356_2.png) [@Ashish\_Mehta](https://discuss.elastic.co/u/Ashish_Mehta)\
**Post date:** [March 31, 2020, 7:02am UTC](https://discuss.elastic.co/t/when-to-use-nested-object-vs-parent-child-relation/225799/1 "2020-03-31T07:02:08Z")

</div>

Hi Team,

I am migrating my relation database table to elastic search. I am stuck in making mapping of the document. I dont figure out which thing i use . Whether i should go to nested object or parent child relation.  
I am giving some hints about my table.  
We have multiple table which are joined to each other. For example

Table 1------one to many---\> Table 2  
Table 2 ---\> One to one ----\> Table 3  
Table 3 ----\> one to many -----\> Table 4  
Table 4-------\> one to one ----\> Table 5

If i am using parent child relationship, then in that case, if i need to load all the object by providing the table 1 id .It would be very difficult.

If i am using nested object, then it would be tightly coupled.

What i trying to think is :  
merge two table i.e Table 1 and Table 2 and table 2 would be the nested object .  
merge two table i.e Table 3 and Table 4 , Table 4 content would be nested object.

and i would make parent child relation between inner object of table 2 present in table 1 object with Table 3  
~  
PUT /my\_index  
{  
"mappings": {  
"properties": {  
"table2Rel": {  
"type": "nested",  
"properties": {  
"rel\_type": { "type": "keyword" },  
"table2\_id": { "type": "integer" },  
"eff\_start\_time": { "type": "date" },  
"eff\_end\_time": { "type": "date" },  
"join\_field" : {  
"type":"join",  
"relations":{  
"table2Rel" : "table3"  
}  
}  
}  
}  
}  
}  
}  
~  
This mapping would give me error , it stated that you cannot put join\_field in inner object.

Please provide me suggestion how can i migrate the tables

---

<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:** [April 28, 2020, 7:02am UTC](https://discuss.elastic.co/t/when-to-use-nested-object-vs-parent-child-relation/225799/2 "2020-04-28T07:02:08Z")

</div>

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