Text highlighting marks portions of returned search text that match the query, helping users scan results quickly. Add a highlight object beside the top-level query and name the fields to emphasize. section 2.3.6 section 8.8.2
A movie search suppresses the original source, searches the title with a term query, and returns matching title text inside a highlight field. section 8.8.2
Configure highlighting around the query:
- Place "highlight" at the same level as "query". section 2.3.6
- List one or more target fields inside "highlight.fields"; each field can use default settings. section 8.8.2
- Expect highlighted fragments under each hit's "highlight" property, commonly wrapped in <em> tags. section 2.3.6 section 8.8.2
- Replace the default tags with custom pre_tags and post_tags when the client needs another marker, such as {{ and }}. section 8.8.2
Highlighting prefix matches
A prefix search for "Mar" in actors.original can return matches such as <em>Marlon Brando</em>, <em>Martin Balsam</em>, and <em>Mark Hamill</em>. Set "_source": false when only highlighted matches are needed. section 9.8.1
