# Index duplicate documents with the different routing id

**URL:** <https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124>\
**Category:** Elasticsearch\
**Created:** [December 18, 2020, 4:39pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124 "2020-12-18T16:39:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maksym1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maksym1/32/78018_2.png) [@Maksym1](https://discuss.elastic.co/u/Maksym1)\
**Post date:** [December 18, 2020, 4:39pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/1 "2020-12-18T16:39:32Z")

</div>

When I try to index two similar documents (in my case, these are customers) with the same id and a different routing id, I get the first document is created, but the second document is updated.

As I know, I can index two similar documents with different routing id.

Here is my mapping:

```auto
{
    "estimate-index": {
        "mappings": {
            "_routing": {
                "required": true
            },
            "properties": {
                "id": {
                    "type": "keyword"
                },
                "joinField": {
                    "type": "join",
                    "eager_global_ordinals": true,
                    "relations": {
                        "estimate": [
                            "customer"
                        ]
                    }
                },
                "name": {
                    "type": "text"
                },
                "number": {
                    "type": "text"
                },
                "parent": {
                    "type": "integer"
                }
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 18, 2020, 4:51pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/2 "2020-12-18T16:51:05Z")

</div>

The routing value determines which shard a document is routed to but it does not guarantee that two documents with different routing IDs will go to different shards. If the documents have the same ID and the routing value resolves to the same shard only the latest will be kept. You can easily see this by indexing a number of documents (3 or more) with the same ID but different routing IDs into an index with just 2 primary shards and see how many total documents are reported..

---

<div class="post-metadata">

**Author:** ![Maksym1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maksym1/32/78018_2.png) [@Maksym1](https://discuss.elastic.co/u/Maksym1)\
**Post date:** [December 18, 2020, 5:19pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/3 "2020-12-18T17:19:00Z")

</div>

How can I organize such a relationship? I would like to store many documents that can point to one document.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 18, 2020, 5:26pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/4 "2020-12-18T17:26:45Z")

</div>

I am not sure I understand the question. Can you give an example? What do you mean by "I would like to store many documents that can point to one document."?

---

<div class="post-metadata">

**Author:** ![Maksym1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maksym1/32/78018_2.png) [@Maksym1](https://discuss.elastic.co/u/Maksym1)\
**Post date:** [December 18, 2020, 5:37pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/5 "2020-12-18T17:37:24Z")

</div>

For example, I want to index a two-child document that has the same ID and different routing IDs. But, as far as I understand, the parent/child relationship doesn't allow it. How can I get around this limitation?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 18, 2020, 5:42pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/6 "2020-12-18T17:42:22Z")

</div>

As far as I know you can not. Instead give the documents unique IDs.

---

<div class="post-metadata">

**Author:** ![Maksym1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maksym1/32/78018_2.png) [@Maksym1](https://discuss.elastic.co/u/Maksym1)\
**Post date:** [December 18, 2020, 5:46pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/7 "2020-12-18T17:46:22Z")

</div>

Thank you.

---

<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:** [January 15, 2021, 5:46pm UTC](https://discuss.elastic.co/t/index-duplicate-documents-with-the-different-routing-id/259124/8 "2021-01-15T17:46:42Z")

</div>

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