<!-- llms-explorer concept facts · https://llms-explorer.com/tree/search-highlighting/ · pack 2026-10-24 · ~1258 tokens -->

# Search Highlighting

> Source-anchored research for Search Highlighting. Run status: COMPLETED.

Parent: [MongoDB Atlas Search](https://llms-explorer.com/tree/mongodb-atlas-search/) · 5 facets · 17 facts · page: https://llms-explorer.com/tree/search-highlighting/

## Structure and components

- Each highlight contains a field path, a relevance score, and texts segments whose value is original text and whose type distinguishes hit from adjacent text. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)

## How-to and procedures

- Configure highlight beside the search operator within $search, then expose the metadata with a projection such as highlights: { $meta: 'searchHighlights' }; highlights are not stored fields in the original document. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)

## Problems, failure modes and limitations

- A matching document can have an empty highlights array if the match lies beyond maxCharsToExamine; the same limit can truncate returned context. (low confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- The highlighting documentation explicitly excludes use with the embeddedDocument operator; its introductory statement about use with search operators must be read subject to that limitation. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)

## Comparisons and alternatives

- To highlight an autocomplete-indexed path, autocomplete must be the only operator using that path in the query. Autocomplete highlight spans can be coarser than the query terms rather than marking only the typed prefix. (medium confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- The frontend can render hit segments with a mark element and preserve ordinary segments as text. Tidewave recommends building elements from these pieces instead of inserting raw HTML strings. (medium confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)

## Facts and statements

- Render the returned segments in the application; the OneUptime example escapes values before wrapping hits in HTML mark tags. (low confidence) — [source](https://oneuptime.com/blog/post/2026-03-31-mongodb-atlas-search-highlight/view)
- For ordinary string-field highlighting, MongoDB documents a string search mapping with indexOptions set to offsets, the default. Its autocomplete example separately uses an autocomplete mapping. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- maxCharsToExamine limits the characters inspected per field per document and defaults to 500,000; maxNumPassages limits returned high-scoring passages per field per document and defaults to five. A passage is approximately a sentence. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- Highlight paths can include fields outside the query path; the demo searches broadly while highlighting title, then title and fullplot. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- Passages are roughly sentence length; a 2020 reproduction showed unexpected truncation at the abbreviation Inc., and MongoDB confirmed sentence-level defaults. (medium confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- Highlight passage scores rank excerpt relevance; applications can choose the highest-scoring excerpt. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- The third-party AtlasSearchBuilder exposes highlight(path, max_chars_to_examine, max_num_passages), including a three-passage example. (low confidence) — [source](https://mongodb-query-builder.readthedocs.io/en/latest/api/atlas-search-builder/)
- In a May 2023 reproduction, wildcard "*" on tags also marked unrelated name tokens as hits. MongoDB explained cross-path highlighting as intended; this is historical evidence, not a current-version test. (low confidence) — [source](https://www.mongodb.com/community/forums/t/search-highlight-is-incorrect-when-using-wildcard-query/225626)
- Atlas Search highlighting supplies matching terms with surrounding original text so an application can explain why a result matched. (high confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- highlight.path can select multiple fields, including fields outside the search operator's path. The Python MongoDB Query Builder exposes field selection and passage/character bounds through AtlasSearchBuilder.highlight(). (medium confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
- Highlights preserve original surface forms, so an analyzed query can highlight a different inflected word: MongoDB's English-analyzer example searches variety and highlights varieties. (low confidence) — [source](https://www.mongodb.com/docs/search/query/highlighting.md)
