Repository navigation
Show literal angle brackets in highlighted search results - #5038
Merged
Merged
Conversation
reakaleek
approved these changes
Nov 24, 2026
The navigation and full-page search render a result's title and description as HTML, but the processor passed literal text through unencoded. A title such as `The <tenant> parameter` lost `<tenant>` as a stripped tag. With highlight options, the processor now encodes the text outside its `<mark>` tags, encodes typed tokens the same way, and never marks inside an entity. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`IsInsideEntity` computes its search window once, and the highlight loop calls it for both ends of a match directly, without a wrapper. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Elasticsearch now encodes the highlighted text, so a literal `<mark>` in a document stays text and never pairs with a real highlight. The processor normalizes those fragments, encodes a fallback title or description whole, and looks up synonyms by the typed token before encoding each candidate. The AI answer panel reads the plain text of a result for its context and its source links, so they show no entities. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Autocomplete and full search are tested at the request, so a search path that stops asking Elasticsearch for the HTML encoder fails a test. The AI answer panel is rendered with a highlighted result, and the test reads the message it streams and the text of its source link. Co-Authored-By: Claude Opus 5.5 <[email protected]>
akira28
force-pushed
the
feature/escape-search-highlights
branch
from
November 24, 2026 17:47
53eb2c6 to
c934f61
Compare
Contributor
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/5038/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Search results now show literal text such as
<tenant>in titles and descriptions. Before, the result row read it as an HTML tag and dropped it.Affects: Search, Site UI
Prompt summary: A review comment on #5036 found that a heading such as
The <tenant> parameterloses<tenant>in the search row. The author asks to fix that in its own PR, since every search result type has the problem, not only API pages.Why
The navigation search and the full-page search render each result's title and description as HTML, so the
<mark>highlights show.SearchResultProcessorbuilds those strings from the document text and the Elasticsearch fragments, but it never encodes them. Any<…>in a title, description or body fragment reaches the browser as a tag. DOMPurify removes it, orResultCardinjects it as raw HTML. This already affects operation summaries and descriptions with placeholders as well.What
Encoded highlights
Both highlight requests set
encoder: html, so Elasticsearch encodes the document text and returns only its own<mark>tags raw. A literal<mark>in a document therefore never pairs with a real highlight.ReencodeHighlightdecodes the text between the marks and encodes it again withEncode, which touches only&,<,>and". A title or description without a fragment is encoded whole.Plain text without highlighting
SearchResultProcessor.ProcessHitreturns HTML only when the caller passes highlight options. Without them, the result keeps the document's plain text, so the MCP search tools, which turn highlighting off, see no entities.Token marking on encoded text
The post-pass that marks query tokens looks up synonyms by the typed token, then encodes each candidate before matching it (
TokenMatching.Encoded). So a typed<tenant>marks<tenant>, and a synonym such asR&Dstill marks. A match that starts or ends inside an entity is skipped, so typingltorampnever breaks<or&.AI answer panel
AIAnswerPanelreads the plain text of each result for the model context and for its Sources links, so neither shows entities or<mark>tags.Verify
🤖 Generated with Claude Code