elasticsearch - 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 个文档的最简单方法是什么?谢谢
解决方案
您应该使用滚动 API 并在不同的调用中获取结果。滚动 API 将最多返回 10000 乘以 10000 的结果(在您在调用中指定的时间内可以查阅),然后您将能够对结果进行分页并通过 scroll_id 获取它们。
推荐阅读
- numerical-methods - 拉盖尔方法
- python - Scrapy 刮表数据
- javascript - 如果给定多个“案例”,我如何修改先前修改的变量而不是连接到它?
- python - Python; 原始列表在函数内发生变化
- python - pyqt QTabWidget setCornerWidget TopRightCorner
- c - 使用嵌套 for 循环使用 C 查找数字的二次幂
- windows - 有没有办法让 python 程序不可关闭?
- javascript - 使普通对象可迭代。(javascript)
- swift - 在 Swift 中多态地解码 KeyedDecodingContainer 的子对象
- javascript - 如何使用 Vega / Vega-lite 呈现类/组织/流/状态图/图表