解决 Elasticsearch 超过 10000 条无法查询的问题
解决 Elasticsearch 超过 10000 条无法查询的问题
问题描述
分页查询场景,当查询记录数超过 10000 条时,会报错。
使用 Kibana 的 Dev Tools 工具查询 从第 10001 条到 10010 条数据。
查询语句如下:
GET alarm/_search { "from": 10000, "size": 10 }
查询结果,截图如下:
报错信息如下:
{ "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 条数据。
解决方案
按照报错信息里的提示,可以看到,通过设置 max_result_window 的值来调整显示数据的大小:
This limit can be set by changing the [index.max_result_window] index level setting.
两种方式可以实现:
【方式一】(修改完配置文件,需要重启集群中的 ES 服务)
修改Elasticsearch 集群中的 配置文件 config/elasticsearch.yml
在配置文件最后增加一行,如下:
max_result_window: 200000000
【方式二】(推荐)
具体操作命令,如下(比如,设置可查询 200000000 条数据,其中 alarm 是index名称):
PUT alarm/_settings { "max_result_window" : 200000000 }
命令执行效果,截图如下:
再次执行查询语句,即可正常查询,效果截图如下:
分类:
Elasticsearch
标签:
Elasticsearch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)