String scrollId = searchResponse.getScrollId();
int scrollRequestCounter = 0;
long sumTimeSpent = 0;
while (true) {
long timeSpent = System.currentTimeMillis();
searchResponse = client.prepareSearchScroll(scrollId).setScroll("10m").get();
sumTimeSpent += (System.currentTimeMillis() - timeSpent);
scrollRequestCounter++;
if (searchResponse.getHits().getTotalHits() != numDocs) {
System.err.printf(Locale.ENGLISH, "Expected total hits [%d] but got [%d]\n", numDocs, searchResponse.getHits().getTotalHits());
}