diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts index f99f7a96158c3..737ece22bb6a8 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/log_threshold_executor.ts @@ -324,22 +324,22 @@ const getReducedGroupByResults = ( key: GroupedSearchQueryResponse['aggregations']['groups']['buckets'][0]['key'] ) => Object.values(key).join(', '); + const reducedGroupByResults: ReducedGroupByResults = []; if (isOptimizedGroupedSearchQueryResponse(results)) { - return results.reduce((acc, groupBucket) => { + for (const groupBucket of results) { const groupName = getGroupName(groupBucket.key); - const groupResult = { name: groupName, documentCount: groupBucket.doc_count }; - return [...acc, groupResult]; - }, []); + reducedGroupByResults.push({ name: groupName, documentCount: groupBucket.doc_count }); + } } else { - return results.reduce((acc, groupBucket) => { + for (const groupBucket of results) { const groupName = getGroupName(groupBucket.key); - const groupResult = { + reducedGroupByResults.push({ name: groupName, documentCount: groupBucket.filtered_results.doc_count, - }; - return [...acc, groupResult]; - }, []); + }); + } } + return reducedGroupByResults; }; export const processGroupByResults = (