场景

做分页查询,当分页达到一定量的时候,报如下错误:

Result window is too large, from + size must be less than or equal to: [10000] but was [78020]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.

原因分析

es对from + size的大小进行限制,必须小于等于10000。

解决方案

  • 在业务中限制分页大小,使from+size<=10000;
  • 动态更改索引设置,为max_result_window参数赋值足够大的值;
PUT index/_settings
{
  "index":{
    "max_result_window":100000000
  }
}

推荐使用第一种解决方案,因为es的优势在于搜索,不在于分页,对此做限制就是为不影响其性。就es的默认配置,假设每页10条记录,也有1000页,如果业务上实在不妥协,则使用第二种方案。

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐