From 2403bc8c88c2c850e572142022efebbac21adf8b Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Thu, 30 Nov 2023 14:29:12 -0600 Subject: [PATCH] [data views] Stored fields are always requested, we don't need logic around it (#171815) ## Summary Stored field handling is basically a dead code path. `['*']` is always sent so lets push this closer to the query. --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../src/__mocks__/data_view.ts | 2 +- .../search_source/search_source.test.ts | 3 +-- .../search/search_source/search_source.ts | 5 ++-- .../common/data_views/data_view.test.ts | 4 ---- .../data_views/common/data_views/data_view.ts | 2 -- .../public/hooks/use_es_doc_search.test.tsx | 23 ++++++++++++------- .../public/hooks/use_es_doc_search.ts | 2 +- .../public/__mocks__/data_view.ts | 2 +- .../public/dataview_picker/mocks/dataview.ts | 2 +- .../common/dependency_mocks/index_patterns.ts | 1 - .../hooks/use_kibana_index_patterns.mock.tsx | 1 - 11 files changed, 22 insertions(+), 25 deletions(-) diff --git a/packages/kbn-discover-utils/src/__mocks__/data_view.ts b/packages/kbn-discover-utils/src/__mocks__/data_view.ts index 66e2803cdd239..b7a365c8b674c 100644 --- a/packages/kbn-discover-utils/src/__mocks__/data_view.ts +++ b/packages/kbn-discover-utils/src/__mocks__/data_view.ts @@ -108,7 +108,7 @@ export const buildDataViewMock = ({ fields: dataViewFields, type: 'default', getName: () => name, - getComputedFields: () => ({ docvalueFields: [], scriptFields: {}, storedFields: ['*'] }), + getComputedFields: () => ({ docvalueFields: [], scriptFields: {} }), getSourceFiltering: () => ({}), getIndexPattern: () => `${name}-title`, getFieldByName: jest.fn((fieldName: string) => dataViewFields.getByName(fieldName)), diff --git a/src/plugins/data/common/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts index 4dfd9aea3b6df..64ae2f3b2ec01 100644 --- a/src/plugins/data/common/search/search_source/search_source.test.ts +++ b/src/plugins/data/common/search/search_source/search_source.test.ts @@ -281,7 +281,6 @@ describe('SearchSource', () => { searchSource.setField('index', { ...indexPattern, getComputedFields: () => ({ - storedFields: ['hello'], scriptFields: { world: {} }, docvalueFields: ['@timestamp'], runtimeFields, @@ -289,7 +288,7 @@ describe('SearchSource', () => { } as unknown as DataView); const request = searchSource.getSearchRequestBody(); - expect(request.stored_fields).toEqual(['hello']); + expect(request.stored_fields).toEqual(['*']); expect(request.script_fields).toEqual({ world: {} }); expect(request.fields).toEqual(['@timestamp']); expect(request.runtime_mappings).toEqual(runtimeFields); diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index 19d39c7772fb9..6fc47ac126431 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -779,12 +779,11 @@ export class SearchSource { const metaFields = getConfig(UI_SETTINGS.META_FIELDS) ?? []; // get some special field types from the index pattern - const { docvalueFields, scriptFields, storedFields, runtimeFields } = index + const { docvalueFields, scriptFields, runtimeFields } = index ? index.getComputedFields() : { docvalueFields: [], scriptFields: {}, - storedFields: ['*'], runtimeFields: {}, }; const fieldListProvided = !!body.fields; @@ -798,7 +797,7 @@ export class SearchSource { ...scriptFields, } : {}; - body.stored_fields = storedFields; + body.stored_fields = ['*']; body.runtime_mappings = runtimeFields || {}; // apply source filters from index pattern if specified by the user diff --git a/src/plugins/data_views/common/data_views/data_view.test.ts b/src/plugins/data_views/common/data_views/data_view.test.ts index 18ab045d81ddf..15a229832a489 100644 --- a/src/plugins/data_views/common/data_views/data_view.test.ts +++ b/src/plugins/data_views/common/data_views/data_view.test.ts @@ -136,10 +136,6 @@ describe('IndexPattern', () => { expect(indexPattern.getComputedFields).toBeInstanceOf(Function); }); - test('should request all stored fields', () => { - expect(indexPattern.getComputedFields().storedFields).toContain('*'); - }); - test('should request date fields as docvalue_fields', () => { const { docvalueFields } = indexPattern.getComputedFields(); const docValueFieldNames = docvalueFields.map((field) => field.field); diff --git a/src/plugins/data_views/common/data_views/data_view.ts b/src/plugins/data_views/common/data_views/data_view.ts index f47d4c0fb2177..d60d0b4c1172c 100644 --- a/src/plugins/data_views/common/data_views/data_view.ts +++ b/src/plugins/data_views/common/data_views/data_view.ts @@ -85,7 +85,6 @@ export class DataView extends AbstractDataView implements DataViewBase { const scriptFields: Record = {}; if (!this.fields) { return { - storedFields: ['*'], scriptFields, docvalueFields: [] as Array<{ field: string; format: string }>, runtimeFields: {}, @@ -117,7 +116,6 @@ export class DataView extends AbstractDataView implements DataViewBase { const runtimeFields = this.getRuntimeMappings(); return { - storedFields: ['*'], scriptFields, docvalueFields, runtimeFields, diff --git a/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.test.tsx b/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.test.tsx index cee1cf509e138..640e6fd48462d 100644 --- a/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.test.tsx +++ b/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.test.tsx @@ -40,7 +40,7 @@ const services = { describe('Test of helper / hook', () => { test('buildSearchBody given useNewFieldsApi is false', () => { const dataView = { - getComputedFields: () => ({ storedFields: [], scriptFields: [], docvalueFields: [] }), + getComputedFields: () => ({ scriptFields: [], docvalueFields: [] }), } as unknown as DataView; const actual = buildSearchBody('1', index, dataView, false); expect(actual).toMatchInlineSnapshot(` @@ -67,7 +67,9 @@ describe('Test of helper / hook', () => { }, }, "script_fields": Array [], - "stored_fields": Array [], + "stored_fields": Array [ + "*", + ], "version": true, }, } @@ -76,7 +78,7 @@ describe('Test of helper / hook', () => { test('buildSearchBody useNewFieldsApi is true', () => { const dataView = { - getComputedFields: () => ({ storedFields: [], scriptFields: [], docvalueFields: [] }), + getComputedFields: () => ({ scriptFields: [], docvalueFields: [] }), } as unknown as DataView; const actual = buildSearchBody('1', index, dataView, true); expect(actual).toMatchInlineSnapshot(` @@ -108,7 +110,9 @@ describe('Test of helper / hook', () => { }, "runtime_mappings": Object {}, "script_fields": Array [], - "stored_fields": Array [], + "stored_fields": Array [ + "*", + ], "version": true, }, } @@ -117,7 +121,7 @@ describe('Test of helper / hook', () => { test('buildSearchBody with requestSource', () => { const dataView = { - getComputedFields: () => ({ storedFields: [], scriptFields: [], docvalueFields: [] }), + getComputedFields: () => ({ scriptFields: [], docvalueFields: [] }), } as unknown as DataView; const actual = buildSearchBody('1', index, dataView, true, true); expect(actual).toMatchInlineSnapshot(` @@ -150,7 +154,9 @@ describe('Test of helper / hook', () => { }, "runtime_mappings": Object {}, "script_fields": Array [], - "stored_fields": Array [], + "stored_fields": Array [ + "*", + ], "version": true, }, } @@ -160,7 +166,6 @@ describe('Test of helper / hook', () => { test('buildSearchBody with runtime fields', () => { const dataView = { getComputedFields: () => ({ - storedFields: [], scriptFields: [], docvalueFields: [], runtimeFields: { @@ -210,7 +215,9 @@ describe('Test of helper / hook', () => { }, }, "script_fields": Array [], - "stored_fields": Array [], + "stored_fields": Array [ + "*", + ], "version": true, }, } diff --git a/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.ts b/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.ts index d215306d6f7ea..80140a1dce0ac 100644 --- a/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.ts +++ b/src/plugins/unified_doc_viewer/public/hooks/use_es_doc_search.ts @@ -131,7 +131,7 @@ export function buildSearchBody( filter: [{ ids: { values: [id] } }, { term: { _index: index } }], }, }, - stored_fields: computedFields.storedFields, + stored_fields: ['*'], script_fields: computedFields.scriptFields, version: true, }, diff --git a/src/plugins/unified_histogram/public/__mocks__/data_view.ts b/src/plugins/unified_histogram/public/__mocks__/data_view.ts index 34043e8348c4b..ffc429c1aa887 100644 --- a/src/plugins/unified_histogram/public/__mocks__/data_view.ts +++ b/src/plugins/unified_histogram/public/__mocks__/data_view.ts @@ -91,7 +91,7 @@ export const buildDataViewMock = ({ metaFields: ['_index', '_score'], fields: dataViewFields, getName: () => name, - getComputedFields: () => ({ docvalueFields: [], scriptFields: {}, storedFields: ['*'] }), + getComputedFields: () => ({ docvalueFields: [], scriptFields: {} }), getSourceFiltering: () => ({}), getFieldByName: jest.fn((fieldName: string) => dataViewFields.getByName(fieldName)), timeFieldName: timeFieldName || '', diff --git a/src/plugins/unified_search/public/dataview_picker/mocks/dataview.ts b/src/plugins/unified_search/public/dataview_picker/mocks/dataview.ts index 699ad5fcd4d9f..7b8c1318fae8c 100644 --- a/src/plugins/unified_search/public/dataview_picker/mocks/dataview.ts +++ b/src/plugins/unified_search/public/dataview_picker/mocks/dataview.ts @@ -100,7 +100,7 @@ export const buildDataViewMock = ({ fields: dataViewFields, type: 'default', getName: () => name, - getComputedFields: () => ({ docvalueFields: [], scriptFields: {}, storedFields: ['*'] }), + getComputedFields: () => ({ docvalueFields: [], scriptFields: {} }), getSourceFiltering: () => ({}), getIndexPattern: () => `${name}-title`, getFieldByName: jest.fn((fieldName: string) => dataViewFields.getByName(fieldName)), diff --git a/x-pack/plugins/infra/common/dependency_mocks/index_patterns.ts b/x-pack/plugins/infra/common/dependency_mocks/index_patterns.ts index a8b78bf2efccf..85193973ed917 100644 --- a/x-pack/plugins/infra/common/dependency_mocks/index_patterns.ts +++ b/x-pack/plugins/infra/common/dependency_mocks/index_patterns.ts @@ -49,7 +49,6 @@ export const createIndexPatternMock = ({ getComputedFields: () => ({ runtimeFields: runtimeFields ?? {}, scriptFields: {}, - storedFields: [], docvalueFields: [], }), getRuntimeMappings: () => runtimeFields ?? {}, diff --git a/x-pack/plugins/infra/public/hooks/use_kibana_index_patterns.mock.tsx b/x-pack/plugins/infra/public/hooks/use_kibana_index_patterns.mock.tsx index 2a72a2d3b3d68..8b7d76113eea8 100644 --- a/x-pack/plugins/infra/public/hooks/use_kibana_index_patterns.mock.tsx +++ b/x-pack/plugins/infra/public/hooks/use_kibana_index_patterns.mock.tsx @@ -99,7 +99,6 @@ export const createIndexPatternMock = ({ return accumulatedRuntimeFields; }, {}), scriptFields: {}, - storedFields: [], }), }; };