Skip to content

Commit

Permalink
[data views] Stored fields are always requested, we don't need logic …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
mattkime and kibanamachine authored Nov 30, 2023
1 parent f98f282 commit 2403bc8
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-discover-utils/src/__mocks__/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,14 @@ describe('SearchSource', () => {
searchSource.setField('index', {
...indexPattern,
getComputedFields: () => ({
storedFields: ['hello'],
scriptFields: { world: {} },
docvalueFields: ['@timestamp'],
runtimeFields,
}),
} 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);
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/common/search/search_source/search_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data_views/common/data_views/data_view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data_views/common/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ export class DataView extends AbstractDataView implements DataViewBase {
const scriptFields: Record<string, estypes.ScriptField> = {};
if (!this.fields) {
return {
storedFields: ['*'],
scriptFields,
docvalueFields: [] as Array<{ field: string; format: string }>,
runtimeFields: {},
Expand Down Expand Up @@ -117,7 +116,6 @@ export class DataView extends AbstractDataView implements DataViewBase {
const runtimeFields = this.getRuntimeMappings();

return {
storedFields: ['*'],
scriptFields,
docvalueFields,
runtimeFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const services = {
describe('Test of <Doc /> 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(`
Expand All @@ -67,7 +67,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
Expand All @@ -76,7 +78,7 @@ describe('Test of <Doc /> 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(`
Expand Down Expand Up @@ -108,7 +110,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
"runtime_mappings": Object {},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
Expand All @@ -117,7 +121,7 @@ describe('Test of <Doc /> 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(`
Expand Down Expand Up @@ -150,7 +154,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
"runtime_mappings": Object {},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
Expand All @@ -160,7 +166,6 @@ describe('Test of <Doc /> helper / hook', () => {
test('buildSearchBody with runtime fields', () => {
const dataView = {
getComputedFields: () => ({
storedFields: [],
scriptFields: [],
docvalueFields: [],
runtimeFields: {
Expand Down Expand Up @@ -210,7 +215,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const createIndexPatternMock = ({
getComputedFields: () => ({
runtimeFields: runtimeFields ?? {},
scriptFields: {},
storedFields: [],
docvalueFields: [],
}),
getRuntimeMappings: () => runtimeFields ?? {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const createIndexPatternMock = ({
return accumulatedRuntimeFields;
}, {}),
scriptFields: {},
storedFields: [],
}),
};
};

0 comments on commit 2403bc8

Please sign in to comment.