# Having same document id for different document types

**URL:** <https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513>\
**Category:** Elasticsearch\
**Created:** [June 11, 2015, 7:50pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513 "2015-06-11T19:50:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bvnagaraju](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bvnagaraju](https://discuss.elastic.co/u/bvnagaraju)\
**Post date:** [June 11, 2015, 7:50pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/1 "2015-06-11T19:50:26Z")

</div>

My application has a document structure , parts of its changes frequently and others remains same through out document life cycle .

As under hood elastic search update is delete and create new document as lucene segments are immutable ,am planning to have two types for same document , one that changes frequently and other that never changes .

Is it possible to have document with two types pointing to same document

---

<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:** [June 12, 2015, 5:46am UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/2 "2015-06-12T05:46:30Z")

</div>

You can have the same ID with different types, yes.  
But these will be treated as totally different documents.

---

<div class="post-metadata">

**Author:** ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)\
**Post date:** [June 12, 2015, 8:23pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/3 "2015-06-12T20:23:05Z")

</div>

I am pretty sure that the document type gets appended onto the ID, so this makes it impossible for two documents to have the same ID

---

<div class="post-metadata">

**Author:** ![bvnagaraju](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bvnagaraju](https://discuss.elastic.co/u/bvnagaraju)\
**Post date:** [June 12, 2015, 9:59pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/4 "2015-06-12T21:59:39Z")

</div>

am planning to use nested objects , is it possible just update the nested object to allow not to reindex (delete /create) entire document

---

<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:** [June 13, 2015, 4:30am UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/5 "2015-06-13T04:30:05Z")

</div>

Try it;

```
PUT test-test/

PUT test-test/test/1
{
  "value": "yes"
}

PUT test-test/nottest/1
{
  "value": "no"
}

GET test-test/nottest/1

GET test-test/test/1
```

---

<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:** [June 13, 2015, 4:31am UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/6 "2015-06-13T04:31:13Z")

</div>

Nesting requires updating the entire document.

---

<div class="post-metadata">

**Author:** ![bvnagaraju](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bvnagaraju](https://discuss.elastic.co/u/bvnagaraju)\
**Post date:** [June 19, 2015, 2:15am UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/7 "2015-06-19T02:15:05Z")

</div>

I think it can be done with parent - child relation , having the fields that gets changed as a separate types

Do you see any problem having multiple child possibly each field as a separate child

---

<div class="post-metadata">

**Author:** ![Harlin\_ES](https://avatars.discourse-cdn.com/v4/letter/h/977dab/32.png) [@Harlin\_ES](https://discuss.elastic.co/u/Harlin_ES)\
**Post date:** [June 19, 2015, 6:47pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/8 "2015-06-19T18:47:25Z")

</div>

What I mean was that it is impossible for two documents to have the same ID in Lucene since the document type gets appended to its Elasticsearch ID in Lucene.

---

<div class="post-metadata">

**Author:** ![bvnagaraju](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bvnagaraju](https://discuss.elastic.co/u/bvnagaraju)\
**Post date:** [June 23, 2015, 11:59pm UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/9 "2015-06-23T23:59:12Z")

</div>

Agree ,I mean to say that I can avoid elastic search updates (delete and re create) by indexing a child document for every frequently changed field

---

<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, 12:05am UTC](https://discuss.elastic.co/t/having-same-document-id-for-different-document-types/2513/10 "2017-07-06T00:05:47Z")

</div>


