Skip to content

Commit 0fb7d22

Browse files
[Tabify] Add meta option to include top-level underscored field values (#90535)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 34cf90e commit 0fb7d22

File tree

3 files changed

+305
-5
lines changed

3 files changed

+305
-5
lines changed

src/plugins/data/common/search/tabify/__snapshots__/tabify_docs.test.ts.snap

Lines changed: 284 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/data/common/search/tabify/tabify_docs.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe('tabifyDocs', () => {
3737
hits: {
3838
hits: [
3939
{
40+
_id: 'hit-id-value',
41+
_index: 'hit-index-value',
42+
_type: 'hit-type-value',
43+
_score: 77,
4044
_source: { sourceTest: 123 },
4145
fields: { fieldTest: 123, invalidMapping: 345, nested: [{ field: 123 }] },
4246
},
@@ -59,6 +63,11 @@ describe('tabifyDocs', () => {
5963
expect(table).toMatchSnapshot();
6064
});
6165

66+
it('combines meta fields if meta option is set', () => {
67+
const table = tabifyDocs(response, index, { meta: true });
68+
expect(table).toMatchSnapshot();
69+
});
70+
6271
it('works without provided index pattern', () => {
6372
const table = tabifyDocs(response);
6473
expect(table).toMatchSnapshot();

src/plugins/data/common/search/tabify/tabify_docs.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { isPlainObject } from 'lodash';
1111
import { IndexPattern } from '../../index_patterns/index_patterns';
1212
import { Datatable, DatatableColumn, DatatableColumnType } from '../../../../expressions/common';
1313

14+
export interface TabifyDocsOptions {
15+
shallow?: boolean;
16+
source?: boolean;
17+
meta?: boolean;
18+
}
19+
1420
export function flattenHit(
1521
hit: SearchResponse<unknown>['hits']['hits'][0],
1622
indexPattern?: IndexPattern,
@@ -56,12 +62,13 @@ export function flattenHit(
5662
if (params?.source !== false && hit._source) {
5763
flatten(hit._source as Record<string, any>);
5864
}
59-
return flat;
60-
}
65+
if (params?.meta !== false) {
66+
// combine the fields that Discover allows to add as columns
67+
const { _id, _index, _type, _score } = hit;
68+
flatten({ _id, _index, _score, _type });
69+
}
6170

62-
export interface TabifyDocsOptions {
63-
shallow?: boolean;
64-
source?: boolean;
71+
return flat;
6572
}
6673

6774
export const tabifyDocs = (

0 commit comments

Comments
 (0)