diff --git a/packages/kbn-discover-utils/src/utils/format_hit.test.ts b/packages/kbn-discover-utils/src/utils/format_hit.test.ts index ba38812b0e142..6e2acbd43846b 100644 --- a/packages/kbn-discover-utils/src/utils/format_hit.test.ts +++ b/packages/kbn-discover-utils/src/utils/format_hit.test.ts @@ -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, diff --git a/packages/kbn-discover-utils/src/utils/format_hit.ts b/packages/kbn-discover-utils/src/utils/format_hit.ts index 99913e32cb78c..b29353253df51 100644 --- a/packages/kbn-discover-utils/src/utils/format_hit.ts +++ b/packages/kbn-discover-utils/src/utils/format_hit.ts @@ -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 { diff --git a/packages/kbn-unified-data-table/src/components/source_document.test.tsx b/packages/kbn-unified-data-table/src/components/source_document.test.tsx index f48e2b58c8424..25d61312dc242 100644 --- a/packages/kbn-unified-data-table/src/components/source_document.test.tsx +++ b/packages/kbn-unified-data-table/src/components/source_document.test.tsx @@ -52,7 +52,7 @@ describe('Unified data table source document cell rendering', function () { /> ); expect(component.html()).toMatchInlineSnapshot( - `"