# If Custom Routing will make document overwrited by same id

**URL:** <https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660>\
**Category:** Elasticsearch\
**Created:** [July 16, 2019, 7:10am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660 "2019-07-16T07:10:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pa101](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pa101](https://discuss.elastic.co/u/pa101)\
**Post date:** [July 16, 2019, 7:10am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660/1 "2019-07-16T07:10:32Z")

</div>

if Custom Routing will make document overwrited by same id , when there is a hash Collisions between routing? I found when routing produce same string by murmur hash, and documents with same id are overwited  
for example routing=2 and routing=4, with 60 shards, and same id document will be overwited meanwhile other routing won't produce such situation.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 16, 2019, 7:34am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660/2 "2019-07-16T07:34:33Z")

</div>

Welcome!

You should never use the same `_id` for different documents whatever the `_routing` key is.

---

<div class="post-metadata">

**Author:** ![pa101](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pa101](https://discuss.elastic.co/u/pa101)\
**Post date:** [July 16, 2019, 8:04am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660/3 "2019-07-16T08:04:21Z")

</div>

thank u very much, I will make \_id unique. Out of curiosity, so document will overwrites with same id when it's in same shard? I found it won't overwrite same id with different routing which not hash collision (in different shard),

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 16, 2019, 8:31am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660/4 "2019-07-16T08:31:26Z")

</div>

Yes.

If you do:

```auto
PUT test/_doc/1
{
  "foo": "bar"
}
PUT test/_doc/1
{
  "foo": "baz"
}
GET test/_doc/1

```

Then you will get this document:

```auto
{
  "foo": "baz"
}

```

---

<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:** [August 13, 2019, 8:31am UTC](https://discuss.elastic.co/t/if-custom-routing-will-make-document-overwrited-by-same-id/190660/5 "2019-08-13T08:31:29Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
