Skip to content

Commit cf016b5

Browse files
committed
Refactor per code review
1 parent 0e5ac7d commit cf016b5

File tree

1 file changed

+11
-16
lines changed
  • x-pack/plugins/fleet/server/services/epm/elasticsearch/template

1 file changed

+11
-16
lines changed

Diff for: x-pack/plugins/fleet/server/services/epm/elasticsearch/template/template.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -645,21 +645,16 @@ const updateExistingDataStream = async ({
645645
esClient: ElasticsearchClient;
646646
logger: Logger;
647647
}) => {
648-
const dataStreamResponse = await esClient.indices.getDataStream({ name: dataStreamName });
649-
const currentBackingIndex =
650-
dataStreamResponse.data_streams[0].indices[
651-
dataStreamResponse.data_streams[0].indices.length - 1
652-
];
653-
654-
const currentBackingIndexData = (
655-
await esClient.indices.get({
656-
index: currentBackingIndex.index_name,
657-
})
658-
)[currentBackingIndex.index_name];
659-
660-
const currentIndexMode = currentBackingIndexData.settings?.index?.mode;
661-
// @ts-expect-error
662-
const currentSourceType = currentBackingIndexData.mappings?._source?.mode;
648+
const existingDs = await esClient.indices.get({
649+
index: dataStreamName,
650+
});
651+
652+
const existingDsConfig = Object.values(existingDs);
653+
const currentBackingIndexConfig = existingDsConfig[existingDsConfig.length - 1];
654+
655+
const currentIndexMode = currentBackingIndexConfig?.settings?.index?.mode;
656+
// @ts-expect-error Property 'mode' does not exist on type 'MappingSourceField'
657+
const currentSourceType = currentBackingIndexConfig.mappings?._source?.mode;
663658

664659
let settings: IndicesIndexSettings;
665660
let mappings: MappingTypeMapping;
@@ -705,7 +700,7 @@ const updateExistingDataStream = async ({
705700
// Trigger a rollover if the index mode or source type has changed
706701
if (
707702
currentIndexMode !== settings?.index?.mode ||
708-
// @ts-expect-error
703+
// @ts-expect-error Property 'mode' does not exist on type 'MappingSourceField'
709704
currentSourceType !== mappings?._source?.mode
710705
) {
711706
logger.debug(

0 commit comments

Comments
 (0)