一. 问题描述
开发环境: JDK1.8、Elasticsearch7.3.1、RestHighLevelClient
问题: 最近在通过Java客户端操作ES进行分页查询(from+size)时,分页获取满足条件的数据和总数。发现满足条件的数据总数一旦超过10000条,使用SearchResponse的getHits().getTotalHits().value返回的结果永远是10000。为什么会被限制只能搜索10000条数据呢?如何查询精确的数据总数呢?
Result window is too large, from + size must be less than or equal to:[10000] but was [10100]. See the scroll api for a more efficient way to requestlarge data sets. This limit can be set by changing the[index.max_result_window] index level parameter
Tips: 本文侧重点在如何精确的获取数据总数,如果想知道如何深度搜索,请参考我的另一篇博客 Elasticsearch from+size与scroll混合使用实现深度分页搜索
二. 问题分析
查看官方文档: Ela