执行批量操作时的索引动态设置

Index Dynamic Settings when performing bulk operation

我正在尝试找到一种方法来在执行 BulkAll 操作时为我的索引指定副本数,我知道如何在使用 CreateIndex 创建单个索引时执行此操作:

var createIndexResponse = client.CreateIndex("index-name", c => c
    // settings for the index
    .Settings(s => s
        .NumberOfReplicas(1)
    )

第二个参数包含 CreateIndexDescriptior,其中包含:

public CreateIndexDescriptor Settings(Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> selector);

我查看了 BulkIndexDescriptor 但找不到设置选项,那么在执行批量操作时如何指定副本数?

这是我当前的代码:

var bulkAllObservable = elasticClient.BulkAll(accessLogs, b => b
                  .Index(null)
                  .MaxDegreeOfParallelism(Environment.ProcessorCount)
                  .BackOffRetries(2)
                  .ContinueAfterDroppedDocuments(true)
                  .BufferToBulk((descriptor, buffer) =>
                  {
                      foreach (var al in buffer)
                      {
                          descriptor.Index<object>(bi => bi
                              .Document(al)
                              .Index($"my-log-{al.Properties.UserId}")
                              .Id($"{al.Properties.Id}")
                          );
                      }
                  })

我正在使用 Nest 7.10.0

假设您依赖于在索引不存在时创建的索引并且文档已编入索引,您可以使用 index templates 模板 创建索引时使用的设置

var client = new ElasticClient();

var putTemplateResponse = client.Indices.PutTemplate("my-log", t => t
    .IndexPatterns("my-log-*")
    .Settings(s => s
        .NumberOfReplicas(1)
    )
);

现在,当创建名称与索引模式 "my-log-*" 匹配的索引时,将创建一个副本。