[9.3] [Discover][Logs profile] Fix missing search highlights (#260056)#260397
Merged
kibanamachine merged 1 commit intoelastic:9.3from Mar 31, 2026
Merged
[9.3] [Discover][Logs profile] Fix missing search highlights (#260056)#260397kibanamachine merged 1 commit intoelastic:9.3from
kibanamachine merged 1 commit intoelastic:9.3from
Conversation
## Summary Fixes search result highlighting not working in the Logs profile summary column and content breakdown. > [!IMPORTANT] > This should be seen as a temporary fix, while the team works on React-based field formatters Closes elastic#259407 ### Root cause The message value was read from `row.flattened`, which doesn't contain ES highlights. The highlight snippets can be found in `row.raw.highlight[field]` with `@kibana-highlighted-field@` tags, but were never passed to the rendering pipeline, after recent changes to the implementation. ### Approaches considered We explored different ways to get the highlighted value into the message rendering. First approach was to reuse `getLogDocumentOverview`, which had been removed to solve an issue with OTel documents, but it called `formatFieldValue` internally. That receives the full ES hit, the field formatter would convert the ES tags to `<mark>` HTML tags automatically, so that we could then keep our current logic working. The idea was to get the field name from `getMessageFieldWithFallbacks(row.flattened)` (which handles OTel fallback) and the already highlighted value from `getMessageFieldWithFallbacks(documentOverview)`. However, this approach didn't work for two reasons: - There's a field resolution priority mismatch, where `getMessageFieldWithFallbacks` checks OTel fields first (`body.text` before `message`), while `getFieldValueWithFallback` inside `getLogDocumentOverview` checks ECS first (`message` before `body.text`). If a doc has both, the field name and value could come from different sources. - `formatFieldValue` passes the ECS field name to `dataView.fields.getByName()`, which can return `undefined` for OTel docs without aliases. When that happens, the field formatter can't look up `hit.highlight[field.name]` and silently skips highlighting entirely. In testing, highlights didn't appear. The final approach reads `row.raw.highlight[field]` directly using the correctly-resolved field name from `getMessageFieldWithFallbacks(row.flattened)`, bypassing the field formatter altogether. A new `getHighlightedFieldValue` utility replicates the logic of `getHighlightHtml` from `@kbn/field-formats-plugin` (which packages can't import directly), merging all ES highlight snippets into the escaped field value — handling multi-valued fields and multiple highlight regions within a single value. `escapeAndPreserveHighlightTags` was simplified back to only handle HTML `<mark>` tags (used by resource badges that receive pre-formatted values from `formatFieldValue`). Also, we fixed a pre-existing undetected bug where multiple highlight regions were silently dropped due to a `markTags.length === 2` condition that only allowed single keyword highlighting. ### Changes - **`content.tsx` / `summary_column.tsx` / `content_breakdown.tsx`** - Read the full ES highlight array from `row.raw.highlight[field]` (not just `[0]`) and pass it with the plain field value to `getHighlightedFieldValue`, which merges all snippets and produces XSS-safe HTML. - **`highlight_utils.ts`** (renamed from `escape_preserve_highlight_tags.ts`) - Added `getHighlightedFieldValue(fieldValue, highlights)`, directly replicating `getHighlightHtml` from `@kbn/field-formats-plugin`, iterating over all ES highlight snippets, stripping ES tags to find matching text, and replacing occurrences in the escaped field value with `<mark>` elements. Handles multi-valued fields and multiple highlight regions. - Simplified `escapeAndPreserveHighlightTags` to only handle HTML `<mark>` tags (its sole remaining use case in `cell_actions_popover.tsx` for resource badges). ### Demo https://github.com/user-attachments/assets/7aa67eb4-f2ff-4874-bd3b-f8734f2c2e00 (cherry picked from commit 7346059)
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.
Backport
This will backport the following commits from
mainto9.3:Questions ?
Please refer to the Backport tool documentation