From 28e8eb012ba6197fe59d726d03b34dcb22efe8f7 Mon Sep 17 00:00:00 2001 From: Achyut Jhunjhunwala Date: Wed, 13 Aug 2025 21:24:44 +0200 Subject: [PATCH] [Dataset Quality]Fix ES issue with index template updates (#231615) ## Summary closes https://github.com/elastic/kibana/issues/231478 closes https://github.com/elastic/kibana/issues/231477 As part of this [PR](https://github.com/elastic/kibana/pull/231407), i fixed the issue but [realised](https://github.com/elastic/kibana/pull/231394/files#diff-b0b75c67a5e67b5f0d2ab1bfc8cd4cd866485a6486d31c6a2b0deafc42beed05R116) there are more fields which are causing issue. Hence removing the exhaustive list of keys which are causing issues --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit a26d279ed4d25fccb774e9ebb8ac76bfcf63afe7) # Conflicts: # x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts --- .../tests/data_streams/es_utils.ts | 47 +++++++++++++++---- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts b/x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts index 6c32e51e51968..580152c848118 100644 --- a/x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts +++ b/x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts @@ -6,6 +6,7 @@ */ import { Client } from '@elastic/elasticsearch'; +import type { IndicesIndexTemplate } from '@elastic/elasticsearch/lib/api/types'; export async function addIntegrationToLogIndexTemplate({ esClient, @@ -20,20 +21,33 @@ export async function addIntegrationToLogIndexTemplate({ name: 'logs', }); + // Remove properties from the GET response that cannot be in the PUT request + const { + created_date: createdDate, + modification_date: modificationDate, + created_date_millis: createdDateMillis, + modified_date_millis: modifiedDateMillis, + ...safeTemplate + } = indexTemplates[0].index_template as IndicesIndexTemplate & { + created_date: number; + created_date_millis: number; + modification_date: number; + modified_date_millis: number; + }; + await esClient.indices.putIndexTemplate({ name: 'logs', - ...indexTemplates[0].index_template, + ...safeTemplate, _meta: { - ...indexTemplates[0].index_template._meta, + ...safeTemplate._meta, package: { name, }, managed_by: managedBy, }, // PUT expects string[] while GET might return string | string[] - ignore_missing_component_templates: indexTemplates[0].index_template - .ignore_missing_component_templates - ? [indexTemplates[0].index_template.ignore_missing_component_templates].flat() + ignore_missing_component_templates: safeTemplate.ignore_missing_component_templates + ? [safeTemplate.ignore_missing_component_templates].flat() : undefined, }); } @@ -43,18 +57,31 @@ export async function cleanLogIndexTemplate({ esClient }: { esClient: Client }) name: 'logs', }); + // Remove properties from the GET response that cannot be in the PUT request + const { + created_date: createdDate, + modification_date: modificationDate, + created_date_millis: createdDateMillis, + modified_date_millis: modifiedDateMillis, + ...safeTemplate + } = indexTemplates[0].index_template as IndicesIndexTemplate & { + created_date: number; + created_date_millis: number; + modification_date: number; + modified_date_millis: number; + }; + await esClient.indices.putIndexTemplate({ name: 'logs', - ...indexTemplates[0].index_template, + ...safeTemplate, _meta: { - ...indexTemplates[0].index_template._meta, + ...safeTemplate._meta, package: undefined, managed_by: undefined, }, // PUT expects string[] while GET might return string | string[] - ignore_missing_component_templates: indexTemplates[0].index_template - .ignore_missing_component_templates - ? [indexTemplates[0].index_template.ignore_missing_component_templates].flat() + ignore_missing_component_templates: safeTemplate.ignore_missing_component_templates + ? [safeTemplate.ignore_missing_component_templates].flat() : undefined, }); }