Result window is too large, from + size must be less than or equal to: [10000] but was [*]

Elasticsearch 使用 from + size 分页查询数据时出现异常如下

{
    "error": {
        "root_cause": [{
            "type": "query_phase_execution_exception",
            "reason": "Result window is too large, from + size must be less than or equal to: [10000] but was [307440]. 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."
        }],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [{
            "shard": 0,
            "index": "",
            "node": "",
            "reason": {
                "type": "query_phase_execution_exception",
                "reason": "Result window is too large, from + size must be less than or equal to: [10000] but was [307440]. 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."
            }
        }]
    },
    "status": 500
}

解决办法在异常信息里已经说明清楚了,需要调整索引的配置项index.max_result_window,调整到数值为需要的大小

PUT index_name/_settings
{
  "index.max_result_window":10000000
}

注:from + size 浅分页只适合少量数据, 因为随着 from 增大,查询的时间就会越大;而且数据越大,查询的效率指数下降。正常搜索返回前1千条匹配率高的记录完全能满足业务了,所以可以固定一个最大的页数。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。