【问题标题】: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)))))));
}
【解决方案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)))))));
}
谢谢
穆克什·拉古万希