diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx index 6a44963d91e66..418972d58e7a9 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx @@ -436,4 +436,46 @@ describe('Mappings editor: core', () => { expect(data).toEqual(updatedMappings); }); }); + + describe('multi-fields support', () => { + it('allows multi-fields for most types', async () => { + const value = { + properties: { + name1: { + type: 'wildcard', + }, + }, + }; + await act(async () => { + testBed = setup({ onChange: onChangeHandler, value }); + }); + + const { component, exists } = testBed; + component.update(); + expect(exists('addMultiFieldButton')).toBe(true); + }); + + it('keeps the fields property in the field', async () => { + const value = { + properties: { + name1: { + type: 'wildcard', + fields: { + text: { + type: 'match_only_text', + }, + }, + }, + }, + }; + await act(async () => { + testBed = setup({ onChange: onChangeHandler, value }); + }); + + const { component } = testBed; + component.update(); + ({ data } = await getMappingsEditorData(component)); + expect(data).toEqual(value); + }); + }); }); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.test.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.test.ts index 162bb59a0528a..1f1ca1b34deef 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.test.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.test.ts @@ -79,15 +79,26 @@ describe('utils', () => { }); describe('getFieldMeta', () => { + test('returns "canHaveMultiFields:true" for text data type', () => { + expect(getFieldMeta({ name: 'text_field', type: 'text' }).canHaveMultiFields).toEqual(true); + }); + test('returns "canHaveMultiFields:true" for keyword data type', () => { + expect(getFieldMeta({ name: 'keyword_field', type: 'keyword' }).canHaveMultiFields).toEqual( + true + ); + }); test('returns "canHaveMultiFields:true" for IP data type', () => { - expect(getFieldMeta({ name: 'ip_field', type: 'ip' })).toEqual({ - canHaveChildFields: false, - canHaveMultiFields: true, - childFieldsName: 'fields', - hasChildFields: false, - hasMultiFields: false, - isExpanded: false, - }); + expect(getFieldMeta({ name: 'ip_field', type: 'ip' }).canHaveMultiFields).toEqual(true); + }); + test('returns "canHaveMultiFields:true" for wildcard data type', () => { + expect(getFieldMeta({ name: 'wildcard_field', type: 'wildcard' }).canHaveMultiFields).toEqual( + true + ); + }); + test('returns "canHaveMultiFields:false" for flattened data type', () => { + expect( + getFieldMeta({ name: 'flattened_field', type: 'flattened' }).canHaveMultiFields + ).toEqual(false); }); }); }); diff --git a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts index 33555bb2ce1d0..631eb8c081b95 100644 --- a/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts +++ b/x-pack/plugins/index_management/public/application/components/mappings_editor/lib/utils.ts @@ -39,13 +39,24 @@ import { TreeItem } from '../components/tree'; export const getUniqueId = () => uuidv4(); +const fieldsWithoutMultiFields: DataType[] = [ + // @ts-expect-error aggregate_metric_double is not yet supported by the editor + 'aggregate_metric_double', + 'constant_keyword', + 'flattened', + 'geo_shape', + 'join', + 'percolator', + 'point', + 'shape', +]; export const getChildFieldsName = (dataType: DataType): ChildFieldName | undefined => { - if (dataType === 'text' || dataType === 'keyword' || dataType === 'ip') { - return 'fields'; + if (fieldsWithoutMultiFields.includes(dataType)) { + return undefined; } else if (dataType === 'object' || dataType === 'nested') { return 'properties'; } - return undefined; + return 'fields'; }; export const getFieldMeta = (field: Field, isMultiField?: boolean): FieldMeta => {