Skip to content

Commit

Permalink
Add empty mapping check to createOrUpdateIndexTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallmain committed Jun 23, 2021
1 parent bbd8335 commit 4ccf63a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export class RuleDataClient implements IRuleDataClient {
const { body: aliasExists } = await clusterClient.indices.existsAlias({
name: alias,
});

const concreteIndexName = `${alias}-000001`;

if (!aliasExists) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 4ccf63a

Please sign in to comment.