66 */
77
88import { Client } from '@elastic/elasticsearch' ;
9+ import type { IndicesIndexTemplate } from '@elastic/elasticsearch/lib/api/types' ;
910
1011export 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