# Extract UID of Documents with Java API

**URL:** <https://discuss.elastic.co/t/extract-uid-of-documents-with-java-api/84176>\
**Category:** Elasticsearch\
**Created:** [May 1, 2017, 7:31pm UTC](https://discuss.elastic.co/t/extract-uid-of-documents-with-java-api/84176 "2017-05-01T19:31:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m6800](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@m6800](https://discuss.elastic.co/u/m6800)\
**Post date:** [May 1, 2017, 7:31pm UTC](https://discuss.elastic.co/t/extract-uid-of-documents-with-java-api/84176/1 "2017-05-01T19:31:03Z")

</div>

Could anyone provide any pointers on grabbing the UID of a given document? I am using Elasticsearch 2.4. I am grabbing data the following way. I can get the GeoPoint values, but have not figured out a way to get the UID. Thanks

```
for (LeafReaderContext ctx : reader.leaves())
{
final MultiGeoPointValues values = fd.load(ctx).getGeoPointValues();

    for( int j = 0; j < ctx.reader().numDocs(); j++ ) 
    {
    	values.setDocument(j);
    	for (int k = 0; k < values.count(); k++ )
    	{
            	//get the value
            	org.elasticsearch.common.geo.GeoPoint geoPoint = values.valueAt(k);
            }
    }
}
```

---

<div class="post-metadata">

**Author:** ![m6800](https://avatars.discourse-cdn.com/v4/letter/m/76d3ee/32.png) [@m6800](https://discuss.elastic.co/u/m6800)\
**Post date:** [May 2, 2017, 1:08pm UTC](https://discuss.elastic.co/t/extract-uid-of-documents-with-java-api/84176/2 "2017-05-02T13:08:58Z")

</div>

I am able to get the UID when operating on an index with a single shard by adding integer j to ctx.docBase. This does not work with multiple shards because you end up with multiple documents having the same UID.

```
int uid = ctx.docBase + j;

```

Is there a shard offset that I can add to this equation to get the UID?

---

<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 30, 2017, 1:23pm UTC](https://discuss.elastic.co/t/extract-uid-of-documents-with-java-api/84176/3 "2017-05-30T13:23:28Z")

</div>

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