es分页条数限制

  

"error": {
    "root_cause": [
      {
        "type": "query_phase_execution_exception",
        "reason": "Result window is too large, from + size must be less than or equal to: [1000000] but was [1000000099]. 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为10000,控制台输入以下指令修改

PUT /index/_settings
{ "index.max_result_window" :"1000000"}

 

经过测试,在match_all的情况下,当from值>20w的时候查询的速度将会超过1s(1核2g)

 

官方解释为

在集群系统中深度分页
为了理解为什么深度分页是有问题的,让我们假设在一个有5个主分片的索引中搜索。当我们请求结果的第一页(结果1到10)时,每个分片产生自己最顶端10个结果然后返回它们给请求节点(requesting node),它再排序这所有的50个结果以选出顶端的10个结果。
现在假设我们请求第1000页——结果10001到10010。工作方式都相同,不同的是每个分片都必须产生顶端的10010个结果。然后请求节点排序这50050个结果并丢弃50040个!
你可以看到在分布式系统中,排序结果的花费随着分页的深入而成倍增长。这也是为什么网络搜索引擎中任何语句不能返回多于1000个结果的原因。

 

推荐使用scroll来解决问题 

https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-request-scroll.html

posted @ 2020-04-13 17:08  MRLL  阅读(3276)  评论(0编辑  收藏  举报