# Confused about GetRequest and SearchRequest

**URL:** <https://discuss.elastic.co/t/confused-about-getrequest-and-searchrequest/13992>\
**Category:** Elasticsearch\
**Created:** [October 17, 2013, 3:25pm UTC](https://discuss.elastic.co/t/confused-about-getrequest-and-searchrequest/13992 "2013-10-17T15:25:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Kley](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@Alexander\_Kley](https://discuss.elastic.co/u/Alexander_Kley)\
**Post date:** [October 17, 2013, 3:25pm UTC](https://discuss.elastic.co/t/confused-about-getrequest-and-searchrequest/13992/1 "2013-10-17T15:25:24Z")

</div>

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)  
.setQuery(QueryBuilders.queryString(luceneNativeQuery)).execute().actionGet();  
int total = ((Long) countResp.getCount()).intValue();

SearchResponse searchResponse =  
esClient.prepareSearch(index).setTypes(types).setQuery(QueryBuilders.queryString(luceneNativeQuery)).setSize(total).setSearchType(SearchType.SCAN).execute().actionGet();

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)  
hit.getSource().get(DATA\_REFERENCE);  
searchResults.add(dataReference);  
}  
}  
....

Best regards and many thanks in advance  
Alex

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:11am UTC](https://discuss.elastic.co/t/confused-about-getrequest-and-searchrequest/13992/2 "2017-07-06T02:11:54Z")

</div>


