问题:在哪里可以指定NEST批量API中使用的批量操作“MaxRetry”或“Timeout”变量?

当我执行以下批量操作时,程序将在成功插入60K记录后停止。我在Elasticsearch.Net.Connection.RequestHandlers.RequestHandlerBase.cs中得到了MaxRetryException。
因此,我正在考虑增加MaxRetry数或超时秒数来解决此问题,我走的路正确吗?

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();
      }

}

最佳答案

我测试了,这就是我指定超时和最大重试次数的方式:

var connectionSettings = new ConnectionSettings(_connectionPool)
    .SetTimeout(1000*30)  // 30 minutes timeout
    .MaximumRetries(5);   // 5 times retry
var client = new ElasticClient(connectionSettings);

关于nest - 在Elasticsearch/Nest Bulk API中的哪里指定 “MaxRetry”和 “Timeout”变量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29805385/

10-11 07:48