demo地址:BulkAll
批量导入
实现目标:想要使用ElasticSearch的 .Net Api客户端NEST批量导入数据,并发异步高效的批量导入
NEST提供了BulkAll
不废话,上代码
const int size = 1000;
var tokenSource = new CancellationTokenSource();
var observableBulk = elasticClient.BulkAll(list, f => f
.MaxDegreeOfParallelism(8)
.BackOffTime(TimeSpan.FromSeconds(10))
.BackOffRetries(2)
.Size(size)
.RefreshOnCompleted()
.Index(indexName)
.BufferToBulk((r, buffer) => r.IndexMany(buffer))
, tokenSource.Token);
var countdownEvent = new CountdownEvent(1);
Exception exception = null;
var bulkAllObserver = new Bu