# How to get document id using java api?

**URL:** <https://discuss.elastic.co/t/how-to-get-document-id-using-java-api/5756>\
**Category:** Elasticsearch\
**Created:** [November 3, 2011, 6:30am UTC](https://discuss.elastic.co/t/how-to-get-document-id-using-java-api/5756 "2011-11-03T06:30:56Z")\
**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, 6:30am UTC](https://discuss.elastic.co/t/how-to-get-document-id-using-java-api/5756/1 "2011-11-03T06:30:56Z")

</div>

Hi

I have doubt regarding setting document id manually or automatically.

1.what benefit we get from setting document id.

2.if it not set the it assign automatically which java method is help  
to get the document id.

Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 3, 2011, 1:08pm UTC](https://discuss.elastic.co/t/how-to-get-document-id-using-java-api/5756/2 "2011-11-03T13:08:14Z")

</div>

It depends on your use case.  
It could be useful for debugging for example.

You could use also ES as a NoSql database and need to retrieve docs by Id.

I think you can get the ID back in the IndexResponse object.  
[https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexResponse.java#L101](https://github.com/elasticsearch/elasticsearch/blob/master/modules/elasticsearch/src/main/java/org/elasticsearch/action/index/IndexResponse.java#L101)

David 😉

Le 3 nov. 2011 à 07:30, sam [mishra.sameek@gmail.com](mailto:mishra.sameek@gmail.com) a écrit :

> Hi
> 
> I have doubt regarding setting document id manually or automatically.
> 
> 1.what benefit we get from setting document id.
> 
> 2.if it not set the it assign automatically which java method is help  
> to get the document id.
> 
> 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:49am UTC](https://discuss.elastic.co/t/how-to-get-document-id-using-java-api/5756/3 "2017-07-06T03:49:56Z")

</div>


