NEST版本:2.4.1
ES版本:2.4.1
1 C# 自定义分析器和映射字段的代码如下:
2 在ES的config目录下创建了analysis\synonym.txt文件.
在执行生成索引的时候,提示错误日志:
MapperParsingException[Failed to parse mapping [mp]: analyzer [myik_syno] not found for field [description]]; nested: MapperParsingException[analyzer [myik_syno] not found for field [description]];
ES版本:2.4.1
1 C# 自定义分析器和映射字段的代码如下:
var descriptor = new CreateIndexDescriptor(DefaultIndex)
.Settings(s => s
.Analysis(a => a
.TokenFilters(tf => tf
.Synonym("my_synonym_filter", stf => stf
.SynonymsPath("analysis/synonym.txt")
.Tokenizer("whitespace")
)
)
.Analyzers(an => an.Custom("myik_syno", ca => ca
.Tokenizer("ik")
.Filters("my_synonym_filter")
)
)
.Analyzers(an => an.Custom("myik_smart_syno", ca => ca
.Tokenizer("ik_smart")
.Filters("my_synonym_filter")
)
)
)
)
.Mappings(m => m.Map<MpMappingInfo>(tm => tm.AutoMap()
.Properties(ps => ps
.Number(p => p.Name(n => n.Id))
.Number(p => p.Name(n => n.MPType))
.Boolean(p => p.Name(n => n.NeedPay))
.Number(p => p.Name(n => n.UserId))
.String(p => p.Name(n => n.TrueName).Analyzer("ik"))
.String(p => p.Name(n => n.ImageUrl).NotAnalyzed())
.String(p => p.Name(n => n.Organization).Analyzer("ik"))
.String(p => p.Name(n => n.Introduction).Analyzer("myik_syno"))
.Number(p => p.Name(n => n.ChannelId))
.String(p => p.Name(n => n.DeptName).Analyzer("ik"))
.String(p => p.Name(n => n.PositionalTitle).NotAnalyzed())
.String(p => p.Name(n => n.Description).Analyzer("myik_syno"))
.String(p => p.Name(n => n.ChannelIdList).NotAnalyzed())
.String(p => p.Name(n => n.ChannelNameList).Analyzer("myik_syno"))
.Date(p => p.Name(n => n.CreateTime))
.GeoPoint(p => p.Name(n => n.Location).LatLon(true))
)
)
);
var indexResponse = config.Client.CreateIndex(descriptor);
2 在ES的config目录下创建了analysis\synonym.txt文件.
在执行生成索引的时候,提示错误日志:
MapperParsingException[Failed to parse mapping [mp]: analyzer [myik_syno] not found for field [description]]; nested: MapperParsingException[analyzer [myik_syno] not found for field [description]];
2 个回复
gouhan
赞同来自: medcl
要定义多个,需要在Analyzers里面,通过Custom多次定义
kennywu76 - Wood
赞同来自: