[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>
This commit is contained in:
Matthew Kime 2023-11-30 14:29:12 -06:00 committed by GitHub
parent f98f282388
commit 2403bc8c88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 22 additions and 25 deletions

View file

@ -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)),

View file

@ -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);

View file

@ -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

View file

@ -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);

View file

@ -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: {},
@ -117,7 +116,6 @@ export class DataView extends AbstractDataView implements DataViewBase {
const runtimeFields = this.getRuntimeMappings();
return {
storedFields: ['*'],
scriptFields,
docvalueFields,
runtimeFields,

View file

@ -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(`
@ -67,7 +67,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
@ -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(`
@ -108,7 +110,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
"runtime_mappings": Object {},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
@ -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(`
@ -150,7 +154,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
"runtime_mappings": Object {},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}
@ -160,7 +166,6 @@ describe('Test of <Doc /> helper / hook', () => {
test('buildSearchBody with runtime fields', () => {
const dataView = {
getComputedFields: () => ({
storedFields: [],
scriptFields: [],
docvalueFields: [],
runtimeFields: {
@ -210,7 +215,9 @@ describe('Test of <Doc /> helper / hook', () => {
},
},
"script_fields": Array [],
"stored_fields": Array [],
"stored_fields": Array [
"*",
],
"version": true,
},
}

View file

@ -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,
},

View file

@ -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 || '',

View file

@ -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)),

View file

@ -49,7 +49,6 @@ export const createIndexPatternMock = ({
getComputedFields: () => ({
runtimeFields: runtimeFields ?? {},
scriptFields: {},
storedFields: [],
docvalueFields: [],
}),
getRuntimeMappings: () => runtimeFields ?? {},

View file

@ -99,7 +99,6 @@ export const createIndexPatternMock = ({
return accumulatedRuntimeFields;
}, {}),
scriptFields: {},
storedFields: [],
}),
};
};