NEST(弹性搜索)在多个领域突出显示 [英] NEST (elasticsearch) Highlighting in multiple fields
本文介绍了NEST(弹性搜索)在多个领域突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用Nest成功获得了结果和亮点,但如果我包含两个搜索亮点的字段,那么它只使用最后一个在弹性搜索查询的构造中。例如以下
I have successfully obtained results and highlights using Nest but if I include two fields in which to search for highlights it only uses the last one in construction of the elasticsearch query. e.g. the following
.Query(qry => qry
.QueryString(qs => qs
.Query(qString)
)
)
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(f => f
.OnField("Title")
.OnField("Summary")
)
)
意味着我只收到摘要字段返回的亮点。如果我使用等效查询直接查询弹性搜索,我可以从两个字段中检索亮点。
例如
means that I only get highlights returned from the "Summary" field. If I query elasticsearch directly with the equivalent query I can retrieve highlights from both fields. e.g.
{
"query": {
"query_string": {
"query": "apple"
}
},
"highlight": {
"pre_tags": ["<b>"],
"post_tags": ["</b>"],
"fields": {
"Title": {},
"Summary": {}
}
}
}
可以用Nest做这个吗?我做错了吗?
Is it possible to do this with Nest? Am I doing something wrong?
推荐答案
每个突出显示的字段都需要一个单独的.OnField。
Each highlighted field needs a separate ".OnField".
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(
f => f.OnField("Title"),
f => f.OnField("Summary")
)
)
另请参见这里。
这篇关于NEST(弹性搜索)在多个领域突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文