# Best way to index hierarchical types

**URL:** <https://discuss.elastic.co/t/best-way-to-index-hierarchical-types/286242>\
**Category:** Elasticsearch\
**Created:** [October 8, 2021, 1:07pm UTC](https://discuss.elastic.co/t/best-way-to-index-hierarchical-types/286242 "2021-10-08T13:07:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lovrodoe](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@lovrodoe](https://discuss.elastic.co/u/lovrodoe)\
**Post date:** [October 8, 2021, 1:07pm UTC](https://discuss.elastic.co/t/best-way-to-index-hierarchical-types/286242/1 "2021-10-08T13:07:12Z")

</div>

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

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![lovrodoe](https://avatars.discourse-cdn.com/v4/letter/l/e47c2d/32.png) [@lovrodoe](https://discuss.elastic.co/u/lovrodoe)\
**Post date:** [October 11, 2021, 8:03am UTC](https://discuss.elastic.co/t/best-way-to-index-hierarchical-types/286242/2 "2021-10-11T08:03:22Z")

</div>

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

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

```auto
{
    "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:

```auto
{
    "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](https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html).  
b) it will result in a single index. I assume it will take a performance hit

---

<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 8, 2021, 8:04am UTC](https://discuss.elastic.co/t/best-way-to-index-hierarchical-types/286242/3 "2021-11-08T08:04:17Z")

</div>

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