Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行批量操作时索引动态设置_C#_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest - Fatal编程技术网 elasticsearch,nest,C#,elasticsearch,Nest" /> elasticsearch,nest,C#,elasticsearch,Nest" />

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

C# 执行批量操作时索引动态设置,c#,elasticsearch,nest,C#,elasticsearch,Nest,我正在试图找到一种方法来指定执行BulkAll操作时索引的副本数量,我知道在使用CreateIndex创建单个索引时如何执行此操作: var createIndexResponse = client.CreateIndex("index-name", c => c // settings for the index .Settings(s => s .NumberOfReplicas(1) ) 第二个参数包含CreateI

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

var createIndexResponse = client.CreateIndex("index-name", c => c
    // settings for the index
    .Settings(s => s
        .NumberOfReplicas(1)
    )
第二个参数包含CreateIndexDescriptor,其中包含:

public CreateIndexDescriptor Settings(Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> selector);
public CreateIndexDescriptor设置(函数选择器);
我查看了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}")
                          );
                      }
                  })
var bulkAllObservable=elasticClient.BulkAll(accessLogs,b=>b
.Index(空)
.MaxDegreeOfParallelism(Environment.ProcessorCount)
.退避重试次数(2)
.ContinueAfterDroppedDocuments(true)
.BufferToBulk((描述符,缓冲区)=>
{
foreach(缓冲区中的var al)
{
descriptor.Index(bi=>bi
.文件(al)
.Index($“我的日志-{al.Properties.UserId}”)
.Id($“{al.Properties.Id}”)
);
}
})

我使用的是Nest 7.10.0

假设您依赖的是创建的索引,而该索引不存在,并且文档已编入其中,则可以使用该模板设置创建索引时要使用的设置

var client=new ElasticClient();
var puttTemplateResponse=client.index.puttTemplate(“我的日志”,t=>t
.IndexPatterns(“我的日志-*”)
.Settings(s=>s
.副本数量(1)
)
);

现在,当创建一个名称与索引模式“my log-*”匹配的索引时,它将使用一个副本来创建。

谢谢@Russ,这正是我最终要做的,除了我在Kibana中做的。