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

**URL:** https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988
**Category:** Elasticsearch
**Created:** [March 4, 2013, 9:06am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988 "2013-03-04T09:06:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Eran\_Eidinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eran_eidinger/32/44831_2.png) [@Eran\_Eidinger](https://discuss.elastic.co/u/Eran_Eidinger)
#### Post date: [March 4, 2013, 9:06am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/1 "2013-03-04T09:06:23Z")

</div>

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](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?

---

<div class="post-metadata">

### Author: ![Eran\_Eidinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eran_eidinger/32/44831_2.png) [@Eran\_Eidinger](https://discuss.elastic.co/u/Eran_Eidinger)
#### Post date: [March 4, 2013, 9:08am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/2 "2013-03-04T09:08:47Z")

</div>

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](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](http://localhost:9200/my_index/my_doctype/id1&routing=new_parent)

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [March 4, 2013, 10:47am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/3 "2013-03-04T10:47:22Z")

</div>

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:

> <https://gist.github.com/radu-gheorghe/5081445>

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Mar 4, 2013 at 11:08 AM, eranid [eranid@gmail.com](mailto: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](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](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](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](http://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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [March 4, 2013, 10:48am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/4 "2013-03-04T10:48:28Z")

</div>

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](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](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](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](http://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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Eran\_Eidinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eran_eidinger/32/44831_2.png) [@Eran\_Eidinger](https://discuss.elastic.co/u/Eran_Eidinger)
#### Post date: [March 4, 2013, 10:51am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/5 "2013-03-04T10:51:06Z")

</div>

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

On Mon, Mar 4, 2013 at 12:48 PM, Clinton Gormley-2 [via Elasticsearch  
Users] [ml-node+s115913n4030911h17@n3.nabble.com](mailto: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](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](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](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](http://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](http://user/SendEmail.jtp?type=node&node=4030911&i=0).
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](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](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 here[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe\_by\_code&node=4030897&code=ZXJhbmlkQGdtYWlsLmNvbXw0MDMwODk3fDY0MzA1NjE1MA==](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4030897&code=ZXJhbmlkQGdtYWlsLmNvbXw0MDMwODk3fDY0MzA1NjE1MA==)  
> .  
> NAML[http://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](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml)

---

<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, 2:48am UTC](https://discuss.elastic.co/t/can-two-documents-with-the-same-id-exist-if-they-have-different-parents/10988/6 "2017-07-06T02:48:38Z")

</div>


