Skip to content

Commit

Permalink
Fix merge existing dynamic_templates
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Aug 2, 2022
1 parent 54a6c4e commit 4589dd9
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { merge } from 'lodash';
import { merge, concat, uniqBy, omit } from 'lodash';
import Boom from '@hapi/boom';
import type { ElasticsearchClient, Logger } from '@kbn/core/server';

Expand Down Expand Up @@ -241,6 +241,15 @@ function buildComponentTemplates(params: {

const templateSettings = merge(defaultSettings, indexTemplateSettings);

const indexTemplateMappings = registryElasticsearch?.['index_template.mappings'] ?? {};

const mappingsProperties = merge(mappings.properties, indexTemplateMappings.properties ?? {});

const mappingsDynamicTemplates = uniqBy(
concat(mappings.dynamic_templates ?? [], indexTemplateMappings.dynamic_templates ?? []),
(dynampingTemplate) => Object.keys(dynampingTemplate)[0]
);

templatesMap[packageTemplateName] = {
template: {
settings: {
Expand All @@ -256,7 +265,11 @@ function buildComponentTemplates(params: {
},
},
},
mappings: merge(mappings, registryElasticsearch?.['index_template.mappings'] ?? {}),
mappings: {
properties: mappingsProperties,
dynamic_templates: mappingsDynamicTemplates.length ? mappingsDynamicTemplates : undefined,
...omit(indexTemplateMappings, 'properties', 'dynamic_templates'),
},
},
_meta,
};
Expand Down

0 comments on commit 4589dd9

Please sign in to comment.