Self type join in elasticsearch

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

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

--Alex

1 Like

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

yes, that was what I meant.

Thanks I will try it tomorrow.

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