Hi all,
I am running an ES 5.5.0 implementation and use the NEST api in a custom .NET app.
I am able to get correct highlight results while using exact word search. But after activating the full lucene query the highlight function returns no results.
Simply put, how do I get back the correct highlight response to lucene queries (using AND/OR, field : value combinations etc) using NEST ?? which function do I use ?
I am using an index created by fscrawler. Now, if I pass a search string, say "boat AND race AND file.extension : pdf" "boat NOT race" the highlight function doesn't return anything.
The search results work fine though.
Ideally, I would like it to behave like it does in kibana, highlight terms like boat & race in the first case, only boat in the second case while ignoring AND, file.extension and such terms.
IOW, the highlight option works if I search inside a specific field, but if I am using lucene query any field in the index might be called. and in that case the highlight function doesn't return any hits.
I think you may need to include the highlight_query in the highlighting; the highlight_query in this case would simply be the same as the search query.
When using the query_string query in 5.5 without specifying any fields, you'll be running the query against the _all field, but higlighting is configured to run against the "content" field, so you need to indicate what query to run against this field for highlighting.
It would look something like the following (adapt to your data):
var response = client.Search<Question>(s => s
.From(0)
.Size(20)
.Type("doc")
.Query(q => q
.QueryString(qs => qs
.Query("text to search")
)
)
.Highlight(h => h
.PreTags("<tag>")
.PostTags("</tag>")
.Fields(fs => fs
.Field(f => f.Body)
.HighlightQuery(hq => hq
// repeat the search query here
.QueryString(qs => qs
.Query("text to search")
)
)
)
.NumberOfFragments(1)
.FragmentSize(200)
)
);
Note that it's possible that this does not highlight anything, if the documents that match the search query don't match for the highlight query in the target field i.e. "text to search" might be a match for a document in the "_all" field with a value that has originated from the "Title" field but not the "Body" field, so a highlight on "Body" field won't have anything to highlight.
thanks. I think I am having the exact problem you warned of. How does kibana handle this ?
Because, as far as I can understand this feature works fine there, IOW it is able to highlight successfully without needing the field to be declared explicitly in the query.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.