Hi,
I am new to ES and am trying to set up a demo to evaluate if ES works for us as search application. In my demo, I can index and search content of a document eg MS Word or PDF successfully. But I did not manage get highlight work. Highlight field always return nothing even though results have been found.
Can I get some help please?
My environment:
ElasticSearch with attachment plugin
NEST client is used to talk to ES server (our application is based on .NET) :
I have created two VO : Attachment and Document
public class Attachment
{
[ElasticProperty(Name = "_content", Store = true)]
public string Content { get; set; }
[ElasticProperty(Name = "_content_type", Store = true),]
public string ContentType { get; set; }
[ElasticProperty(Name = "_name", Store = true)]
public string Name { get; set; }
}
[ElasticType(Name = "document")]
public class Document
{
public int Id { set; get; }
[ElasticProperty(Store = true)]
public string Title { set; get; }
[ElasticProperty(Type = FieldType.Attachment, TermVector = TermVectorOption.WithPositionsOffsets, Store = true)]
public Attachment File { set; get; }
}
The following methods are used to index and search content of a indexed MS word document:
private static void IndexWordDoc()
{
docElasticClient.CreateIndex(INDEX_NAME, c =>
c.AddMapping(m => m.MapFromAttributes().SearchAnalyzer("standard").IndexAnalyzer("standard")));
var attachment = new Attachment
{
Content = Convert.ToBase64String(File.ReadAllBytes(path)),
ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
Name = "SeachTest.docx"
};
var doc = new Document()
{
Id = 1,
Title = "SeachTest.docx(title)",
File = attachment
};
docElasticClient.Index(doc);
}
And search funciton is:
private static ISearchResponse searchMSWord(string term)
{
var query = Query.Term("file", term);
var searchResults = docElasticClient.Search(s => s
.From(0)
.Size(10)
.Query(query)
.Highlight(h=>h.OnFields(f=>f.OnField("file")))
);
return searchResults;
}
searchResults can resturn result(s) when I perform a search against indexed document. But Highlight field in the searchResults is always null.
Any idea which part I got it wrong? Thank you