Can two documents with the same ID exist if they have different parents?

I tried to change the parent of a document, simply by reindexing it with another parent.

I then got the following:
curl -X GET 'http://localhost:9200/my_index/my_doctype/_search?pretty=true' -d '{"fields":["_parent"],"query":{"match":{"doc_id": "id1"}}}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 11.163984,
"hits" : [ {
"_index" : "my_index",
"_type" : "my_doctype",
"_id" : "id1",
"_score" : 11.163984,
"fields" : {
"_parent" : "old_parent"
}
}, {
"_index" : "my_index",
"_type" : "my_doctype",
"_id" : "id1",
"_score" : 10.388675,
"fields" : {
"_parent" : "new_parent"
}
} ]
}

How can this be? can two documents of the same type exist with the same ID if they have a different parent?

If so, how do I delete one of them (the old_parent one...), but not the other?

Also, none of them is accessible by "get" now.

neither of the following returns any result:
curl -X GET 'http://localhost:9200/my_index/my_doctype/id1&routing=old_parent
curl -X GET 'http://localhost:9200/my_index/my_doctype/id1&routing=new_parent

Hello,

There can be different documents with the same ID if they have different
routing values. And child documents automatically get their parents' IDs as
routing values.

The fact that you can't retrieve them afterwards, even with the parent's ID
as routing value is a bit strange. Can you gist a curl recreation of the
problem? For me, this works:

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Mon, Mar 4, 2013 at 11:08 AM, eranid eranid@gmail.com wrote:

Also, none of them is accessible by "get" now.

neither of the following returns any result:
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=old_parent
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=new_parent

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Can-two-documents-with-the-same-ID-exist-if-they-have-different-parents-tp4030897p4030898.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

On Mon, 2013-03-04 at 01:06 -0800, eranid wrote:

I tried to change the parent of a document, simply by reindexing it with
another parent.

How can this be? can two documents of the same type exist with the same ID
if they have a different parent?

A child is assigned to a particular shard based on the parent ID. If
you change the parent, then it tries to index that doc on a new shard
(potentially, depending on which shard the new ID hashes to) but it
doesn't know that it has to delete the old version on the old shard.

You have to handle this one yourself.

Also, none of them is accessible by "get" now.

neither of the following returns any result:
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=old_parent
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=new_parent

That's because you're using '&' instead of '?'

clint

If so, how do I delete one of them (the old_parent one...), but not the
other?

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Can-two-documents-with-the-same-ID-exist-if-they-have-different-parents-tp4030897.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Raud and Clinton.
Together, you answered all my question :slight_smile:

On Mon, Mar 4, 2013 at 12:48 PM, Clinton Gormley-2 [via Elasticsearch
Users] ml-node+s115913n4030911h17@n3.nabble.com wrote:

On Mon, 2013-03-04 at 01:06 -0800, eranid wrote:

I tried to change the parent of a document, simply by reindexing it with
another parent.

How can this be? can two documents of the same type exist with the same
ID
if they have a different parent?

A child is assigned to a particular shard based on the parent ID. If
you change the parent, then it tries to index that doc on a new shard
(potentially, depending on which shard the new ID hashes to) but it
doesn't know that it has to delete the old version on the old shard.

You have to handle this one yourself.

Also, none of them is accessible by "get" now.

neither of the following returns any result:
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=old_parent
curl -X GET
'http://localhost:9200/my_index/my_doctype/id1&routing=new_parent

That's because you're using '&' instead of '?'

clint

If so, how do I delete one of them (the old_parent one...), but not the
other?

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Can-two-documents-with-the-same-ID-exist-if-they-have-different-parents-tp4030897.html

Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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 [hidden email]http://user/SendEmail.jtp?type=node&node=4030911&i=0.

For more options, visit https://groups.google.com/groups/opt_out.


If you reply to this email, your message will be added to the discussion
below:

http://elasticsearch-users.115913.n3.nabble.com/Can-two-documents-with-the-same-ID-exist-if-they-have-different-parents-tp4030897p4030911.html
To unsubscribe from Can two documents with the same ID exist if they have
different parents?, click herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4030897&code=ZXJhbmlkQGdtYWlsLmNvbXw0MDMwODk3fDY0MzA1NjE1MA==
.
NAMLhttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers!nabble%3Aemail.naml-instant_emails!nabble%3Aemail.naml-send_instant_email!nabble%3Aemail.naml