Skip to content

[ES|QL][Discover] Highlight results when using ES|QL highlight#271519

Merged
sddonne merged 27 commits into
elastic:mainfrom
sddonne:highlight-results
May 29, 2026
Merged

[ES|QL][Discover] Highlight results when using ES|QL highlight#271519
sddonne merged 27 commits into
elastic:mainfrom
sddonne:highlight-results

Conversation

@sddonne
Copy link
Copy Markdown
Contributor

@sddonne sddonne commented May 27, 2026

Summary

This PR adds highlighting support for ES|QL.

image

How does highlighting work?

DSL and ES|QL highlights do not work in the same way:

  • DSL keeps the value unchanged and return an extra 'highlight' field in the hit that contains substrings to be highlighted.
  • ES|QL directly inlines the highlighting tags inside the result value, not additional information is received in the result.

Implementation details

In order to leverage the current fields formatter architecture, we decorate the Discover hit with a new inline_highlights field when it's detected that the query result has been highlighted. It contains the highlighted columns and which tags has been used for highlighting on each of them (could be different).
Then when the field formatter receives the hit it can decide which algorithm to use.
See #270394 for alternatives discussed.

Checklist

  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

}

const highlights = hit.raw.highlight ?? {};
const highlights = hit.raw.highlight ?? hit.raw.inline_highlights ?? {};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to order highlighted fields at the start of the summary column.

@sddonne sddonne changed the title [ES|QL] Highlight results [ES|QL][Discover] Highlight results when using ES|QL hihglight May 28, 2026
@sddonne sddonne added v9.5.0 Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// Team:ESQL ES|QL related features in Kibana t// release_note:enhancement labels May 28, 2026
@sddonne sddonne added backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana labels May 28, 2026
@sddonne sddonne marked this pull request as ready for review May 28, 2026 10:20
@sddonne sddonne requested review from a team as code owners May 28, 2026 10:20
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/kibana-esql (Team:ESQL)

Copy link
Copy Markdown
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look very nice and it works well, thanks!

@stratoula stratoula changed the title [ES|QL][Discover] Highlight results when using ES|QL hihglight [ES|QL][Discover] Highlight results when using ES|QL highlight May 29, 2026
Copy link
Copy Markdown
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice enhancement, I like it a lot. Some very tiny comments!

Comment thread src/platform/packages/shared/kbn-esql-utils/src/index.ts Outdated
}
});
return columns;
return replaceColumnNamesIfRenamed(root, columns);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

Copy link
Copy Markdown
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

@sddonne sddonne enabled auto-merge (squash) May 29, 2026 10:01
@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #139 / discover/esql_4 discover esql controls when adding an ES|QL panel with controls in Dashboard and exploring it in Discover should retain the controls and their state
  • [job] [logs] FTR Configs #118 / lens app - TSVB Open in Lens Convert to Lens action on dashboard "before all" hook for "should show notification in context menu if visualization can be converted"
  • [job] [logs] Scout Lane #12 - stateful-classic / default / local-stateful-classic - Saved query menu — CRUD (Discover) - save, load, update, save-as-new, delete via the popover
  • [job] [logs] Scout Lane #2 - stateful-classic / default / local-stateful-classic - Stream data routing - previewing data - should show no matches when condition matches nothing

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
agentBuilder 1967 1968 +1
agentBuilderDashboards 598 599 +1
alertingVTwo 1199 1200 +1
apm 2262 2263 +1
cases 2072 2073 +1
cloudSecurityPosture 825 826 +1
console 390 391 +1
controls 434 435 +1
dashboard 1094 1095 +1
data 642 643 +1
datasetQuality 1124 1125 +1
dataVisualizer 934 935 +1
discover 2127 2128 +1
esql 1069 1070 +1
esqlDataGrid 494 495 +1
eventAnnotationListing 759 760 +1
fleet 2234 2235 +1
infra 1914 1915 +1
lens 1812 1813 +1
lists 474 475 +1
logsShared 486 487 +1
maps 1383 1384 +1
ml 4349 4350 +1
observability 1819 1820 +1
observabilityAIAssistantApp 854 855 +1
observabilityLogsExplorer 307 308 +1
osquery 817 818 +1
queryActivity 311 312 +1
searchPlayground 636 637 +1
securitySolution 9578 9579 +1
slo 1388 1389 +1
stackAlerts 237 238 +1
streamsApp 1968 1969 +1
transform 952 953 +1
triggersActionsUi 1864 1865 +1
unifiedDocViewer 983 984 +1
visTypeVega 1838 1839 +1
visualizations 778 779 +1
workflowsManagement 1871 1872 +1
total +39

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
alertingVTwo 879.8KB 879.9KB +51.0B
cloudSecurityPosture 616.0KB 616.1KB +51.0B
discover 1.9MB 1.9MB +1.0KB
esql 921.6KB 921.7KB +51.0B
esqlDataGrid 156.0KB 156.0KB +51.0B
osquery 1.3MB 1.3MB +51.0B
securitySolution 12.1MB 12.1MB +51.0B
slo 1.2MB 1.2MB +51.0B
streamsApp 2.1MB 2.1MB +51.0B
workflowsManagement 2.5MB 2.5MB +51.0B
total +1.5KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fieldFormats 60.5KB 60.8KB +298.0B

History

@sddonne sddonne merged commit 56985e7 into elastic:main May 29, 2026
32 checks passed
dej611 pushed a commit to dej611/kibana that referenced this pull request May 29, 2026
…ic#271519)

- Closes elastic#190293
## Summary
This PR adds highlighting support for ES|QL.

<img width="1905" height="866" alt="image"
src="https://github.com/user-attachments/assets/d806ccc1-165e-46f6-a7f7-57258ac03191"
/>


### How does highlighting work?
DSL and ES|QL highlights do not work in the same way:
- DSL keeps the value unchanged and return an extra 'highlight' field in
the hit that contains substrings to be highlighted.
- ES|QL directly inlines the highlighting tags inside the result value,
not additional information is received in the result.

### Implementation details
In order to leverage the current fields formatter architecture, we
decorate the Discover hit with a new `inline_highlights` field when it's
detected that the query result has been highlighted. It contains the
highlighted columns and which tags has been used for highlighting on
each of them (could be different).
Then when the field formatter receives the `hit` it can decide which
algorithm to use.
See elastic#270394 for alternatives
discussed.


### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratou <efstratia.kalafateli@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:enhancement Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// Team:ESQL ES|QL related features in Kibana t// v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discover][ES|QL] Highlight the results of a search

4 participants