我有一个这样的循环......
while (true) {
scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(600000)).execute().actionGet();
for (SearchHit hit : scrollResp.getHits()){
// does this when totalHits > scrollSize, skips it otherwise
}
//Break condition: No hits are returned
if (scrollResp.hits().hits().length == 0) {
break;
}
}
查询的 scrollSize 设置为 500。当 scrollResp.getHits().totalHits() < 500 时,永远不会进入 for 循环。如果我将 scrollSize 修改为 < totalHits,则将进入 for 循环。
一般来说,我期望每个查询有 > 500 个结果,但我需要它在任何一种情况下都能正常工作。不确定我是否可能错误地尝试迭代或什么。反馈表示赞赏。