Best way to index hierarchical types

Let's say I have hierarchical types such as in example below:

base_type
    child_type1
        child_type3
    child_type2

child_type1 and child_type2 inherit metadata properties from base_type. child_type3 has all properties inherited from both child_type1 and base_type.

To add to the example, here's several objects with their properties:

base_type_object: {
    base_type_property: "bto_prop_value_1"
},
child_type1_object: {
    base_type_property: "ct1o_prop_value_1",
    child_type1_property: "ct1o_prop_value_2"
},
child_type2_object: {
    base_type_property: "ct2o_prop_value_1",
    child_type2_property: "ct2o_prop_value_2"
},
child_type3_object: {
    base_type_property: "ct3o_prop_value_1",
    child_type1_property: "ct3o_prop_value_2",
    child_type3_property: "ct3o_prop_value_3"
}

When I query for base_type_object, I expect to search base_type_property values in each and every one of the child types as well. Likewise, if I query for child_type1_property, I expect to search through all types that have such property, meaning objects of type child_type1 and child_type3.

I see that mapping types have been removed. What I'm wondering is whether this use case warrants indexing under separate indices.

My current line of thinking using example above would be to create 4 indices: base_type_index, child_type1_index, child_type2_index and child_type3_index. Each index would only have mappings of their own properties, so base_type_index would only have base_type_property, child_type1_index would have child_type1_property etc. Indexing child_type1_object would create an entry on both base_type_index and child_type1_index indices.
This seems convenient because it's possible to search multiple indices using GET /my-index-000001,my-index-000002/_search. So I would technically just need to list my hierarchical types in GET request: GET /base_type_index,child_type1_index/_search.

Does this make sense and is there a better way of indexing for my use case?

Thanks in advance.

Different indexing strategy, the way it's currently implemented:

What I did was call PUT on /parent/mapping with body:

{
    "properties": {
        "parent.parent_property": {
            "type": "text"
        },
        "parent.child1.child1_property": {
            "type": "text"
        },
        "parent.child1.child3.child3_property": {
            "type": "text"
        },
        "parent.child2.child2_property": {
            "type": "text"
        }
    }
}

Calling GET on /parent/_mapping nets me the following result:

{
    "parent": {
        "mappings": {
            "properties": {
                "parent": {
                    "properties": {
                        "child1": {
                            "properties": {
                                "child1_property": {
                                    "type": "text"
                                },
                                "child3": {
                                    "properties": {
                                        "child3_property": {
                                            "type": "text"
                                        }
                                    }
                                }
                            }
                        },
                        "child2": {
                            "properties": {
                                "child2_property": {
                                    "type": "text"
                                }
                            }
                        },
                        "parent_property": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

My worry here is
a) whether this has anything to do with deprecated mapping types.
b) it will result in a single index. I assume it will take a performance hit

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