问题:在NEST批量API中使用指定批量操作“MaxRetry”或“Timeout”变量的位置?
当我执行以下批量操作时,程序在成功插入60K记录后停止。我在Elasticsearch.Net.Connection.RequestHandlers.RequestHandlerBase.cs中得到了一个MaxRetryException。 所以,我正在考虑增加MaxRetry数或Timeout秒来克服这个问题,我是否在正确的道路上?
var counter = 0;
var indexName = "SomeIndexName";
var indexType = "SomeType";
var routingString = "SomeRouting";
var bulkDescriptor = new BulkDescriptor();
while (await result.ReadAsync())
{
counter++;
var document = GetDocumentObject<T>(result);
var idString = GetID(result);
bulkDescriptor.Index<T>(op => op
.Routing(routingString)
.Index(indexName)
.Type(indexType)
.Id(idString)
.Document(document));
if (counter % 1000 == 0)
{
var bulkResponse = await client.BulkAsync(bulkDescriptor);
bulkDescriptor = new BulkDescriptor();
}
}
答案 0 :(得分:3)
我测试了,这就是我指定超时和&amp;的方法。最大重试次数:
var connectionSettings = new ConnectionSettings(_connectionPool)
.SetTimeout(1000*30) // 30 minutes timeout
.MaximumRetries(5); // 5 times retry
var client = new ElasticClient(connectionSettings);