# Duplicate document with same \_id and \_type

**URL:** <https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631>\
**Category:** Elasticsearch\
**Created:** [August 3, 2012, 4:13pm UTC](https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631 "2012-08-03T16:13:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dchancogne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dchancogne/32/2786_2.png) [@dchancogne](https://discuss.elastic.co/u/dchancogne)\
**Post date:** [August 3, 2012, 4:13pm UTC](https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631/1 "2012-08-03T16:13:14Z")

</div>

We are running in the same issue as in this post, unfortunately the thread  
doesn't really have any answer ☹ :  
[http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html](http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html)

Running a search against a single index for a 'post' with a given id we get  
2 hits. We use \_parent and use a  
'userId' for the parent. The following result happens after trying reassign  
the post to a different user and  
reindex the post. Is \_parent somehow used in the \_uid?

{

- took: 6
- timed\_out: false
- \_shards: {
  - total: 5
  - successful: 5
  - failed: 0  
}

- hits: {
  - total: 2
  - max\_score: 1
  - hits: [
    - {
      - \_index: traackr\_alt
      - \_type: post
      - \_id: 8fc84a5ce16436b2910276c109a439ed
      - \_score: 1
      - fields: {
        - channelId: a20fed5f67dd3f3599d8a85bbe7b65de
        - \_routing: 1f27ff80a17f3f4fb6b37e44a3bab059
        - \_parent: 1f27ff80a17f3f4fb6b37e44a3bab059
        - userId: 1f27ff80a17f3f4fb6b37e44a3bab059  
}  
}

    - {
      - \_index: traackr\_alt
      - \_type: post
      - \_id: 8fc84a5ce16436b2910276c109a439ed
      - \_score: 1
      - fields: {
        - channelId: 04cca4500ebf3322b4ca31bde245b6c1
        - \_routing: 9b932eb9528d39a3854b556b470d9579
        - \_parent: 9b932eb9528d39a3854b556b470d9579
        - userId: 9b932eb9528d39a3854b556b470d9579  
}  
}  
]  
}

}

---

<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:** [August 3, 2012, 4:23pm UTC](https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631/2 "2012-08-03T16:23:30Z")

</div>

On Fri, 2012-08-03 at 09:13 -0700, David Chancogne wrote:

> We are running in the same issue as in this post, unfortunately the  
> thread doesn't really have any answer ☹ :  
> [http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html](http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html)

> Running a search against a single index for a 'post' with a given id  
> we get 2 hits. We use \_parent and use a  
> 'userId' for the parent. The following result happens after trying  
> reassign the post to a different user and  
> reindex the post. Is \_parent somehow used in the \_uid?

A unique ID really depends on index/type/id/routing. The routing, by  
default, is derived from the ID. But if you use parent-child  
relationships, it is derived from the parent.

So if you change the parent and reindex, it may or may not end up on the  
same shard. If it is on a different shard, then the old doc will not be  
removed.

So if you're going to change the parent, you should delete the old doc  
before indexing the new doc

clint

---

<div class="post-metadata">

**Author:** ![dchancogne](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dchancogne/32/2786_2.png) [@dchancogne](https://discuss.elastic.co/u/dchancogne)\
**Post date:** [August 3, 2012, 5:38pm UTC](https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631/3 "2012-08-03T17:38:28Z")

</div>

On Friday, August 3, 2012 12:23:30 PM UTC-4, Clinton Gormley wrote:

> On Fri, 2012-08-03 at 09:13 -0700, David Chancogne wrote:
> 
> > We are running in the same issue as in this post, unfortunately the  
> > thread doesn't really have any answer ☹ :
> 
> [http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html](http://elasticsearch-users.115913.n3.nabble.com/duplicate-id-type-within-the-same-index-td3530682.html)
> 
> > Running a search against a single index for a 'post' with a given id  
> > we get 2 hits. We use \_parent and use a  
> > 'userId' for the parent. The following result happens after trying  
> > reassign the post to a different user and  
> > reindex the post. Is \_parent somehow used in the \_uid?
> 
> A unique ID really depends on index/type/id/routing. The routing, by  
> default, is derived from the ID. But if you use parent-child  
> relationships, it is derived from the parent.
> 
> So if you change the parent and reindex, it may or may not end up on the  
> same shard. If it is on a different shard, then the old doc will not be  
> removed.
> 
> So if you're going to change the parent, you should delete the old doc  
> before indexing the new doc

Thank you Clint. That makes sense. Just wish the doc on \_uid would  
mention that \_routing is derived from \_parent when present:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Thanks again.

---

<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, 3:17am UTC](https://discuss.elastic.co/t/duplicate-document-with-same--id-and--type/8631/4 "2017-07-06T03:17:47Z")

</div>


