ElasticSearch performs a good job on finding results also in large text documents. Thus, for searching text in very large blocks it's very useful, but to improve the user experience it is sometimes required to show the abstract part: a small portion of the text that has matched the query. The highlight functionality in ElasticSearch is designed to do this job.
You need a working ElasticSearch cluster and an index populated with the script available in online code.
For searching and highlighting the results, we need to perform the following steps:
From command line, we can execute a search with a
highlight
section as follows:curl -XGET 'http://127.0.0.1:9200/test-index/_search?from=0&size=10' -d ' { "query": {"query_string": {"query": "joe"}}, "highlight": { "pre_tags": ["<b>"], "fields": { "parsedtext": {"order": "score"}, "name": {"order": "score"}}, "post_tags": ["</b>"]}}'