【问题标题】:Elasticsearch upgrade 2.3.1 Nest client Raw StringElasticsearch 升级 2.3.1 Nest 客户端 Raw String
【发布时间】:2016-07-27 00:49:18
【问题描述】:

在升级到弹性 2.3.1 时,我遇到了 .Net Nest 客户端的障碍。

在 Nest 1.0 中,我可以从文件中读取索引的设置,并在创建时使用原始字符串配置索引。有没有办法在 Nest 2.0 中实现类似的东西,还是我必须对包括分析部分在内的每个设置使用流利的 API?映射的同样问题。

巢 1.0

private bool CreateIndex(string index, FileInfo settingsFile)
{
    var settings = File.ReadAllText(settingsFile.FullName);

    IElasticsearchConnector _elastic
    var response = _elastic.Client.Raw.IndicesCreate(index, settings);

    if (!response.IsValid)
    {
        //Logging error
        return false
    }
    return true;
}

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    ElasticClient.Raw 已重命名为 ElasticClient.LowLevel

    这是您在 NEST 2.x 中编写请求的方式。

    _elastic.Client.LowLevel.IndicesCreate<object>(indexName, File.ReadAllText("index.json"));
    

    index.json 文件内容:

    {
        "settings" : {
            "index" : {
                "number_of_shards" : 1,
                "number_of_replicas" : 1
            },
            "analysis" : {
                "analyzer" : {
                    "analyzer-name" : {
                        "type" : "custom",
                        "tokenizer" : "keyword",
                        "filter" : "lowercase"
                    }
                }
            },
            "mappings" : {
                "employeeinfo" : {
                    "properties" : {
                        "age" : {
                            "type" : "long"
                        },
                        "experienceInYears" : {
                            "type" : "long"
                        },
                        "name" : {
                            "type" : "string",
                            "analyzer" : "analyzer-name"
                        }
                    }
                }
            }
        }
    }
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2020-12-22
      • 2015-02-19
      • 1970-01-01
      • 1970-01-01
      • 2013-03-31
      • 2020-10-27
      • 2012-09-23
      • 2014-10-14
      相关资源
      最近更新 更多