import static org.elasticsearch.index.query.QueryBuilders.*;
QueryBuilder qb = termQuery("multi", "test");
SearchResponse scrollResp = client.prepareSearch(test)
.addSort(SortParseElement.DOC_FIELD_NAME, SortOrder.ASC)
.setScroll(new TimeValue(60000))
.setQuery(qb)
.setSize(100).execute().actionGet(); [b]//100 hits per shard will be returned for each scroll
[/b]//Scroll until no hits are returned
while (true) {
for (SearchHit hit : scrollResp.getHits().getHits()) {
//Handle the hit...
}
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();
//Break condition: No hits are returned
if (scrollResp.getHits().getHits().length == 0) {
break;
}
}
.setSize(100).execute().actionGet(); //100 hits per shard will be returned for each scroll
按照这句话的意思 返回的数量应该等于 shard count * size ,但我事件测试时,一直都是返回100 求解
1 个回复
God_lockin
赞同来自: redhat
这里说的是,从所有分片(N个)里每个拿100,然后按条件排序,然后按scroll的方式每次返回100给你,一共能scrollN次