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": {}
}
}
}
Is it possible to do this with Nest? Am I doing something wrong?
Each highlighted field needs a separate ".OnField".
.Highlight(h => h
.PreTags("<b>")
.PostTags("</b>")
.OnFields(
f => f.OnField("Title"),
f => f.OnField("Summary")
)
)
See another example here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With