# How to Index duplicate documents with the different routing id

**URL:** <https://discuss.elastic.co/t/how-to-index-duplicate-documents-with-the-different-routing-id/302353>\
**Category:** Elasticsearch\
**Created:** [April 13, 2022, 3:10pm UTC](https://discuss.elastic.co/t/how-to-index-duplicate-documents-with-the-different-routing-id/302353 "2022-04-13T15:10:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raja\_augstin](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@raja\_augstin](https://discuss.elastic.co/u/raja_augstin)\
**Post date:** [April 13, 2022, 3:10pm UTC](https://discuss.elastic.co/t/how-to-index-duplicate-documents-with-the-different-routing-id/302353/1 "2022-04-13T15:10:02Z")

</div>

My index settings:

```auto
{
    "aliases": {
        "alias_test_read": {}
    },
    "mappings": {
        "_routing": {
            "required": true
        },
        "properties": {
            "id": {
                "type": "text",
                "store": true
            },
            "name": {
                "type": "text",
                "store": true
            },
            "type": {
                "type": "text",
                "store": true
            }
        }
    },
    "settings": {
        "index": {
            "number_of_shards": "3",
            "number_of_replicas": "1"
        }
    }
}

```

inserting the recodes using the bulk API:  
curl -xpost [http://host](http://host):port/test/\_bulk

```auto

{"index":{"_id":"1","routing":"ABC","version":"1","version_type":"external"}}
{"id": "1", "name" : "Raj", "type": "ABC"}
{"index":{"_id":"1","routing":"XYC","version":"1","version_type":"external"}}
{"id": "1", "name" : "Raj", "type": "XYC"}
{"index":{"_id":"1","routing":"PQR","version":"1","version_type":"external"}}
{"id": "1", "name" : "Raj", "type": "PQR"}

```

output:

```auto
{"took":9,"errors":true,"items":[{"index":{"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"test","_type":"_doc","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":2,"failed":0},"_seq_no":0,"_primary_term":1,"status":201}},{"index":{"_index":"test","_type":"_doc","_id":"1","status":409,"error":{"type":"version_conflict_engine_exception","reason":"[1]: version conflict, current version [1] is higher or equal to the one provided [1]","index_uuid":"VP024Sr9TRqsLBzsfEYoUA","shard":"1","index":"test"}}}]}

```

Not sure why i'm getting version conflict for third record alone not for the second. is their any way to keep same \_id with different routing records in index ?

---

<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:** [April 13, 2022, 5:20pm UTC](https://discuss.elastic.co/t/how-to-index-duplicate-documents-with-the-different-routing-id/302353/2 "2022-04-13T17:20:26Z")

</div>

All documents with a specific routing id will end up in the same shard but documents with different routing ids do not necessary end up in different shards. It is common to have significantly more routing ids than there is shards in an index. You can therefore not have multiple documents with trhe same id in an index separate by routing id. An option might be to create a document id consisting of the id concatenated with the routing id.

---

<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:** [May 11, 2022, 5:20pm UTC](https://discuss.elastic.co/t/how-to-index-duplicate-documents-with-the-different-routing-id/302353/3 "2022-05-11T17:20:38Z")

</div>

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