# What is difference between document id and index id?

**URL:** <https://discuss.elastic.co/t/what-is-difference-between-document-id-and-index-id/5758>\
**Category:** Elasticsearch\
**Created:** [November 3, 2011, 7:27am UTC](https://discuss.elastic.co/t/what-is-difference-between-document-id-and-index-id/5758 "2011-11-03T07:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_4](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@Sam\_4](https://discuss.elastic.co/u/Sam_4)\
**Post date:** [November 3, 2011, 7:27am UTC](https://discuss.elastic.co/t/what-is-difference-between-document-id-and-index-id/5758/1 "2011-11-03T07:27:55Z")

</div>

Hi

I have doubt regarding document id and index id:

1.both are same or both are different.

2.how to set the document id using java API.

Thanks

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [November 3, 2011, 8:25am UTC](https://discuss.elastic.co/t/what-is-difference-between-document-id-and-index-id/5758/2 "2011-11-03T08:25:10Z")

</div>

When you create an index you'll need the name(==index id) or what do  
you mean?

When you create a document you can specify the id:  
client.prepareIndex("index", "type", "id")

or using bulk api:  
BulkRequestBuilder brb = client.prepareBulk();  
IndexRequest indexReq =  
Requests.indexRequest("index").type("type").id("id").source(source);  
brb.add(indexReq);

Peter.

On 3 Nov., 08:27, sam [mishra.sam...@gmail.com](mailto:mishra.sam...@gmail.com) wrote:

> Hi
> 
> I have doubt regarding document id and index id:
> 
> 1.both are same or both are different.
> 
> 2.how to set the document id using java API.
> 
> Thanks

---

<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, 3:50am UTC](https://discuss.elastic.co/t/what-is-difference-between-document-id-and-index-id/5758/3 "2017-07-06T03:50:00Z")

</div>


