【问题标题】:How to remove default mapping of index without deleting its data of elasticsearch如何在不删除elasticsearch数据的情况下删除索引的默认映射
【发布时间】:2015-05-13 14:55:36
【问题描述】:

我在 Couch-base 中有一些文档,其中一些字段值中有空格(“例如,“纽约”)。 我无法使用术语查询将其搜索为完全匹配。 我发现要搜索有空格的字段值需要一些映射,例如 - index : not_analysed

我也这样做了

但是当我从沙发底座到弹性搜索进行 XDCR 时。沙发底座本身会创建默认映射。因此我没有得到正确的结果。

那么,有什么方法可以删除默认映射而不删除其数据?

【问题讨论】:

    标签: c#-4.0 elasticsearch couchbase nest


    【解决方案1】:

    请参考以下代码。 我已经使用动态模板创建并映射了索引,然后做了 XDCR。 现在所有的字符串字段都不会被分析。

     IIndicesOperationResponse result = null;
                        if (!objElasticClient.IndexExists(elastic_indexname).Exists)
                        {
                            result = objElasticClient.CreateIndex(elastic_indexname, c => c.AddMapping<dynamic>(m => m.Type("_default_").DynamicTemplates(t => t
                                                        .Add(f => f.Name("string_fields").Match("*").MatchMappingType("string").Mapping(ma => ma
                                                            .String(s => s.Index(FieldIndexOption.NotAnalyzed)))))));
                }
    

    【讨论】:

      【解决方案2】:

      从技术上讲,您可以更改映射(查看映射 API),但实际上我发现它或多或少是不可能的,因为与现有映射存在冲突。

      所以:

      1) 在索引任何数据之前创建映射 2) 应用这篇博文中的一些想法:https://www.elastic.co/blog/changing-mapping-with-zero-downtime

      【讨论】:

        【解决方案3】:

        我有解决办法 在这里,我使用动态模板创建和映射索引,然后执行 XDCR。现在所有字符串字段都不会被分析。它对我有用。

        IIndicesOperationResponse result = null;
                            if (!objElasticClient.IndexExists(elastic_indexname).Exists)
                            {
                                result = objElasticClient.CreateIndex(elastic_indexname, c => c.AddMapping<dynamic>(m => m.Type("_default_").DynamicTemplates(t => t
                                                            .Add(f => f.Name("string_fields").Match("*").MatchMappingType("string").Mapping(ma => ma
                                                                .String(s => s.Index(FieldIndexOption.NotAnalyzed)))))));
                        }
        

        谢谢

        穆克什·拉古万希

        【讨论】:

          猜你喜欢
          • 2016-05-22
          • 1970-01-01
          • 2018-01-06
          • 1970-01-01
          • 1970-01-01
          • 2019-06-05
          • 2015-01-13
          • 1970-01-01
          • 2012-08-21
          相关资源
          最近更新 更多