0%

elasticsearch中max_result_window有上限限制

场景

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

1
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参数赋值足够大的值;
    1
    2
    3
    4
    5
    6
    PUT index/_settings
    {
    "index":{
    "max_result_window":100000000
    }
    }

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