Skip to content

Instantly share code, notes, and snippets.

@kimchy
Created August 10, 2010 17:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kimchy/517664 to your computer and use it in GitHub Desktop.
Save kimchy/517664 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