解決 Elasticsearch 超過 10000 條沒法查詢的問題

解決 Elasticsearch 超過 10000 條沒法查詢的問題

 


問題描述

分頁查詢場景,當查詢記錄數超過 10000 條時,會報錯。node

使用 Kibana 的 Dev Tools 工具查詢 從第 10001 條到 10010 條數據。api

查詢語句以下:less

GET alarm/_search { "from": 10000, "size": 10 }

 

查詢結果,截圖以下:elasticsearch

 

報錯信息以下:工具

{ "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 [10010]. 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": "alarm", "node": "hdLJanxRTbmF52eK6-FFgg", "reason": { "type": "query_phase_execution_exception", "reason": "Result window is too large, from + size must be less than or equal to: [10000] but was [10010]. 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 }

 


緣由分析

Elasticsearch 默認查詢結果最多展現前 10000 條數據。spa

 


解決方案

按照報錯信息裏的提示,能夠看到,經過設置 max_result_window 的值來調整顯示數據的大小:3d

This limit can be set by changing the [index.max_result_window] index level setting.

 

兩種方式能夠實現:code

【方式一】(修改完配置文件,須要重啓集羣中的 ES 服務)

修改Elasticsearch 集羣中的 配置文件 config/elasticsearch.ymlblog

在配置文件最後增長一行,以下:ci

max_result_window: 200000000

 

【方式二】(推薦)

具體操做命令,以下(好比,設置可查詢 200000000 條數據,其中 alarm 是index名稱):

PUT alarm/_settings { "max_result_window" : 200000000 } 

 

命令執行效果,截圖以下:

 

再次執行查詢語句,便可正常查詢,效果截圖以下:

相關文章
相關標籤/搜索