Example of how to use scrollAsync in a loop with High Level Rest Client

How do you use client.scrollAsync multiple times in a loop like below of Synchronous version of scroll:

while (searchHits != null && searchHits.length > 0) {
SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId);
scrollRequest.scroll(scroll);
searchResponse = client.scroll(scrollRequest, RequestOptions.DEFAULT);
scrollId = searchResponse.getScrollId();
searchHits = searchResponse.getHits().getHits();
}

In Asynchronous case, the searchResponse is received inside the scrollListener's onResponse but then I need to get the next scrollId from that, get the searchHits, set a new scrollRequest and do another client.scrollAsync.

Can you suggest an example?
I have looked into [No code for] Example of using scrollAsync with the java High Level Rest Client

I wonder why the returned Hits is not collected in that example.
I looked up other post regarding "scrollAsync" in this ES discussion forum and the .Net use of "scrollAsync" is simpler:

var scrollResponse = client.ScrollAsync(scrollsrequest).Result

One other thing to confirm is that I shouldn't use client.searchAsync if I am going to use client.scrollAsync correct? I am using scrollAsync to speed up retrieval of many documents records that needs to be paginated yes?

Thank you
-Indra

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.