im using elasticsearch within a C# project using the NEST API. i want to show the searched terms as highlights in the results page but dont know how i handle the display of them. All the docs tell me how to set up the highlight feature in the search query but i cannot find any help on how i make these highlights appear on the page of results...
Then i set my results to a variable that is the data for my repeater
var documents = result.Hits.Select(h => h.Source);
this.rptSearch.DataSource = documents;
this.rptSearch.DataBind();
this.rptSearch.Visible = true;
i dont see any of the terms highlighted in my results nor do i see the terms wrapped in the highlight tags...
i did notice on debug my results have a hits and a highlights array though the highlights value doesnt seem to show the complete text returned as i see in the hits.source...
ive seen that link and have that .highlight in the search query for the fields i want to use...
thats all done, what i cant see is how i get the highlighted words appearing in the text... they are not wrapped in the highlight tags...
the hits.source has the original text but the .highlights element has the highlighted snippet so i presume i need to do some sort of replace on the source text from the highlight text?
Highlighting's second job is snipping the text to the most "interesting" parts. If you just want the whole text back with the highlights there then set fragment_size to something large - 10k or something.
Highlighting works fine without making any changes to the index but you can make changes to the index to make highlighting faster - its all on the highlightings docs.
That is the trouble - I don't know the client so I can't explain it. If you go from the client to curl I could be more helpful.
The default for the highlighter is to highlight fields using only terms from the query that were explicitly targeted at those fields (so a search for forename:mark won't highlight any "mark" tokens found in a surname field).
i can see the highlights when i step through with debug... these are set against just one field in my index...
im currently getting the results into my page by loading them from the source which is getting both the title and body fields returned from the search
var documents = result.Hits.Select(h => h.Source);
but if there are highlights for the hit i want the body field to be the highlight value. i can grab the highlight value but am unable to overwrite the body content or know how to populate the body field with the highlight and keep the other fields as they were....
thanks i get this working now to the extent that the contentbody has the new highlight snippet at this point and i see it in the source fields when the documents variable is assigned.
however i do not see the highlights in the page and view source reveals the pre and post tags are not there so need to find out why.
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.