elasticsearch 如何检索elasticsearch索引中的所有文档(大小大于10000)
我正在尝试获取索引中的所有文档,我尝试了以下操作- 1) 首先获取记录总数,然后设置/_search?size=parameter-不起作用,因为size参数限制为10000 2) 通过多次调用尝试分页,并使用参数“?size=1000&from=9000” -工作到“从”小于9000,但超过9000后,我再次得到此尺寸限制错误-elasticsearch 如何检索elasticsearch索引中的所有文档(大小大于10000),elasticsearch,lucene,elasticsearch,Lucene,我正在尝试获取索引中的所有文档,我尝试了以下操作- 1) 首先获取记录总数,然后设置/_search?size=parameter-不起作用,因为size参数限制为10000 2) 通过多次调用尝试分页,并使用参数“?size=1000&from=9000” -工作到“从”小于9000,但超过9000后,我再次得到此尺寸限制错误- "Result window is too large, from + size must be less than or equal to: [10000] but
"Result window is too large, from + size must be less than or equal to: [10000] but was [100000]. 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甚至文档状态的答案-
"While a search request returns a single “page” of results, the scroll API can be used to retrieve large numbers of results (or even all results) from a single search request, in much the same way as you would use a cursor on a traditional database."
但我找不到任何示例查询,无法在单个请求中获取所有记录
我在索引中总共有388794个文档。
另外请注意,这是一次电话,因此我不担心性能问题。找到了解决方案-
Scroll api是实现这一点的正确方法-以下是它的工作原理-
在获取文档的第一个调用中,可以提供大小(比如1000)和滚动参数,指定搜索上下文超时的时间(以分钟为单位)
POST /index/type/_search?scroll=1m
{
"size": 1000,
"query": {....
}
}
对于所有后续调用,我们可以使用在第一次调用的响应中返回的scroll_id来获取嵌套的记录块
POST /_search/scroll
{
"scroll" : "1m",
"scroll_id" : "DnF1ZXJ5VGhIOLSJJKSVNNZZND344D123RRRBNMBBNNN==="
}