Skip to content

Commit

Permalink
[Tabify] Add meta option to include top-level underscored field values (
Browse files Browse the repository at this point in the history
#90535)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
tsullivan and kibanamachine authored Feb 9, 2021
1 parent d43547a commit 4b3d1bf
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 5 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/plugins/data/common/search/tabify/tabify_docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ describe('tabifyDocs', () => {
hits: {
hits: [
{
_id: 'hit-id-value',
_index: 'hit-index-value',
_type: 'hit-type-value',
_score: 77,
_source: { sourceTest: 123 },
fields: { fieldTest: 123, invalidMapping: 345, nested: [{ field: 123 }] },
},
Expand All @@ -59,6 +63,11 @@ describe('tabifyDocs', () => {
expect(table).toMatchSnapshot();
});

it('combines meta fields if meta option is set', () => {
const table = tabifyDocs(response, index, { meta: true });
expect(table).toMatchSnapshot();
});

it('works without provided index pattern', () => {
const table = tabifyDocs(response);
expect(table).toMatchSnapshot();
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/data/common/search/tabify/tabify_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { isPlainObject } from 'lodash';
import { IndexPattern } from '../../index_patterns/index_patterns';
import { Datatable, DatatableColumn, DatatableColumnType } from '../../../../expressions/common';

export interface TabifyDocsOptions {
shallow?: boolean;
source?: boolean;
meta?: boolean;
}

export function flattenHit(
hit: SearchResponse<unknown>['hits']['hits'][0],
indexPattern?: IndexPattern,
Expand Down Expand Up @@ -56,12 +62,13 @@ export function flattenHit(
if (params?.source !== false && hit._source) {
flatten(hit._source as Record<string, any>);
}
return flat;
}
if (params?.meta !== false) {
// combine the fields that Discover allows to add as columns
const { _id, _index, _type, _score } = hit;
flatten({ _id, _index, _score, _type });
}

export interface TabifyDocsOptions {
shallow?: boolean;
source?: boolean;
return flat;
}

export const tabifyDocs = (
Expand Down

0 comments on commit 4b3d1bf

Please sign in to comment.