Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions x-pack/plugins/fleet/server/constants/fleet_es_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import { getESAssetMetadata } from '../services/epm/elasticsearch/meta';

const meta = getESAssetMetadata();
export const MAPPINGS_TEMPLATE_SUFFIX = '@mappings';

export const SETTINGS_TEMPLATE_SUFFIX = '@settings';
export const PACKAGE_TEMPLATE_SUFFIX = '@package';

export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom';

Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/fleet/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export {
FLEET_FINAL_PIPELINE_ID,
FLEET_FINAL_PIPELINE_CONTENT,
FLEET_FINAL_PIPELINE_VERSION,
MAPPINGS_TEMPLATE_SUFFIX,
SETTINGS_TEMPLATE_SUFFIX,
USER_SETTINGS_TEMPLATE_SUFFIX,
PACKAGE_TEMPLATE_SUFFIX,
} from './fleet_es_assets';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { merge, cloneDeep } from 'lodash';
import { merge } from 'lodash';
import Boom from '@hapi/boom';
import type { ElasticsearchClient, Logger, SavedObjectsClientContract } from 'src/core/server';

Expand All @@ -29,8 +29,7 @@ import { getAsset, getPathParts } from '../../archive';
import { removeAssetTypesFromInstalledEs, saveInstalledEsRefs } from '../../packages/install';
import {
FLEET_COMPONENT_TEMPLATES,
MAPPINGS_TEMPLATE_SUFFIX,
SETTINGS_TEMPLATE_SUFFIX,
PACKAGE_TEMPLATE_SUFFIX,
USER_SETTINGS_TEMPLATE_SUFFIX,
} from '../../../../constants';

Expand Down Expand Up @@ -245,34 +244,28 @@ function buildComponentTemplates(params: {
defaultSettings: IndexTemplate['template']['settings'];
}) {
const { templateName, registryElasticsearch, packageName, defaultSettings, mappings } = params;
const mappingsTemplateName = `${templateName}${MAPPINGS_TEMPLATE_SUFFIX}`;
const settingsTemplateName = `${templateName}${SETTINGS_TEMPLATE_SUFFIX}`;
const packageTemplateName = `${templateName}${PACKAGE_TEMPLATE_SUFFIX}`;
const userSettingsTemplateName = `${templateName}${USER_SETTINGS_TEMPLATE_SUFFIX}`;

const templatesMap: TemplateMap = {};
const _meta = getESAssetMetadata({ packageName });

const indexTemplateSettings = registryElasticsearch?.['index_template.settings'] ?? {};
// @ts-expect-error no property .mapping (yes there is)
const indexTemplateMappingSettings = indexTemplateSettings?.index?.mapping;
const indexTemplateSettingsForTemplate = cloneDeep(indexTemplateSettings);

// index.mapping settings must go on the mapping component template otherwise
// the template may be rejected e.g if nested_fields.limit has been increased
if (indexTemplateMappingSettings) {
// @ts-expect-error no property .mapping
delete indexTemplateSettingsForTemplate.index.mapping;
}

templatesMap[mappingsTemplateName] = {
const templateSettings = merge(defaultSettings, indexTemplateSettings);

templatesMap[packageTemplateName] = {
template: {
settings: {
...templateSettings,
index: {
...templateSettings.index,
mapping: {
...templateSettings?.mapping,
total_fields: {
...templateSettings?.mapping?.total_fields,
limit: '10000',
},
...indexTemplateMappingSettings,
},
},
},
Expand All @@ -281,13 +274,6 @@ function buildComponentTemplates(params: {
_meta,
};

templatesMap[settingsTemplateName] = {
template: {
settings: merge(defaultSettings, indexTemplateSettingsForTemplate),
},
_meta,
};

// return empty/stub template
templatesMap[userSettingsTemplateName] = {
template: {
Expand Down
Loading