具体报错如下
{Type: search_phase_execution_exception Reason: "all shards failed" CausedBy: "Type: illegal_argument_exception Reason: "Result window is too large, from + size must be less than or equal to: [10000] but was [16000]. 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." CausedBy: "Type: illegal_argument_exception Reason: "Result window is too large, from + size must be less than or equal to: [10000] but was [16000]. 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."""}
根据ElasticSearch: Result window is too large,有三种解决方案:
1.设置index的max_result_window
http://你的ES IP地址:9200/index名称/_settings
PUT
Body:
{
"max_result_window": "10000000"
}
返回结果
{
"acknowledged": true
}
2.使用Scroll API(官方不推荐)
类似游标
第一次查询带上?scroll=1m
http://127.0.0.1:9200/indexName/_search?scroll=1m
POST
{
"size": 100,
查询条件
}
返回结果
{
"_scroll_id": "FGluY2x1ZGVfY29udGV4dF91dWlkDXF1ZXJ5QW5kRmV0Y2gBFkJnSGFwelc1UXg2RkR0amFINVdvYncAAAAAAAB2vRY2enRNYVU4QVN6Q3ZHZG1hWnNMVmtB",
其他数据
}
之后调用/_search/scroll
接口,每次带上查询返回的_scroll_id
进行查询
http://127.0.0.1:9200/_search/scroll/获得的_scroll_id?scroll=1m
GET
返回结果
{
"_scroll_id": "FGluY2x1ZGVfY29udGV4dF91dWlkDXF1ZXJ5QW5kRmV0Y2gBFkJnSGFwelc1UXg2RkR0amFINVdvYncAAAAAAAB2zBY2enRNYVU4QVN6Q3ZHZG1hWnNMVmtB",
分页的数据集合
}
根据Scroll API,不同版本的ES Scroll API使用略有不同,可以根据版本查阅
参考资料
Paginate search results
Scroll API