Confused about GetRequest and SearchRequest

Hi all,

we will store searchable data into the _source field. So there isn't stored
a classic known document like pdf or so. Additionally we will store the
database primary key in the _scource field like this:

_source{ "searchfield1":"value1","searchfield2":"value2","dbkey":"4711"}

If we'll get the dbkeys from ES search by a query to process some other
stuff, is it the preferred method to do the following process:

  1. send a CountRequest to get the "count" of the searchquery,
  2. after this send a SearchRequest with the same query and with
    SearchType.SCAN and setSize(count) to receive the ids,
  3. then send a GetRequest in a id based for-loop to get all documents
    (_source fields) to receive the dbkey field

I think there must be another approach. Can you help me?

some code for better understanding:

CountResponse countResp = esClient.prepareCount(index).setTypes(types)
int total = ((Long) countResp.getCount()).intValue();

SearchResponse searchResponse =

for (SearchHit hit : searchResponse.getHits().getHits()) {
GetRequest getRequest = new GetRequest(index, hit.getType(), hit.getId());
GetResponse getResponse = esClient.get(getRequest).actionGet();

if (!hit.isSourceEmpty()) {
DataReference dataReference = (DataReference)

Best regards and many thanks in advance

You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit