diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts index c06d0cdbb6429..dbc93e35c8218 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.test.ts @@ -1900,9 +1900,19 @@ describe('EPM template', () => { it('should fill constant keywords from previous mappings', async () => { const esClient = elasticsearchServiceMock.createElasticsearchClient(); + esClient.indices.getDataStream.mockResponse({ - data_streams: [{ name: 'test-constant.keyword-default' }], + data_streams: [ + { + name: 'test-constant.keyword-default', + indices: [ + { index_name: '.ds-test-constant.keyword-default-0001' }, + { index_name: '.ds-test-constant.keyword-default-0002' }, + ], + }, + ], } as any); + esClient.indices.get.mockResponse({ 'test-constant.keyword-default': { mappings: { @@ -1942,6 +1952,9 @@ describe('EPM template', () => { } as any, }, ]); + expect(esClient.indices.get).toBeCalledWith({ + index: '.ds-test-constant.keyword-default-0002', + }); const putMappingsCalls = esClient.indices.putMapping.mock.calls; expect(putMappingsCalls).toHaveLength(1); expect(putMappingsCalls[0][0]).toEqual({ diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts index b9c0846f3e4f2..96d510b901fa9 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts @@ -1014,8 +1014,13 @@ const updateExistingDataStream = async ({ skipDataStreamRollover?: boolean; }; }) => { + const dataStream = await esClient.indices.getDataStream({ + name: dataStreamName, + expand_wildcards: ['open', 'hidden'], + }); + const existingDs = await esClient.indices.get({ - index: dataStreamName, + index: dataStream?.data_streams?.[0]?.indices?.at(-1)?.index_name ?? dataStreamName, }); const existingDsConfig = Object.values(existingDs);