我试图弄清楚如何使用NEST 2.3.2检索大量文档。由于响应中的文档数受到限制(由服务器管理员设置),因此我想使用Scroll来保证安全。
我读过this,但找不到使用NEST 2.3.2库来实现的方法。此documentation适用于1.x,不适用于2.x。
具体来说,当我尝试在SearchType = Elasticsearch.Net.SearchType.Scan
中设置SearchRequest
时,它将自动向/_search?search_type=scan
发送请求,并且服务器仅返回“search_phase_execution_exception”,因为“在扫描时必须提供滚动...”。但是我不知道如何获取滚动ID。
有谁知道如何实现这一目标?我想在合格的文档上滚动一些请求,直到全部检索出来。如果有人可以提供一些示例代码,那将非常有帮助。非常感谢你。
最佳答案
我针对这样的问题尝试了类似的方法,其中我需要将所有文档编入索引,然后进行一些处理。我使用滚动。您可以从here看我的问题
var scanResults = client.Search<IndexName>(s => s
.From(0)
.Size(20) //any size you can give
.MatchAll()
.Source(so => so
.Include(fi => fi.Field(fieldName))
.SearchType(Elasticsearch.Net.SearchType.Scan)
.Scroll("5m") //time for which the scrollId is saved. Can be anything.
);
var results = client.Scroll<IndexName>("10m", scanResults.ScrollId);
while (results.Documents.Any())
{
//do whatever you want to do from the resultant documents
results = client.Scroll<IndexName>("10m", results.ScrollId);
}
有关scroll的更多信息
希望这可以帮助。
关于.net - 使用NEST在Elasticsearch中检索未知数量的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959629/