Retrieving a document by its ID, JAVA API

Hello,
I am a newbie to elasticsearch. I wanted to know how, in JAVA, can we
retrieve a document if we know its ID? Any help would be appreciated.

HTH
David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 20 juin 2012 à 11:39, Harsh harsh.chhatwani@gmail.com a écrit :

Hello,
I am a newbie to elasticsearch. I wanted to know how, in JAVA, can we retrieve a document if we know its ID? Any help would be appreciated.

To help out a little more, check the IdsQueryBuilder. So, something like this:

SearchRequestBuilder req = xxxx; // however you usually get your request builder...
IdsQueryBuilder qb = QueryBuilders.idsQuery(type);
qb.addIds(id1);
req.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(qb)
.addField(fieldName);
SearchResponse resp = req.execute().actionGet();

Bob.