# Self type join in elasticsearch

**URL:** <https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487>\
**Category:** Elasticsearch\
**Created:** [October 7, 2019, 7:21am UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487 "2019-10-07T07:21:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ducanh2110](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ducanh2110/32/55484_2.png) [@ducanh2110](https://discuss.elastic.co/u/ducanh2110)\
**Post date:** [October 7, 2019, 7:21am UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/1 "2019-10-07T07:21:38Z")

</div>

Hi, I have a question about child-parent join in Elasticsearch, I have a real model like Category and Product.

"categoryRelations": {  
"type": "join",  
"eager\_global\_ordinals": true,  
"relations": {  
"category": [  
"productContent",  
"category"  
]  
}  
}

and I design mapping in my index like that. My purpose here is category have child category, and in each category has its own product. Can i design like that or any suggestion for doing that? when I tried to put some data with relation category and parent it show exception: "DocValuesField "categoryRelations#category" appears more than once in this document (only one value is allowed per field)".

Thanks so much

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 7, 2019, 12:41pm UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/2 "2019-10-07T12:41:47Z")

</div>

Hey,

indeed, you cannot self join. If each product would contain the category it is in as an array (aka a multivalue), would that work as well? You might want to take a look at the [path hierarchy tokenizer](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/analysis-pathhierarchy-tokenizer.html)

--Alex

---

<div class="post-metadata">

**Author:** ![ducanh2110](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ducanh2110/32/55484_2.png) [@ducanh2110](https://discuss.elastic.co/u/ducanh2110)\
**Post date:** [October 7, 2019, 12:56pm UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/3 "2019-10-07T12:56:58Z")

</div>

Thanks for your support. I will make your solution clearly. You mean that i will add one field to product that contains all category tree that product is belong to? Is that what you mean. Thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 7, 2019, 12:59pm UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/4 "2019-10-07T12:59:27Z")

</div>

yes, that was what I meant.

---

<div class="post-metadata">

**Author:** ![ducanh2110](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ducanh2110/32/55484_2.png) [@ducanh2110](https://discuss.elastic.co/u/ducanh2110)\
**Post date:** [October 7, 2019, 1:30pm UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/5 "2019-10-07T13:30:25Z")

</div>

Thanks I will try it tomorrow.

---

<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:** [November 4, 2019, 1:30pm UTC](https://discuss.elastic.co/t/self-type-join-in-elasticsearch/202487/6 "2019-11-04T13:30:26Z")

</div>

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