【发布时间】:2017-02-07 17:40:04
【问题描述】:
我试图了解为什么 elasticsearch.net NEST 滚动调用不断返回相同的结果。我的 C# 应用程序中有一个外部循环,用于跟踪当前页面,它与批处理大小一起传入。我已经简化了代码:
List<int> ids = GetIds();
int count = _batchSize;
int currentPage = 0;
while (count == _batchSize)
{
var results = Execute(client => client.Search<Invoice>(s => s
.Index(indexName)
.Query(q => q
.Terms(n => n
.Field(f => f.Items.FirstOrDefault().MyInformation.FirstOrDefault().ItemID)
.Terms(ids)))
.Size(batchSize)
.From(currentPage * batchSize)
.Scroll("1m")
));
DoSomethingWithResults();
count = results.Count();
currentPage++;
}
在上面的调用中,id 列表是嵌套元素的 id,与它们所包含的对象存在一对多关系。这就是我想使用滚动的原因,因为我不知道将返回多少 Invoice 对象。每次调用 currentPage 时,都会增加 1。我曾假设将返回滚动中的下一批。
我认为我做错了什么,因为我认为这更像是一个分页流程。
【问题讨论】:
标签: .net elasticsearch scroll nest