mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Discover] Highlight matching field values when performing a KQL search on a keyword field (#201952)
## Summary Closes [Highlighting isn't visible in Discover on keywords if the field also has text type while searching #118590](https://github.com/elastic/kibana/issues/118590 ) Added `text` field highlight when querying on matching `keyword` Before:  After: <img width="722" alt="Screenshot 2024-11-27 at 13 10 51" src="https://github.com/user-attachments/assets/c4c0ae23-e6bc-4840-84fb-908c50da5491"> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [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 - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [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) ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ...
This commit is contained in:
parent
e5b1773971
commit
f0fbefa144
3 changed files with 38 additions and 3 deletions
|
@ -106,6 +106,36 @@ describe('formatHit', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('should highlight a subfield even shouldShowFieldHandler determines it should not be shown ', () => {
|
||||
const highlightHit = buildDataTableRecord(
|
||||
{
|
||||
_id: '2',
|
||||
_index: 'logs',
|
||||
fields: {
|
||||
object: ['object'],
|
||||
'object.value': [42, 13],
|
||||
},
|
||||
highlight: { 'object.value': ['%%'] },
|
||||
},
|
||||
dataViewMock
|
||||
);
|
||||
|
||||
const formatted = formatHit(
|
||||
highlightHit,
|
||||
dataViewMock,
|
||||
(fieldName) => ['object'].includes(fieldName),
|
||||
220,
|
||||
fieldFormatsMock
|
||||
);
|
||||
|
||||
expect(formatted).toEqual([
|
||||
['object.value', 'formatted:42,13', 'object.value'],
|
||||
['object', ['object'], 'object'],
|
||||
['_index', 'formatted:logs', '_index'],
|
||||
['_score', undefined, '_score'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('should filter fields based on their real name not displayName', () => {
|
||||
const formatted = formatHit(
|
||||
row,
|
||||
|
|
|
@ -70,9 +70,14 @@ export function formatHit(
|
|||
const pairs = highlights[key] ? renderedPairs : otherPairs;
|
||||
|
||||
// If the field is a mapped field, we first check if it should be shown,
|
||||
// if not we always include it into the result.
|
||||
// or if it's highlighted, but the parent is not.
|
||||
// If not we always include it into the result.
|
||||
if (displayKey) {
|
||||
if (shouldShowFieldHandler(key)) {
|
||||
const multiParent = field.getSubtypeMulti?.()?.multi.parent;
|
||||
const isHighlighted = Boolean(highlights[key]);
|
||||
const isParentHighlighted = Boolean(multiParent && highlights[multiParent]);
|
||||
|
||||
if ((isHighlighted && !isParentHighlighted) || shouldShowFieldHandler(key)) {
|
||||
pairs.push([displayKey, undefined, key]);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -52,7 +52,7 @@ describe('Unified data table source document cell rendering', function () {
|
|||
/>
|
||||
);
|
||||
expect(component.html()).toMatchInlineSnapshot(
|
||||
`"<dl class=\\"euiDescriptionList unifiedDataTable__descriptionList unifiedDataTable__cellValue css-id58dh-euiDescriptionList-inline-left\\" data-test-subj=\\"discoverCellDescriptionList\\" data-type=\\"inline\\"><dt class=\\"euiDescriptionList__title unifiedDataTable__descriptionListTitle css-1fizlic-euiDescriptionList__title-inline-compressed\\">_index</dt><dd class=\\"euiDescriptionList__description unifiedDataTable__descriptionListDescription css-11rdew2-euiDescriptionList__description-inline-compressed\\">test</dd><dt class=\\"euiDescriptionList__title unifiedDataTable__descriptionListTitle css-1fizlic-euiDescriptionList__title-inline-compressed\\">_score</dt><dd class=\\"euiDescriptionList__description unifiedDataTable__descriptionListDescription css-11rdew2-euiDescriptionList__description-inline-compressed\\">1</dd></dl>"`
|
||||
`"<dl class=\\"euiDescriptionList unifiedDataTable__descriptionList unifiedDataTable__cellValue css-id58dh-euiDescriptionList-inline-left\\" data-test-subj=\\"discoverCellDescriptionList\\" data-type=\\"inline\\"><dt class=\\"euiDescriptionList__title unifiedDataTable__descriptionListTitle css-1fizlic-euiDescriptionList__title-inline-compressed\\">extension</dt><dd class=\\"euiDescriptionList__description unifiedDataTable__descriptionListDescription css-11rdew2-euiDescriptionList__description-inline-compressed\\">.gz</dd><dt class=\\"euiDescriptionList__title unifiedDataTable__descriptionListTitle css-1fizlic-euiDescriptionList__title-inline-compressed\\">_index</dt><dd class=\\"euiDescriptionList__description unifiedDataTable__descriptionListDescription css-11rdew2-euiDescriptionList__description-inline-compressed\\">test</dd><dt class=\\"euiDescriptionList__title unifiedDataTable__descriptionListTitle css-1fizlic-euiDescriptionList__title-inline-compressed\\">_score</dt><dd class=\\"euiDescriptionList__description unifiedDataTable__descriptionListDescription css-11rdew2-euiDescriptionList__description-inline-compressed\\">1</dd></dl>"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue