当ES数据量较大,使用分页查询超过10000条(1000页)时,出现如下错误:
Cannot execute jest action , response code : 500 , 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 [16630]. 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":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"data_hosp_v6","node":"AXEzIOAdT1Oj1mnBBz5_Ww","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [16630]. 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."}}]} , message : null
[http-nio-7024-exec-2] 11-09 09:58:19 ERROR 34826 ApiExceptionResolver - Cannot execute jest action , response code : 500 , 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 [16630]. 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":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"data_hosp_v6","node":"AXEzIOAdT1Oj1mnBBz5_Ww","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [16630]. 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."}}]} , message : null
com.github.vanroy.springdata.jest.exception.JestElasticsearchException: Cannot execute jest action , response code : 500 , 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 [16630]. 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":"dfs","grouped":true,"failed_shards":[{"shard":0,"index":"data_hosp_v6","node":"AXEzIOAdT1Oj1mnBBz5_Ww","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [16630]. 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."}}]} , message : null
解决问题的方法就在报告的错误中,原文:
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.
两种方式,1. 使用滚动API;2. 直接设置[index.max_result_window]参数。
这里用方法2解决:
curl -XPUT http://127.0.0.1:9200/my_index/_settings -d '{ "index" : { "max_result_window" : 500000}}'
my_index 更换为要修改默认参数值的索引,后面的数值也可以自己设置,比如数据量为两万多并且不会发生大的数量上的变化,可以把值设置为30000。
如果是在Kibana控制面板里面,则执行下面这段:
PUT my_index/_settings
{
"index":{
"max_result_window":500000
}
}
ElasticSearch实际上更适合作为一个搜索的引擎,像这种分页查询遍历查询,实际上不是非常合适的。并且数值设置过大,会对机器造成压力,可能造成内存溢出等错误。
如果满意,请打赏博主任意金额,感兴趣的在微信转账的时候,添加博主微信哦。 请下方留言吧,可与博主自由讨论哦。
支付宝 | 微信 |
---|---|