Retrieving a document by its ID, JAVA API

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Retrieving a document by its ID, JAVA API

Harsh
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.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving a document by its ID, JAVA API

dadoonet
http://www.elasticsearch.org/guide/reference/java-api/get.html

HTH
David ;-)
Twitter : @dadoonet / @elasticsearchfr

Le 20 juin 2012 à 11:39, Harsh <[hidden email]> 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.
Reply | Threaded
Open this post in threaded view
|

Re: Retrieving a document by its ID, JAVA API

rpsandiford
This post has NOT been accepted by the mailing list yet.
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.
Bob.