我想用NEST实现全文搜索和标记化搜索,所以我想得到像这样的多字段:
"tweet": {
"properties": {
"message": {
"type": "string",
"store": true,
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
目前,我与NEST的映射是
[ElasticType(Name = "tweet")]
internal class Tweet
{
[ElasticProperty(Name = "message")]
public string Message { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我搜索了NEST和ElasticSearch.net上的文档但没有任何结果.
是否有任何选项可以自动在字段中获取原始字段,还是应该定义嵌套类并指定自己的原始字段(我更喜欢更简洁的方式)?
看看这个答案.
基本上,你可以做这样的事情:
client.CreatIndex("tweets", c => c
.AddMapping<Tweet>(m => m
.MapFromAttributes()
.Properties(props => props
.MultiField(mf => mf
.Name(t => t.Message)
.Fields(fs => fs
.String(s => s.Name(t => t.Message).Analyzer("standard"))
.String(s => s.Name(t => t.Message.Suffix("raw")).Index(FieldIndexOption.not_analyzed)))))));
Run Code Online (Sandbox Code Playgroud)