Creating an index Nest

后端 未结 5 1250
傲寒
傲寒 2020-12-19 03:01

How would I recreate the following index using Elasticsearch Nest API?

Here is the json for the index including the mapping:

{
    \"settings\": {
           


        
5条回答
  •  被撕碎了的回忆
    2020-12-19 03:21

    For 7.X plus you can use the following code to create an index with Shards, Replicas and with Automapping:

     if (!_elasticClient.Indices.Exists(_elasticClientIndexName).Exists)
            {
                var response = _elasticClient.Indices
                                .Create(_elasticClientIndexName, s => s
                                    .Settings(se => se
                                        .NumberOfReplicas(1)
                                        .NumberOfShards(shards)
                                        ).Map(
                                                    x => x.AutoMap().DateDetection(false)
                                                ));
    
    
    
                if (!response.IsValid)
                {
                    // Elasticsearch index status is invalid, log an exception
    
                }
            }
    

提交回复
热议问题