# Having grandchildren in index with multiple shards

**URL:** <https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878>\
**Category:** Elasticsearch\
**Created:** [December 14, 2018, 10:24am UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878 "2018-12-14T10:24:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![3ms1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/3ms1/32/54472_2.png) [@3ms1](https://discuss.elastic.co/u/3ms1)\
**Post date:** [December 14, 2018, 10:24am UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878/1 "2018-12-14T10:24:33Z")

</div>

Hi,

I have following relation in mapping grandparent -\> parent -\> children.

Currently, queries work but if the number of shards is increased to 5 (from 1) then the query below is not returning all result.

```
{
"query": {
    "has_child": {
      "type": "parent",
      "query": {
        "has_child": {
          "type": "children",
          "query": {
            "match_all": {}
          }
        }
      }
    }
  }
}

```

Can the reason be something related to routing?

Thanks,

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 14, 2018, 1:52pm UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878/2 "2018-12-14T13:52:14Z")

</div>

if you have grandparents/parents & children you have to make sure that **all** those documents from one grandparent are on the same shard. This is done by setting the `routing` to the id of the grandparent for all of those documents.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![3ms1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/3ms1/32/54472_2.png) [@3ms1](https://discuss.elastic.co/u/3ms1)\
**Post date:** [December 14, 2018, 2:34pm UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878/3 "2018-12-14T14:34:29Z")

</div>

First of all thank you for your quick response.

Currently, children have routing ids to their parents and they have routing to the grandparents.

So, only grandparents doesn't have routing.

What am I probably missing?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 14, 2018, 2:36pm UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878/4 "2018-12-14T14:36:33Z")

</div>

All documents (parents and children) must be routed based on the grandparent as all documents in the hierarchy must end up in the same shard.

---

<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:** [January 11, 2019, 2:42pm UTC](https://discuss.elastic.co/t/having-grandchildren-in-index-with-multiple-shards/160878/6 "2019-01-11T14:42:27Z")

</div>

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