定义应该在哪个节点上创建多个节点的索引

js4nwp54  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(346)

这是我的连接文件

this IServiceCollection services, IConfiguration configuration)
        {
            var  EsNode = configuration["elasticsearch:AcqDataUrl"];

            var NCTNode = configuration["elasticsearch:NCTDataUrl"];

            var nodes = new Uri[]
                {
                    new Uri(EsNode),
                    new Uri(NCTNode)
                };

            var pool = new StaticConnectionPool(nodes);
            var connection = new ConnectionSettings(pool).DisableDirectStreaming();
            EsClient = new ElasticClient(connection);

            var settings = new IndexSettings { NumberOfReplicas = 1, NumberOfShards = 2 };

            var indexConfig = new IndexState
            {
                Settings = settings
            };

在这里,我想定义应该在哪个节点上创建索引,即它在第一个节点上创建索引的多个节点之间的节点[0]或节点[1]

{
               EsClient.Indices.Create(configuration["elasticsearch:AcquiringIndex"], c => c
                 .InitializeUsing(indexConfig)
                 .Mappings(m => m.Map<Acquirer>(mp => mp.AutoMap())));

           }
           if (!EsClient.Indices.Exists(configuration["elasticsearch:ElasticR&DIndex"]).Exists)
           {
               EsClient.Indices.Create(configuration["elasticsearch:ElasticR&DIndex"], c => c
                 .InitializeUsing(indexConfig)
                 .Mappings(m => m.Map<Employee>(mp => mp.AutoMap())));

           }
           if (!EsClient.Indices.Exists(configuration["elasticsearch:NetConnectTransactionIndex"]).Exists)
           {
               EsClient.Indices.Create(configuration["elasticsearch:NetConnectTransactionIndex"], c => c
               .InitializeUsing(indexConfig)
               .Mappings(m => m.Map<TransactionDto>(mp => mp.AutoMap())));

           }

           services.AddSingleton<IElasticClient>(EsClient);

       }

我想从singleton开始传递这两个连接,并在startup.cs中调用它,因为它将在继承控制器的类中使用,以便进一步查询

holgip5t

holgip5t1#

如果创建了一个包含2个主碎片和1个副本的索引,并且有2个数据节点,则两个节点上都有碎片[0]和碎片[1](因为每个碎片有2个副本,而副本不能位于同一个节点上),接收create index api调用的节点与确定碎片的位置无关

相关问题