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

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:

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.

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 :wink:

DELETE my_index
2 Likes

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