Skip to content

Commit a26d279

Browse files
[Dataset Quality]Fix ES issue with index template updates (#231615)
## Summary closes #231478 closes #231477 As part of this [PR](#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 <[email protected]>
1 parent 9cdbe77 commit a26d279

File tree

1 file changed

+35
-16
lines changed
  • x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams

1 file changed

+35
-16
lines changed

x-pack/solutions/observability/test/dataset_quality_api_integration/tests/data_streams/es_utils.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { Client } from '@elastic/elasticsearch';
9+
import type { IndicesIndexTemplate } from '@elastic/elasticsearch/lib/api/types';
910

1011
export async function addIntegrationToLogIndexTemplate({
1112
esClient,
@@ -20,24 +21,33 @@ export async function addIntegrationToLogIndexTemplate({
2021
name: 'logs',
2122
});
2223

23-
const template = indexTemplates[0].index_template;
24-
// @ts-expect-error `created_date` is a system-managed property that cannot be set
25-
delete template.created_date;
24+
// Remove properties from the GET response that cannot be in the PUT request
25+
const {
26+
created_date: createdDate,
27+
modification_date: modificationDate,
28+
created_date_millis: createdDateMillis,
29+
modified_date_millis: modifiedDateMillis,
30+
...safeTemplate
31+
} = indexTemplates[0].index_template as IndicesIndexTemplate & {
32+
created_date: number;
33+
created_date_millis: number;
34+
modification_date: number;
35+
modified_date_millis: number;
36+
};
2637

2738
await esClient.indices.putIndexTemplate({
2839
name: 'logs',
29-
...template,
40+
...safeTemplate,
3041
_meta: {
31-
...indexTemplates[0].index_template._meta,
42+
...safeTemplate._meta,
3243
package: {
3344
name,
3445
},
3546
managed_by: managedBy,
3647
},
3748
// PUT expects string[] while GET might return string | string[]
38-
ignore_missing_component_templates: indexTemplates[0].index_template
39-
.ignore_missing_component_templates
40-
? [indexTemplates[0].index_template.ignore_missing_component_templates].flat()
49+
ignore_missing_component_templates: safeTemplate.ignore_missing_component_templates
50+
? [safeTemplate.ignore_missing_component_templates].flat()
4151
: undefined,
4252
});
4353
}
@@ -47,22 +57,31 @@ export async function cleanLogIndexTemplate({ esClient }: { esClient: Client })
4757
name: 'logs',
4858
});
4959

50-
const template = indexTemplates[0].index_template;
51-
// @ts-expect-error `created_date` is a system-managed property that cannot be set
52-
delete template.created_date;
60+
// Remove properties from the GET response that cannot be in the PUT request
61+
const {
62+
created_date: createdDate,
63+
modification_date: modificationDate,
64+
created_date_millis: createdDateMillis,
65+
modified_date_millis: modifiedDateMillis,
66+
...safeTemplate
67+
} = indexTemplates[0].index_template as IndicesIndexTemplate & {
68+
created_date: number;
69+
created_date_millis: number;
70+
modification_date: number;
71+
modified_date_millis: number;
72+
};
5373

5474
await esClient.indices.putIndexTemplate({
5575
name: 'logs',
56-
...template,
76+
...safeTemplate,
5777
_meta: {
58-
...indexTemplates[0].index_template._meta,
78+
...safeTemplate._meta,
5979
package: undefined,
6080
managed_by: undefined,
6181
},
6282
// PUT expects string[] while GET might return string | string[]
63-
ignore_missing_component_templates: indexTemplates[0].index_template
64-
.ignore_missing_component_templates
65-
? [indexTemplates[0].index_template.ignore_missing_component_templates].flat()
83+
ignore_missing_component_templates: safeTemplate.ignore_missing_component_templates
84+
? [safeTemplate.ignore_missing_component_templates].flat()
6685
: undefined,
6786
});
6887
}

0 commit comments

Comments
 (0)