elasticsearch - 如何使用偏移+限制> 1000的ES查询
问题描述
我为我的客户端公开了一个 API,我使用 ES 来获取特定时间范围的数据。这个数字是记录远远超过 100 万。现在,我必须提供另一个功能,我给他们偏移量和限制,客户端可以从偏移量中获取记录数(限制)。
我的 ES 查询形成如下
{"from":10000,"size":2001,"timeout":"60s","query":{"bool":{"must":[{"terms":{"tollId":["59850"],"boost":1.0}},{"range":{"updatedAt":{"from":"2020-08-15T00:00:00.000Z","to":null,"include_lower":true,"include_upper":true,"boost":1.0}}},{"range":{"updatedAt":{"from":null,"to":"2020-12-15T22:08:21.000Z","include_lower":true,"include_upper":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"sort":[{"updatedAt":{"order":"desc"}}]}
当我在 Elastic Search 上执行此操作时,我得到
"failed_shards": [
{
"shard": 0,
"index": "companydatabase",
"node": "vQU6NjSVRK6dKNLsWkfqEw",
"reason": {
"type": "query_phase_execution_exception",
"reason": "Result window is too large, from + size must be less than or equal to: [10000] but was [12001]. 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."
}
解决方案是使用 Scroll API 来获取记录,但是当我必须从某个偏移量到某个限制获取记录时,我不能使用 scroll Api。
我错过了什么吗?有没有办法解决这个问题,或者我每次都必须获取所有记录(文档)并过滤结果?
解决方案
推荐阅读
- c++ - 铸造 Derived** → Base** 错了吗?有什么选择?
- node.js - Vscode API:读取剪贴板文本内容
- c# - PreFlight Request 404 not found .net web api;对预检请求的响应未通过访问控制检查:它没有 http ok 状态
- c# - 单击工具条时停止显示类型光标
- sql - 在每个主键的指定打开和关闭日期之间为多个主键创建日期表
- python - Disqus 在设置了唯一 page.url 和 page.id 的所有页面上显示相同的评论
- ios - 为什么 iPhone XR、XS 和 XS Max 没有将环境图像应用到 ARKit 中的场景?
- c - 如何在定义的位置附加一个字符
- django - Django Rest Framework:使用 url slug 查找模型实例,而不是 pk(lookup_field,retrievemodelmixin)
- python - 如何在 python shell 中激活虚拟环境