Extract UID of Documents with Java API


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++ ) 
    	for (int k = 0; k < values.count(); k++ )
            	//get the value
            	org.elasticsearch.common.geo.GeoPoint geoPoint = values.valueAt(k);


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?

(system) #3

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