美文网首页
Result window is too large, from

Result window is too large, from

作者: __Bw__ | 来源:发表于2020-01-10 13:53 被阅读0次

    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千条匹配率高的记录完全能满足业务了,所以可以固定一个最大的页数。

    相关文章

      网友评论

          本文标题:Result window is too large, from

          本文链接:https://www.haomeiwen.com/subject/tnipactx.html