Changing Parents

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

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 eefy net

On Thu, Jun 14, 2012 at 9:39 AM, Florian Gilcher flo@andersground.netwrote:

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

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
patrick eefy net

On Thu, Jun 14, 2012 at 9:39 AM, Florian Gilcher flo@andersground.netwrote:

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

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

Yes, you can assume that.

On Sat, Jun 23, 2012 at 2:35 PM, Florian Gilcher flo@andersground.netwrote:

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

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7546af8c-cf8c-4960-97b1-876fdf264702%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.