# Elasticsearch 5.3: Indexing child document winds up on different shard than parent

**URL:** <https://discuss.elastic.co/t/elasticsearch-5-3-indexing-child-document-winds-up-on-different-shard-than-parent/222127>\
**Category:** Elasticsearch\
**Created:** [March 4, 2020, 5:08pm UTC](https://discuss.elastic.co/t/elasticsearch-5-3-indexing-child-document-winds-up-on-different-shard-than-parent/222127 "2020-03-04T17:08:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BarryS](https://avatars.discourse-cdn.com/v4/letter/b/f0a364/32.png) [@BarryS](https://discuss.elastic.co/u/BarryS)\
**Post date:** [March 4, 2020, 5:08pm UTC](https://discuss.elastic.co/t/elasticsearch-5-3-indexing-child-document-winds-up-on-different-shard-than-parent/222127/1 "2020-03-04T17:08:14Z")

</div>

Elasticsearch 5.3 indexing issue: Children sometimes wind up on different shards than their parent after indexing. This prevents the use of hasChild and hasParent queries against the index.

The index (myindex\_v001) contains three types: tasks, documents, assignments. When creating the index, documents are mapped as children of tasks, and assignments are mapped as children of documents.

```
{
  "myindex_v001": {
    "mappings": {
      "tasks": {
        "_all": {
          "analyzer": "default",
          "search_analyzer": "default_search"
        },
        ...
}

{
  "myindex_v001": {
    "mappings": {
      "documents": {
        "_all": {
           "analyzer": "default",
          "search_analyzer": "default_search"
        },
        "_parent": {
          "type": "tasks"
        },
        "_routing": {
          "required": true
        },
        ...
}

{
  "myindex_v001": {
     "mappings": {
       "assignments": {
         "_all": {
             "analyzer": "default",
             "search_analyzer": "default_search"
         },
         "_parent": {
             "type": "documents"
         },
         "_routing": {
             "required": true
         },
         ...
}

```

All indexing is performed within a Java service. Java makes a REST call (PUT) to the url specifying the index, type, and parent\_id. The same code is used to perform indexing on tasks, documents, and assignments.

When indexing documents ([http://eshost](http://eshost):port/myindex/documents/{document\_id}?parent={task\_id}) each indexed document winds up on the same shard as its parent task as expected. hasChild queries work just fine for tasks/documents.

However, when indexing assignments ([http://eshost](http://eshost):port/myindex/assignments/{assignment\_id}?parent={document\_id}) the assignment usually winds up being indexed on a shard that is different from its parent document. This is causing problems because a hasChild and hasParent query does not work with documents/assignments.

Can anyone suggest what may be going wrong with indexing the assignments (not being placed on same shard as documents)?

---

<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:** [April 1, 2020, 5:08pm UTC](https://discuss.elastic.co/t/elasticsearch-5-3-indexing-child-document-winds-up-on-different-shard-than-parent/222127/2 "2020-04-01T17:08:28Z")

</div>

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