[英]Using Nest for elasticsearch
嗨,我將Nest用作Elastisearch的接口。 一切正常,我只能做一件事。 這就是重點。
我有以下“模特”
[ElasticType(Name = "WebResource", SearchAnalyzer = "full_name", IndexAnalyzer = "partial_name", DateDetection = true, NumericDetection = true)]
public class WebResource
{
public string _id;
[ElasticProperty(Type = FieldType.integer_type, Index = FieldIndexOption.not_analyzed)]
public string Id
{
get
{
if (_id == null || _id == Guid.Empty.ToString())
{
_id = Guid.NewGuid().ToString();
}
return _id;
}
set
{
_id = value;
}
}
[ElasticProperty(Type = FieldType.string_type, Index = FieldIndexOption.analyzed)]
public string Keywords { get; set; }
[ElasticProperty(Type = FieldType.string_type, Index = FieldIndexOption.analyzed)]
public string Content { get; set; }
}
我有一個索引,搜索返回文檔,但突出顯示始終為零
Client.Search<WebResource>(g => g.Query(k => k.Term(l => l.Content, searchText) || k.Term(l => l.Keywords, searchText)).Highlight(k => k.OnFields(p => p.OnField("Keywords"), p => p.OnField("Content")).FragmentSize(200)));
其中searchText是searchtext。 任何幫助表示贊賞。
親切的問候
原來這個問題與NEST(elasticsearch)在多個領域的突出顯示有關
我的解決方案是將其分解為更具可讀性的形式
Action<HighlightFieldDescriptor<WebResource>> actWeb = (t) => t.OnField(g => g.Content);
Action<HighlightFieldDescriptor<WebResource>> actKey = (t) => t.OnField(g => g.Keywords);
Action<HighlightDescriptor<WebResource>> higDesc = t => t.OnFields(actWeb,actKey);
SearchDescriptor<WebResource> searchdesc = new SearchDescriptor<WebResource>();
searchdesc.Query( t => t.Term( k => k.Content,searchText) || t.Term( l =>l.Keywords,searchText));
searchdesc.Highlight(higDesc);
var resp = Client.Search(searchdesc);
事實證明,這是組合字段的方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.