使用Nest,我如何确保批量更新完成?我现在的测试中似乎遇到了竞态条件,所以我认为这就是问题所在:
var bulkRequest = new BulkRequest(ServiceIndexName)
{
Operations = new List<IBulkOperation>()
};
// adding a lot of items here
bulkRequest.Operations.Add(new BulkIndexOperation<MyItem>(item));
elasticClient.Bulk(bulkRequest);
// I want to make sure the operation is completed here
1条答案
按热度按时间vfh0ocws1#
当
elasticClient.Bulk(bulkRequest)
调用返回时,您可以确定所有批量操作都已执行。但是,由于ES操作in near real-time,因此基础索引可能尚未刷新,这可能是您在测试中看到争用条件的原因。您只需要在批量调用中调用specify the
refresh=wait_for
parameter,因此确保它返回后,所有内容都已执行,并且所有内容都已刷新。