From 4ccf63a2ca45878e56f7de569ad65cdd427ab91f Mon Sep 17 00:00:00 2001 From: Marshall Main Date: Wed, 23 Jun 2021 10:49:49 -0700 Subject: [PATCH] Add empty mapping check to createOrUpdateIndexTemplate --- .../rule_registry/server/rule_data_client/index.ts | 1 + .../server/rule_data_plugin_service/index.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/rule_registry/server/rule_data_client/index.ts b/x-pack/plugins/rule_registry/server/rule_data_client/index.ts index fb8690c1a762d6..cb69463135ec0f 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_client/index.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_client/index.ts @@ -188,6 +188,7 @@ export class RuleDataClient implements IRuleDataClient { const { body: aliasExists } = await clusterClient.indices.existsAlias({ name: alias, }); + const concreteIndexName = `${alias}-000001`; if (!aliasExists) { diff --git a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/index.ts b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/index.ts index 12609fe1c236fe..e2af6ca868795f 100644 --- a/x-pack/plugins/rule_registry/server/rule_data_plugin_service/index.ts +++ b/x-pack/plugins/rule_registry/server/rule_data_plugin_service/index.ts @@ -7,7 +7,7 @@ import { ClusterPutComponentTemplate } from '@elastic/elasticsearch/api/requestParams'; import { estypes } from '@elastic/elasticsearch'; import { ElasticsearchClient, Logger } from 'kibana/server'; -import { merge } from 'lodash'; +import { isEmpty, merge } from 'lodash'; import { technicalComponentTemplate } from '../../common/assets/component_templates/technical_component_template'; import { DEFAULT_ILM_POLICY_ID, @@ -132,6 +132,14 @@ export class RuleDataPluginService { const clusterClient = await this.getClusterClient(); this.options.logger.debug(`Installing index template ${template.name}`); + const { body: simulateResponse } = await clusterClient.indices.simulateTemplate(template); + const mappings: estypes.MappingTypeMapping = simulateResponse.template.mappings; + + if (isEmpty(mappings)) { + throw new Error( + 'No mappings would be generated for this index, possibly due to failed/misconfigured bootstrapping' + ); + } const mergedTemplate = merge( { body: {