Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

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

export async function addIntegrationToLogIndexTemplate({
esClient,
Expand All @@ -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,
});
}
Expand All @@ -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,
});
}