Using Nest, how can I make sure the bulk update is completed? I seem to run in to race conditions in my tests now, so I presume that's the problem:
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
When the elasticClient.Bulk(bulkRequest)
call returns you know for sure that all bulk operations have been executed. However, since ES operates in near real-time, the underlying indexes might not have been refreshed yet, which might be the reason why you see race conditions in your test.
What you simply need to do is to specify the refresh=wait_for
parameter in your bulk call, so make sure that once it returns, everything has been executed AND everything has been refreshed.