请帮助我突出显示。不明白如何正确地做到这一点。 我有下一个搜索,需要突出显示查询结果 我也在使用Elasticsearch 2.3版本 我试图添加一些亮点部分,但它不适合我。非常感谢您的帮助!
public SearchResult<Post> Search(string query, int page, int pageSize)
{
var result = client.Search<Post>(x => x.Query(q => q
.MultiMatch(mp => mp
.Query(query)
.Fields(f => f
.Fields(f1 => f1.Title, f2 => f2.Body, f3 => f3.Tags))))
.Highlight(h =>h
.PreTags("<h3>")
.PostTags("</h3>")
.Fields(f =>f
.Field("f2=>f2.Body")
.Type(HighlighterType.Plain)
))
.Aggregations(a => a
.Terms("by_tags", t => t
.Field(f => f.Tags)
.Size(10)))
.From(page - 1)
.Size(pageSize));
return new SearchResult<Post>
{
Total = (int)result.Total,
Page = page,
Results = result.Documents,
ElapsedMilliseconds = result.Took,
AggregationsByTags = result.Aggs.Terms("by_tags").Buckets.ToDictionary(x => x.Key, y => y.DocCount.GetValueOrDefault(0))
};
}