如何检索弹性搜索索引中的所有文档(大小大于10000)



我正在尝试获取索引中的所有文档,我尝试了以下操作-

1( 首先获取记录的总数,然后设置/search?size=parameter-不起作用,因为size参数被限制为10000

2( 尝试通过多次调用进行分页,并使用参数"?size=1000&从=9000'-一直工作到'from'是<9000,但在它超过9000后,我再次得到这个大小限制错误-

"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"

那么,如何检索索引中的所有文档呢?我读到一些答案,建议使用滚动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份文件。另外请注意,这是一次通话,所以我不担心性能问题。

找到解决方案-滚动api是正确的方法-下面是它的工作原理-

在获取文档的第一次调用中,可以提供1000大小和滚动参数,滚动参数指定搜索上下文超时后的时间(以分钟为单位(。

POST /index/type/_search?scroll=1m
{
"size": 1000,
"query": {....
}
}

对于所有后续调用,我们可以使用第一次调用响应中返回的scroll_id来获取记录的嵌套块。

POST /_search/scroll 
{
"scroll" : "1m", 
"scroll_id" : "DnF1ZXJ5VGhIOLSJJKSVNNZZND344D123RRRBNMBBNNN===" 
}

最新更新