如何在Elasticsearch索引中检索所有大于10000的文档

我正在尝试将所有文​​档都添加到索引中,我尝试了以下操作-

1)首先获取记录总数,然后设置/ _search?size =参数-无效,因为size参数限制为10000

2)尝试通过多次调用进行分页,并使用了参数'?size = 1000&from = 9000' -直到'from'为

"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个文档。 另外请注意,这是一次通话,因此我不必担心性能问题。

mexiaoping 回答:如何在Elasticsearch索引中检索所有大于10000的文档

找出解决方案- 滚动api是执行此操作的正确方法-这是其工作方式-

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

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

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

POST /_search/scroll 
{
    "scroll" : "1m","scroll_id" : "DnF1ZXJ5VGhIOLSJJKSVNNZZND344D123RRRBNMBBNNN===" 
}
本文链接:https://www.f2er.com/3158888.html

大家都在问