Dynamic template for parent child mapping

I'm using Elastic search 2.4.6 version. I want to have parent child relationship in my document. Parent is product related attributes and child is parent-city related attributes. We've around 100 cities now. Our idea is Product related attributes is Parent type and each city/product related attributes in product_{city}. So 100 types. Is there anyway to define this mapping dynamically like this ?

  {
        "mappings": {
            "product": {},
            "product_*": {
                "_parent": {
                    "type": "product"
                }
            }
        }
    } 

So that when we add new city, I don't have to delete and recreate the index again ?

So 100 types

I cannot think of a good way to solve this issue, but I just want to warn you that this approach is not sustainable in a long run. It is not efficient and the current version of elasticsearch doesn't support more than 1 type per index. So, I would recommend going with just 2 types - one for product and another for attribute. And if you are developing a new system, I would strongly advise to go with a more modern version of ES since the handling of parent child relationships and types changed dramatically recently.

Thanks for the response. Our main reason to have 100 types is to have smaller set for search. Our search is always at single city level. We'll try to have to single type and see how that affects the performance.

Internally searching a type is implemented as a term query on the internal field _type. This query is automatically added to your search when you search within a type. If you add a not analyzed field called type and add your own term query to your search, you will get the same performance benefits during search, but you will save time maintaining and shipping around a huge mapping in the cluster state.

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