如何使用NEST强类型指定字段



根据Elasticsearch的文档,我们应该指定我们的带状疱疹子字段,如本例所示:

GET my-index-000001/_search
{
"query": {
"multi_match": {
"query": "brown f",
"type": "bool_prefix",
"fields": [
"my_field",
"my_field._2gram",
"my_field._3gram"
]
}
}
}

如何使用Elasticsearch的官方客户端NEST强类型指定这些字段?

ISearchRequest Selector(SearchDescriptor<PointOfInterest> s)
{
return s
.Index(IndexName)
.Query(q => q
.MultiMatch(c => c
.Fields(f => f
.Field(p => p.MyField) // This one we can easily specify
.Field("my_field._2gram") // This one needs to be hard coded? Field(p => $"{p.MyField}._2gram")) doesn't work 
.Field("my_field._3gram"))
.Type(TextQueryType.BoolPrefix)
.Query(query.Query)));
}

Suffix扩展方法将帮助您使用此

ISearchRequest Selector(SearchDescriptor<PointOfInterest> s)
{
return s
.Index(IndexName)
.Query(q => q
.MultiMatch(c => c
.Fields(f => f
.Field(p => p.MyField)
.Field(p => p.MyField.Suffix("_2gram"))
.Field(p => p.MyField.Suffix("_3gram")))
.Type(TextQueryType.BoolPrefix)
.Query(query.Query)));
}

相关内容

  • 没有找到相关文章

最新更新