# Convert parent doc to child doc in 6.6

**URL:** <https://discuss.elastic.co/t/convert-parent-doc-to-child-doc-in-6-6/268683>\
**Category:** Elasticsearch\
**Created:** [March 29, 2021, 5:54pm UTC](https://discuss.elastic.co/t/convert-parent-doc-to-child-doc-in-6-6/268683 "2021-03-29T17:54:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgeographer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kgeographer/32/26217_2.png) [@kgeographer](https://discuss.elastic.co/u/kgeographer)\
**Post date:** [March 29, 2021, 5:54pm UTC](https://discuss.elastic.co/t/convert-parent-doc-to-child-doc-in-6-6/268683/1 "2021-03-29T17:54:03Z")

</div>

In a 6.6 index, I have a join field 'relation' like so:

```auto
"relation": { 
  "type": "join",
  "relations": {
    "parent": "child" 
}

```

Several hundred parent docs need to become children to another existing parent doc. I have lists of all the relevant \_id values for 'demoted' docs and 'winner' docs. For example, I need to make 5678 a child of 5677

```auto
{
  "_index": "myindex",
  "_type": "place",
  "_id": "5678",
  "_source": {
    "children": [],
    "relation": {
      "name": "parent"
    }
  }
},
{
  "_index": "myindex",
  "_type": "place",
  "_id": "5677",
  "_source": {
    "children": [],
    "relation": {
      "name": "parent"
    }
  }
}

```

Currently, all child records include "\_routing": "1". I don't remember why I configured it that way, e.g.

```auto
{
  "_index": "myindex",
  "_type": "place",
  "_id": "6368962",
  "_routing": "1",
  "_source": {
    "children": [],
    "relation": {
      "parent": "13005543",
      "name": "child"
    }
  }
}

```

So the goal for the demoted doc is...

```auto
{
  "_index": "myindex",
  "_type": "place",
  "_id": "5678",
  "_routing": "1",
  "_source": {
    "children": [],
    "relation": {
      "parent": "5677",
      "name": "child"
    }
  }
}

```

I have tried this \_update in Kibana console

```auto
POST myindex/place/5678/_update
{"script":{
	"source": """
		ctx._source.relation=params.relation;
		ctx._source.children=params.children;""",
	"lang": "painless",
	"params":{
		"relation": {"name":"child","parent":"5677"},
		"children": [] }
}}

```

and get this error:  
`"[routing] is missing for join field [relation]"`

I tried adding `ctx._routing=1;` to the script, and it has no effect.  
Is there no way to "demote" a parent to a child and specify its new parent?

thx

---

<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 26, 2021, 5:54pm UTC](https://discuss.elastic.co/t/convert-parent-doc-to-child-doc-in-6-6/268683/2 "2021-04-26T17:54:19Z")

</div>

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