【问题标题】:ElasticSearch/NEST: Determine if Mapping already existsElasticSearch/NEST:确定映射是否已经存在
【发布时间】:2016-06-21 11:57:51
【问题描述】:

我正在使用 NEST client 访问我的 ElasticSearch 索引/映射。我正在尝试确定映射是否已经存在,如果不存在则创建一个新映射。 IndexExistsAsync() 有一个方法,但似乎没有 MappingExistsAsync() 方法。 GetMappingAsync() 返回一个IGetMappingResponse,它有一个布尔值IsValid,我想我可以检查一下,但是如果映射不存在,调用GetMappingAsync() 只会抛出一个异常。我可以检查是否抛出异常并创建映射,但有没有更好的处理方法?

【问题讨论】:

    标签: c# elasticsearch mapping nest


    【解决方案1】:

    我想通了。问题是我已将客户端设置为在失败时抛出异常,而不是让 IsValid 决定成功。

    var connectionPool = new SingleNodeConnectionPool(node);
    var settings = new ConnectionSettings(connectionPool)
        .BasicAuthentication(username, password)
        .DisableDirectStreaming()
        .PrettyJson();
        //.ThrowExceptions(); <-- This line had to be commented out.
    

    【讨论】:

      【解决方案2】:

      你不应该使用

      TypeExists defined on the interface IElasticClient
      

      相反?

      我的意思是如果类型存在,那么该类型的映射也存在。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-29
        • 2015-04-29
        • 1970-01-01
        • 2017-08-08
        • 2011-05-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多