ElasticSearch查詢超過10000條報錯Result window is too large
阿新 • • 發佈:2020-07-22
背景
後臺查詢訂單列表,將mysql查詢改造為es查詢.分頁展示,每頁10條資料,當查詢頁數超過1000頁時,發現後臺es報錯,報錯資訊為:
(’Result window is too large, from + size must be less than or equal to: [10000] but was [10100]. 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 parameter.’)
分析
分析報錯資訊,明顯提示結果視窗集太大了,條數不應該超過10000條.這是因為ElasticSearch預設查詢10000條展示(官網有說明),當超過10000條時,就會報錯
解決方式
可以通過elasticsearch-head外掛解決
1.關閉索引庫
2.點選複合查詢
3.執行PUT語法(這裡數值修改為足夠大)
4.檢視返回結果(true代表成功)
5.開啟索引庫
注意:執行PUT語法時可能會報錯 :
Content-Type header [application/x-www-form-urlencoded] is not supported
解決方法如下:
修改head外掛目錄下的vendor.js檔案的6886行和7573行
將application/x-www-form-urlencoded 替換為 application/json;charset=UTF-8
再次執行PUT語句即可