# How to create a dynamic template for parent-child relationship in Elasticsearch 6.x version

**URL:** <https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274>\
**Category:** Elasticsearch\
**Created:** [June 10, 2018, 8:52pm UTC](https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274 "2018-06-10T20:52:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudeepkumarnair](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sudeepkumarnair](https://discuss.elastic.co/u/sudeepkumarnair)\
**Post date:** [June 10, 2018, 8:52pm UTC](https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274/1 "2018-06-10T20:52:44Z")

</div>

I am having a hard time in figuring the dynamic template which can define the parent-child relationship for ES 6.x . Any examples are welcome ...

Basically, I have a root and child documents (parent-child). Currently, I do the following explicit mapping:

PUT index-2018.06.05  
{  
"mappings": {  
"\_doc": {  
"properties": {  
"join\_field": {  
"type": "join",  
"relations": {  
"root": "child"  
}  
}  
}  
}  
}  
}

Is it possible for me to define the same as part of a dynamic template?

---

<div class="post-metadata">

**Author:** ![sudeepkumarnair](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sudeepkumarnair](https://discuss.elastic.co/u/sudeepkumarnair)\
**Post date:** [June 12, 2018, 5:47pm UTC](https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274/2 "2018-06-12T17:47:41Z")

</div>

ANYONE ?

---

<div class="post-metadata">

**Author:** ![sudeepkumarnair](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sudeepkumarnair](https://discuss.elastic.co/u/sudeepkumarnair)\
**Post date:** [June 13, 2018, 11:09pm UTC](https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274/3 "2018-06-13T23:09:37Z")

</div>

I managed to the same with two templates with different ordering numbers. Hope it helps someone.  
{  
"index\_patterns": [  
"discovery-\*"  
],  
"order": 0,  
"mappings": {  
"\_doc": {  
"properties": {  
"join\_field": {  
"type": "join",  
"relations": {  
"topo": "document"  
}  
}  
}  
}  
}  
}

PUT \_template/discovery-events  
{  
"order": 1,  
"index\_patterns": [  
"discovery-_"  
],  
"settings": {  
"index": {  
"number\_of\_shards": "1",  
"number\_of\_replicas": "1"  
}  
},  
"mappings": {  
"\_doc": {  
"dynamic\_templates": [  
{  
"timestamp": {  
"mapping": {  
"format": "strict\_date\_optional\_time||epoch\_millis",  
"type": "date"  
},  
"match\_mapping\_type": "long",  
"path\_match": "timestamp"  
}  
},  
{  
"name": {  
"mapping": {  
"type": "keyword"  
},  
"match\_mapping\_type": "string"  
}  
},  
{  
"namespace": {  
"mapping": {  
"type": "keyword"  
},  
"match\_mapping\_type": "string"  
}  
},  
{  
"doctype": {  
"mapping": {  
"type": "keyword"  
},  
"match\_mapping\_type": "string"  
}  
},  
{  
"dimensions": {  
"mapping": {  
"type": "nested",  
"eager\_global\_ordinals": true  
},  
"match": "_",  
"match\_mapping\_type": "object"  
}  
},  
{  
"values": {  
"mapping": {  
"type": "nested",  
"eager\_global\_ordinals": true  
},  
"match": "\*",  
"match\_mapping\_type": "object"  
}  
}  
]  
}  
},  
"aliases": {}  
}

---

<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 11, 2018, 11:11pm UTC](https://discuss.elastic.co/t/how-to-create-a-dynamic-template-for-parent-child-relationship-in-elasticsearch-6-x-version/135274/4 "2018-07-11T23:11:57Z")

</div>

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