Skip to content

Instantly share code, notes, and snippets.

@djodjoni
Forked from kimchy/gist:517664
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djodjoni/1ecb3a17c9b89a657ad0 to your computer and use it in GitHub Desktop.
Save djodjoni/1ecb3a17c9b89a657ad0 to your computer and use it in GitHub Desktop.
SearchResponse searchResponse = client.prepareSearch()
.setQuery(matchAllQuery())
.setSize(35)
.setScroll(TimeValue.timeValueMinutes(2))
.addSort("field", SortOrder.ASC)
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(100l));
assertThat(searchResponse.hits().hits().length, equalTo(35));
searchResponse = client.prepareSearchScroll(searchResponse.scrollId())
.setScroll(TimeValue.timeValueMinutes(2))
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(100l));
assertThat(searchResponse.hits().hits().length, equalTo(35));
for (SearchHit hit : searchResponse.hits()) {
assertThat(((Number) hit.sortValues()[0]).longValue(), equalTo(counter++));
}
searchResponse = client.prepareSearchScroll(searchResponse.scrollId())
.setScroll(TimeValue.timeValueMinutes(2))
.execute().actionGet();
assertThat(searchResponse.hits().getTotalHits(), equalTo(100l));
assertThat(searchResponse.hits().hits().length, equalTo(30));
for (SearchHit hit : searchResponse.hits()) {
assertThat(((Number) hit.sortValues()[0]).longValue(), equalTo(counter++));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment