diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/install.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/install.ts index 78a80b0f1c90d..7f9649fb8ecc3 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/install.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/install.ts @@ -216,11 +216,10 @@ const installPreBuiltComponentTemplates = async ( const esClientParams = { name: templateName, - body: content, + ...content, }; return retryTransientEsErrors( - // @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584 () => esClient.cluster.putComponentTemplate(esClientParams, { ignore: [404] }), { logger } ); @@ -695,10 +694,9 @@ async function installTemplate({ // TODO: Check return values for errors const esClientParams = { name: template.templateName, - body: template.indexTemplate, + ...template.indexTemplate, }; await retryTransientEsErrors( - // @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584 () => esClient.indices.putIndexTemplate(esClientParams, { ignore: [404] }), { logger } ); diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.test.ts index 1b4ad7c8c0519..5e38053f8b546 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.test.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.test.ts @@ -2037,12 +2037,10 @@ describe('EPM template', () => { expect(putMappingsCalls).toHaveLength(1); expect(putMappingsCalls[0][0]).toEqual({ index: 'test-constant.keyword-default', - body: { - properties: { - some_keyword_field: { - type: 'constant_keyword', - value: 'some_value', - }, + properties: { + some_keyword_field: { + type: 'constant_keyword', + value: 'some_value', }, }, write_index_only: true, @@ -2087,7 +2085,6 @@ describe('EPM template', () => { expect(putMappingsCalls).toHaveLength(1); expect(putMappingsCalls[0][0]).toEqual({ index: 'test-constant.keyword-default', - body: {}, write_index_only: true, }); }); diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.ts index 79f90e1a202e1..d5e720667c8d9 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/template/template.ts @@ -1107,8 +1107,7 @@ const updateExistingDataStream = async ({ () => esClient.indices.putMapping({ index: dataStreamName, - // @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584 - body: mappings, + ...mappings, write_index_only: true, }), { logger } diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/transforms.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/transforms.test.ts index cf8830f33c8cd..496d91c83a002 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/transforms.test.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/elasticsearch/transform/transforms.test.ts @@ -383,21 +383,19 @@ _meta: expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([ [ { - body: { - _meta: meta, - composed_of: [ - 'logs-endpoint.metadata_current-template@package', - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - index_patterns: ['.metrics-endpoint.metadata_united_default'], - priority: 250, - template: { mappings: undefined, settings: undefined }, - ignore_missing_component_templates: [ - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - }, + _meta: meta, + composed_of: [ + 'logs-endpoint.metadata_current-template@package', + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], + index_patterns: ['.metrics-endpoint.metadata_united_default'], + priority: 250, + template: { mappings: undefined, settings: undefined }, + ignore_missing_component_templates: [ + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], name: 'logs-endpoint.metadata_current-template', }, { ignore: [404] }, @@ -673,21 +671,19 @@ _meta: expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([ [ { - body: { - _meta: meta, - composed_of: [ - 'logs-endpoint.metadata_current-template@package', - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - index_patterns: ['.metrics-endpoint.metadata_united_default'], - priority: 250, - template: { mappings: undefined, settings: undefined }, - ignore_missing_component_templates: [ - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - }, + _meta: meta, + composed_of: [ + 'logs-endpoint.metadata_current-template@package', + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], + index_patterns: ['.metrics-endpoint.metadata_united_default'], + priority: 250, + template: { mappings: undefined, settings: undefined }, + ignore_missing_component_templates: [ + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], name: 'logs-endpoint.metadata_current-template', }, { ignore: [404] }, @@ -940,21 +936,19 @@ _meta: expect(esClient.indices.putIndexTemplate.mock.calls).toEqual([ [ { - body: { - _meta: meta, - composed_of: [ - 'logs-endpoint.metadata_current-template@package', - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - index_patterns: ['.metrics-endpoint.metadata_united_default'], - priority: 250, - template: { mappings: undefined, settings: undefined }, - ignore_missing_component_templates: [ - 'endpoint@custom', - 'logs-endpoint.metadata_current-template@custom', - ], - }, + _meta: meta, + composed_of: [ + 'logs-endpoint.metadata_current-template@package', + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], + index_patterns: ['.metrics-endpoint.metadata_united_default'], + priority: 250, + template: { mappings: undefined, settings: undefined }, + ignore_missing_component_templates: [ + 'endpoint@custom', + 'logs-endpoint.metadata_current-template@custom', + ], name: 'logs-endpoint.metadata_current-template', }, { ignore: [404] }, diff --git a/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.test.ts index 17bc3fd4b98f2..cf0cc420d8512 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.test.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.test.ts @@ -269,12 +269,10 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - settings: expect.objectContaining({ - index: expect.objectContaining({ - mapping: expect.objectContaining({ source: { mode: 'synthetic' } }), - }), + template: expect.objectContaining({ + settings: expect.objectContaining({ + index: expect.objectContaining({ + mapping: expect.objectContaining({ source: { mode: 'synthetic' } }), }), }), }), @@ -296,15 +294,13 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - mappings: expect.objectContaining({ - properties: expect.objectContaining({ - sequence: { - type: 'long', - index: false, - }, - }), + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + sequence: { + type: 'long', + index: false, + }, }), }), }), @@ -326,15 +322,13 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - mappings: expect.objectContaining({ - properties: expect.objectContaining({ - name: { - type: 'keyword', - index: false, - }, - }), + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + name: { + type: 'keyword', + index: false, + }, }), }), }), @@ -356,14 +350,12 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - mappings: expect.objectContaining({ - properties: expect.objectContaining({ - '@timestamp': { - type: 'date', - }, - }), + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + '@timestamp': { + type: 'date', + }, }), }), }), @@ -385,11 +377,9 @@ describe('experimental_datastream_features', () => { expect(esClient.indices.getIndexTemplate).toHaveBeenCalled(); expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - settings: expect.objectContaining({ - index: { mode: 'time_series' }, - }), + template: expect.objectContaining({ + settings: expect.objectContaining({ + index: { mode: 'time_series' }, }), }), _meta: { has_experimental_data_stream_indexing_features: true }, @@ -485,12 +475,10 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - settings: expect.objectContaining({ - index: expect.objectContaining({ - mapping: expect.objectContaining({ source: { mode: 'synthetic' } }), - }), + template: expect.objectContaining({ + settings: expect.objectContaining({ + index: expect.objectContaining({ + mapping: expect.objectContaining({ source: { mode: 'synthetic' } }), }), }), }), @@ -512,15 +500,13 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - mappings: expect.objectContaining({ - properties: expect.objectContaining({ - sequence: { - type: 'long', - index: false, - }, - }), + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + sequence: { + type: 'long', + index: false, + }, }), }), }), @@ -542,15 +528,13 @@ describe('experimental_datastream_features', () => { expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - mappings: expect.objectContaining({ - properties: expect.objectContaining({ - name: { - type: 'keyword', - index: false, - }, - }), + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + name: { + type: 'keyword', + index: false, + }, }), }), }), @@ -588,11 +572,9 @@ describe('experimental_datastream_features', () => { expect(esClient.indices.getIndexTemplate).toHaveBeenCalled(); expect(esClient.indices.putIndexTemplate).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - template: expect.objectContaining({ - settings: expect.objectContaining({ - index: { mode: 'time_series' }, - }), + template: expect.objectContaining({ + settings: expect.objectContaining({ + index: { mode: 'time_series' }, }), }), _meta: { has_experimental_data_stream_indexing_features: true }, diff --git a/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.ts b/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.ts index 85fe94152b9bd..12326d47f0728 100644 --- a/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.ts +++ b/x-pack/platform/plugins/shared/fleet/server/services/package_policies/experimental_datastream_features.ts @@ -192,8 +192,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({ await esClient.cluster.putComponentTemplate({ name: componentTemplateName, - // @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584 - body, + ...body, _meta: { has_experimental_data_stream_indexing_features: hasExperimentalDataStreamIndexingFeatures, }, @@ -211,7 +210,7 @@ export async function handleExperimentalDatastreamFeatureOptIn({ settings: { ...(indexTemplate.template?.settings ?? {}), index: { - mode: featureMapEntry.features.tsdb ? 'time_series' : null, + mode: featureMapEntry.features.tsdb ? 'time_series' : undefined, }, }, }, @@ -221,11 +220,14 @@ export async function handleExperimentalDatastreamFeatureOptIn({ await esClient.indices.putIndexTemplate({ name: featureMapEntry.data_stream, - // @ts-expect-error elasticsearch@9.0.0 https://github.com/elastic/elasticsearch-js/issues/2584 - body: indexTemplateBody, + ...indexTemplateBody, _meta: { has_experimental_data_stream_indexing_features: featureMapEntry.features.tsdb, }, + // GET brings string | string[] | undefined but this PUT expects string[] + ignore_missing_component_templates: indexTemplateBody.ignore_missing_component_templates + ? [indexTemplateBody.ignore_missing_component_templates].flat() + : undefined, }); }