# Indexed documents with composite \_id collide

**URL:** <https://discuss.elastic.co/t/indexed-documents-with-composite-id-collide/286073>\
**Category:** Elasticsearch\
**Created:** [October 6, 2021, 8:56pm UTC](https://discuss.elastic.co/t/indexed-documents-with-composite-id-collide/286073 "2021-10-06T20:56:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason-Leap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jason-leap/32/83901_2.png) [@Jason-Leap](https://discuss.elastic.co/u/Jason-Leap)\
**Post date:** [October 6, 2021, 8:56pm UTC](https://discuss.elastic.co/t/indexed-documents-with-composite-id-collide/286073/1 "2021-10-06T20:56:51Z")

</div>

Hi guys. I've found some interesting behaviour that I was hoping to get some clarification on. Let's say I perform a bulk index of two documents like so:

```auto
curl --request POST \
  --url <domain>/<index>/_bulk \
  --header 'Content-Type: application/json' \
  --data '{ "index" : { "_id": "aaa", "_type": "1" }}
{ "name": "Carlson Barnes", "age": 34}
{ "index" : { "_id": "aaa#bbb", "_type": "1" }}
{ "name": "Sheppard Stein","age": 39}
'

```

And now I go to retrieve the record aaa#bbb:

```auto
curl --request GET \
  --url '<domain>/<index>/1/aaa#bbb'

```

This replies with:

```auto
{
  "_index": "<index>",
  "_type": "1",
  "_id": "aaa",
  "_version": 2,
  "_seq_no": 2,
  "_primary_term": 1,
  "found": true,
  "_source": {
    "name": "Carlson Barnes",
    "age": 34
  }
}

```

So it's actually matching on and returning aaa, instead of aaa#bbb. I believe that this is a problem when indexing rather and retrieving, since I originally noticed this behaviour when indexing multiple documents with composite \_id fields and then doing an aggregation.

Can anyone explain why this happens, and if it's intended behaviour? My workaround at this stage is to perhaps create a hash to use for the \_id field, and move the composite key into a separate field.

Thanks heaps!

Update: This mainly seems to be a problem with using a hash as a delimiter. Using a colon or underscore seems to work as expected.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 11, 2021, 1:02am UTC](https://discuss.elastic.co/t/indexed-documents-with-composite-id-collide/286073/2 "2021-10-11T01:02:16Z")

</div>

Welcome to our community! 😃 We aren't all guys though 🙂

> [@Jason-Leap](#):
>
> I believe that this is a problem when indexing rather and retrieving

Yes, that's show with `"_version": 2`. AFAIK you can include these sorts of non-alpha chars in the `_id` but you need to escape them to work.

---

<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:** [November 8, 2021, 1:02am UTC](https://discuss.elastic.co/t/indexed-documents-with-composite-id-collide/286073/3 "2021-11-08T01:02:34Z")

</div>

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