"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