Highlighting
/ Highlight, / SearchHighlighting #
Ask for matched fragments of your text fields back alongside each hit, with the matched terms wrapped in tags — ready to render as a search result list.
POST /my-collection/_search
How it works #
Highlighting is an engine-native enrich step that runs on the returned page
only — after ranking and truncation, exactly like
script
fields. It has two phases (lib/engine/src/search/highlight/):
1. Term extraction. The engine walks the query tree and collects
(field, term) pairs worth highlighting: term, terms, fuzzy,
span_term, intervals, match, multi_match, match_phrase, and
bool clauses. Text queries (match, multi_match, phrase) are
re-tokenized through the field’s search analyzer (or the query’s explicit
analyzer override), so the highlighted terms mirror what the query
scored. must_not clauses never contribute — documents excluded by them
get no tags from them. match_all, range, geo and
vector queries carry nothing to highlight.