diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts index 58bcfcca386cf..82ee4a52b65a3 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts @@ -1314,6 +1314,71 @@ describe('EPM template', () => { expect(mappings).toEqual(runtimeFieldMapping); }); + it('tests processing dimension fields on a dynamic template object', () => { + const textWithRuntimeFieldsLiteralYml = ` +- name: labels.* + type: object + object_type: keyword + dimension: true +`; + const runtimeFieldMapping = { + properties: { + labels: { + type: 'object', + dynamic: true, + }, + }, + dynamic_templates: [ + { + 'labels.*': { + match_mapping_type: 'string', + path_match: 'labels.*', + mapping: { + type: 'keyword', + time_series_dimension: true, + }, + }, + }, + ], + }; + const fields: Field[] = safeLoad(textWithRuntimeFieldsLiteralYml); + const processedFields = processFields(fields); + const mappings = generateMappings(processedFields, true); + expect(mappings).toEqual(runtimeFieldMapping); + }); + + it('tests processing dimension fields on a dynamic template field', () => { + const textWithRuntimeFieldsLiteralYml = ` +- name: labels.* + type: keyword + dimension: true +`; + const runtimeFieldMapping = { + properties: { + labels: { + type: 'object', + dynamic: true, + }, + }, + dynamic_templates: [ + { + 'labels.*': { + match_mapping_type: 'string', + path_match: 'labels.*', + mapping: { + type: 'keyword', + time_series_dimension: true, + }, + }, + }, + ], + }; + const fields: Field[] = safeLoad(textWithRuntimeFieldsLiteralYml); + const processedFields = processFields(fields); + const mappings = generateMappings(processedFields, true); + expect(mappings).toEqual(runtimeFieldMapping); + }); + it('tests processing scaled_float fields in a dynamic template', () => { const textWithRuntimeFieldsLiteralYml = ` - name: numeric_labels diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts index 01b1792dc5e79..0cc3816e839a9 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts @@ -451,6 +451,10 @@ function _generateMappings( ); } + if (field.dimension && isIndexModeTimeSeries) { + dynProperties.time_series_dimension = field.dimension; + } + // When a wildcard field specifies the subobjects setting, // the parent intermediate object should set the subobjects // setting.