# Changing Parents

**URL:** https://discuss.elastic.co/t/changing-parents/8106
**Category:** Elasticsearch
**Created:** [June 14, 2012, 3:39pm UTC](https://discuss.elastic.co/t/changing-parents/8106 "2012-06-14T15:39:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Florian\_Gilcher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florian_gilcher/32/2809_2.png) [@Florian\_Gilcher](https://discuss.elastic.co/u/Florian_Gilcher)
#### Post date: [June 14, 2012, 3:39pm UTC](https://discuss.elastic.co/t/changing-parents/8106/1 "2012-06-14T15:39:56Z")

</div>

Hi,

I have been playing around with parent/child documents lately and the  
following question came up: is it possible to change the parent of a  
document?

Say, I have the following two documents:

/person/1 -d {}  
/person/2 -d {}

and an asset:

/asset/3?parent=1

is it possible to change the parent to "2"?

Reindexing with parent 2 only seems to introduce a second document. (which  
makes sense, as parent doubles as routing parameter)

I tried setting the \_parent field directly to 2 in multiple ways (index,  
update with script), but it somehow seemed to render elasticsearch  
inconsistent (e.g. parents were still querying their old childs on  
has\_child).

Is this possible or supported? Or do I have to delete the old document and  
index a new one with the same source, but different \_parent settings?

Best Regards,  
Florian

---

<div class="post-metadata">

### Author: ![Patrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick/32/1437_2.png) [@Patrick](https://discuss.elastic.co/u/Patrick)
#### Post date: [June 14, 2012, 4:00pm UTC](https://discuss.elastic.co/t/changing-parents/8106/2 "2012-06-14T16:00:09Z")

</div>

I don't believe it is without creating a new document and deleting the old  
one, that you can move parents. Most modification actions imply a  
recreation of a document, and not an update.

## Patrick

> **[Patrick Ancillotti on about.me](https://about.me/patrick.ancillotti)**
>
> I live in New York.

patrick eefy net

On Thu, Jun 14, 2012 at 9:39 AM, Florian Gilcher [flo@andersground.net](mailto:flo@andersground.net)wrote:

> Hi,
> 
> I have been playing around with parent/child documents lately and the  
> following question came up: is it possible to change the parent of a  
> document?
> 
> Say, I have the following two documents:
> 
> /person/1 -d {}  
> /person/2 -d {}
> 
> and an asset:
> 
> /asset/3?parent=1
> 
> is it possible to change the parent to "2"?
> 
> Reindexing with parent 2 only seems to introduce a second document. (which  
> makes sense, as parent doubles as routing parameter)
> 
> I tried setting the \_parent field directly to 2 in multiple ways (index,  
> update with script), but it somehow seemed to render elasticsearch  
> inconsistent (e.g. parents were still querying their old childs on  
> has\_child).
> 
> Is this possible or supported? Or do I have to delete the old document and  
> index a new one with the same source, but different \_parent settings?
> 
> Best Regards,  
> Florian

---

<div class="post-metadata">

### Author: ![Pierre\_Durand](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierre_durand/32/1895_2.png) [@Pierre\_Durand](https://discuss.elastic.co/u/Pierre_Durand)
#### Post date: [June 14, 2012, 4:56pm UTC](https://discuss.elastic.co/t/changing-parents/8106/3 "2012-06-14T16:56:16Z")

</div>

imo, it's not possible, because a child document is stores on the same  
shard as its parent

On Thursday, June 14, 2012 6:00:09 PM UTC+2, Patrick Ancillotti wrote:

> I don't believe it is without creating a new document and deleting the old  
> one, that you can move parents. Most modification actions imply a  
> recreation of a document, and not an update.
> 
> ## Patrick
> 
> [Patrick Ancillotti - New York | about.me](http://about.me/patrick.ancillotti)  
> patrick eefy net
> 
> On Thu, Jun 14, 2012 at 9:39 AM, Florian Gilcher [flo@andersground.net](mailto:flo@andersground.net)wrote:
> 
> > Hi,
> > 
> > I have been playing around with parent/child documents lately and the  
> > following question came up: is it possible to change the parent of a  
> > document?
> > 
> > Say, I have the following two documents:
> > 
> > /person/1 -d {}  
> > /person/2 -d {}
> > 
> > and an asset:
> > 
> > /asset/3?parent=1
> > 
> > is it possible to change the parent to "2"?
> > 
> > Reindexing with parent 2 only seems to introduce a second document.  
> > (which makes sense, as parent doubles as routing parameter)
> > 
> > I tried setting the \_parent field directly to 2 in multiple ways (index,  
> > update with script), but it somehow seemed to render elasticsearch  
> > inconsistent (e.g. parents were still querying their old childs on  
> > has\_child).
> > 
> > Is this possible or supported? Or do I have to delete the old document  
> > and index a new one with the same source, but different \_parent settings?
> > 
> > Best Regards,  
> > Florian

---

<div class="post-metadata">

### Author: ![Florian\_Gilcher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/florian_gilcher/32/2809_2.png) [@Florian\_Gilcher](https://discuss.elastic.co/u/Florian_Gilcher)
#### Post date: [June 23, 2012, 12:35pm UTC](https://discuss.elastic.co/t/changing-parents/8106/4 "2012-06-23T12:35:59Z")

</div>

Hi Pierre and Patrick,

thanks for the answers. So my suspicion was right. I was aware that this  
would be a special operation, as the child would have to be moved to the  
new shard.

I have an additional question for my future mental model: can I safely  
assume that documents never "travel" shards and have to be moved by hand?

Regards,  
Florian

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 25, 2012, 12:31pm UTC](https://discuss.elastic.co/t/changing-parents/8106/5 "2012-06-25T12:31:32Z")

</div>

Yes, you can assume that.

On Sat, Jun 23, 2012 at 2:35 PM, Florian Gilcher [flo@andersground.net](mailto:flo@andersground.net)wrote:

> Hi Pierre and Patrick,
> 
> thanks for the answers. So my suspicion was right. I was aware that this  
> would be a special operation, as the child would have to be moved to the  
> new shard.
> 
> I have an additional question for my future mental model: can I safely  
> assume that documents never "travel" shards and have to be moved by hand?
> 
> Regards,  
> Florian

---

<div class="post-metadata">

### Author: ![Mark\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/m/ccd318/32.png) [@Mark\_Hoffman](https://discuss.elastic.co/u/Mark_Hoffman)
#### Post date: [July 18, 2014, 5:40pm UTC](https://discuss.elastic.co/t/changing-parents/8106/6 "2014-07-18T17:40:52Z")

</div>

We have also experienced this issue where we are now using parent/child  
documents. We are using 0.90.5 version.  
Our application requires that we re-assign a child to a new parent from  
time to time and we discovered that without first deleting the child with  
the old parent, two documents with the same \_id but different parents can  
be in the index because the parents are on different shards. Does anyone  
know if it is possible to reassign a child to a new parent without first  
deleting might something available in newer versions? It seems reasonable  
that a document can be updated by it's canonical document id (\_id), without  
having to aware of the subtleties of sharding?

On Thursday, June 14, 2012 11:39:56 AM UTC-4, Florian Gilcher wrote:

> Hi,
> 
> I have been playing around with parent/child documents lately and the  
> following question came up: is it possible to change the parent of a  
> document?
> 
> Say, I have the following two documents:
> 
> /person/1 -d {}  
> /person/2 -d {}
> 
> and an asset:
> 
> /asset/3?parent=1
> 
> is it possible to change the parent to "2"?
> 
> Reindexing with parent 2 only seems to introduce a second document. (which  
> makes sense, as parent doubles as routing parameter)
> 
> I tried setting the \_parent field directly to 2 in multiple ways (index,  
> update with script), but it somehow seemed to render elasticsearch  
> inconsistent (e.g. parents were still querying their old childs on  
> has\_child).
> 
> Is this possible or supported? Or do I have to delete the old document and  
> index a new one with the same source, but different \_parent settings?
> 
> Best Regards,  
> Florian

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/7546af8c-cf8c-4960-97b1-876fdf264702%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/7546af8c-cf8c-4960-97b1-876fdf264702%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [July 6, 2017, 1:14am UTC](https://discuss.elastic.co/t/changing-parents/8106/7 "2017-07-06T01:14:50Z")

</div>


