# \[Parent-child deletion\] documentation says routing is required but without routing it works. \[ES 6.5v\]

**URL:** <https://discuss.elastic.co/t/parent-child-deletion-documentation-says-routing-is-required-but-without-routing-it-works-es-6-5v/163290>\
**Category:** Elasticsearch\
**Created:** [January 8, 2019, 2:14am UTC](https://discuss.elastic.co/t/parent-child-deletion-documentation-says-routing-is-required-but-without-routing-it-works-es-6-5v/163290 "2019-01-08T02:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mashhur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mashhur/32/39553_2.png) [@mashhur](https://discuss.elastic.co/u/mashhur)\
**Post date:** [January 8, 2019, 2:14am UTC](https://discuss.elastic.co/t/parent-child-deletion-documentation-says-routing-is-required-but-without-routing-it-works-es-6-5v/163290/1 "2019-01-08T02:14:53Z")

</div>

Hi there,  
I have started using Elasticsearch 6.5 version with parent-child actions (mapping, indexing, updating, deleting). In case of delete, documentation says ROUTING value is required. In a reality ROUTING value is not required and so it works! Because parent and child are in a same index (from ES \>=6.0). So, is documentation wrongly typed or is it ES bug?

## Documentation page: [https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html:](https://www.elastic.co/guide/en/elasticsearch/reference/current/parent-join.html:)

Parent-join restrictions  
Only one join field mapping is allowed per index.  
Parent and child documents must be indexed on the same shard. This means that the same routing value needs to be provided when getting, deleting, or updating a child document.  
An element can have multiple children but only one parent.  
It is possible to add a new relation to an existing join field.  
It is also possible to add a child to an existing element but only if the element is already a parent.

---

<div class="post-metadata">

**Author:** ![mashhur](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mashhur/32/39553_2.png) [@mashhur](https://discuss.elastic.co/u/mashhur)\
**Post date:** [January 10, 2019, 4:49am UTC](https://discuss.elastic.co/t/parent-child-deletion-documentation-says-routing-is-required-but-without-routing-it-works-es-6-5v/163290/2 "2019-01-10T04:49:24Z")

</div>

I got clear explanation through email.  
So, in some cases I will success on it, in some cases not!  
It means if doc is found without routing value it can be deleted, otherwise not.

Here is the experiment I got and id=3 or id=4 certainly CANNOT BE DELETED because of routing value.  
Thanks for ES dev group!

# Here is the Experiment

## Define your index

```
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "my_join_field": { 
          "type": "join",
          "relations": {
            "question": "answer" 
          }
        }
      }
    }
  }
}

```

# Index doc 1

```
PUT my_index/_doc/1?refresh
{
  "text": "This is a question",
  "my_join_field": "question" 
}

```

# Index doc 2

```
PUT my_index/_doc/2?refresh
{
  "text": "This is another question",
  "my_join_field": "question"
}

```

# Index doc 3 (answer to q1)

```
PUT my_index/_doc/3?routing=1&refresh
{
  "text": "This is an answer",
  "my_join_field": {
    "name": "answer", 
    "parent": "1" 
  }
}

```

# Index doc 4 (answer to q2)

```
PUT my_index/_doc/4?routing=2&refresh
{
  "text": "This is another answer",
  "my_join_field": {
    "name": "answer",
    "parent": "2"
  }
}

```

# Search for all parent child (returns total of 4 documents)

```
GET my_index/_search
{
  "query": {
    "match_all": {}
  },
  "sort": ["_id"]
}

GET _cat/indices/my_index?v
GET _cat/shards/my_index?v

```

# Deleting documents 1 to 4, 3 or 4 doc deletion will fail

```
DELETE my_index/_doc/1
DELETE my_index/_doc/2
DELETE my_index/_doc/3
DELETE my_index/_doc/4

```

# You should still see 1 or 2 orphan documents exist in the index

```
GET _cat/shards/my_index?v

```

# To completely remove the documents - you'll need to provide the routing

```
DELETE my_index/_doc/3?routing=1
DELETE my_index/_doc/4?routing=2

```

# Now it should be completely clear

```
GET _cat/shards/my_index?v

```

# Confirm your search again

```
GET my_index/_search
{
  "query": {
    "match_all": {}
  },
  "sort": ["_id"]
}

```

# Delete when done / convinced 😉

```
DELETE my_index
```

---

<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:** [February 7, 2019, 4:49am UTC](https://discuss.elastic.co/t/parent-child-deletion-documentation-says-routing-is-required-but-without-routing-it-works-es-6-5v/163290/3 "2019-02-07T04:49:28Z")

</div>

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