首页 > 解决方案 > ElasticSearch:结果窗口太大

问题描述

我的朋友在 Elastic Search 云上存储了 65000 个文档,我想检索所有文档(使用 python)。但是,当我运行我当前的脚本时,有一个错误提示:

RequestError(400, 'search_phase_execution_exception', 'Result window is too large, from + size must be less than or equal to: [10000] but was [30000]. 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.') 

我的剧本

 es = Elasticsearch(cloud_id=cloud_id, http_auth=(username, password))
 docs =  es.search(body={"query": {"match_all": {}}, '_source': ["_id"], 'size': 65000})

检索所有这些文档而不是将其限制为 10000 个文档的最简单方法是什么?谢谢

标签: elasticsearch

解决方案


您应该使用滚动 API 并在不同的调用中获取结果。滚动 API 将最多返回 10000 乘以 10000 的结果(在您在调用中指定的时间内可以查阅),然后您将能够对结果进行分页并通过 scroll_id 获取它们。


推荐阅读