N-Level Category Tree Mapping

I have an ElasticSearch document mapping that is designed to support an n-level category tree, is there an alternate recommendation or best practice to accomplish n-level trees within a mapping structure? We are using the NEST client for building up our queries and to properly query and aggregate on this mapping is rather challenging and we haven't been able to dynamically build up the queries to search the entire tree.

Here's a json implementation of what our mapping looks like for the category tree
"productIndex": {
"mappings": {
"_doc": {
"properties": {
"productId": {
"type": "integer"
},
"category": {
"properties": {
"categoryId": {
"type": "integer"
},
"categoryName": {
"type": "text"
},
"childCategories": {
"categoryId": {
"type": "integer"
},
"categoryName": {
"type": "text"
}
}
}
}
}
}
}
}

Future use case for this product document mapping would be to allow for a product to be a part of multiple leaf nodes within the category tree.

Thanks!

Hey,

I am not sure if this solves your problem of fully modeling a tree, but the main question usually is, if this is required for a search (and again the answer is that it depends on your use-case).

A common trick for these kind of problems is using the path hierarchy tokenizer, which would allow you to specify categories (even multiple ones) in some kind of a breadcrumb and this also filter based on the breadcrumb (including prefix filtering).

Hope this helps as an alternative start!

--Alex

Thanks for the recommendation! I hadn't looked at using the path hierarchy tokenizer yet but will certainly look into it.

In our use case, the category names are searchable and the category ids are used in the query filters.

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