From 2f28e1c8b253af6544f7947ff0618854c27dfc52 Mon Sep 17 00:00:00 2001 From: demjened Date: Wed, 5 Oct 2022 18:01:47 -0400 Subject: [PATCH] Minor style changes --- .../get_inference_errors.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/lib/ml_inference_pipeline/get_inference_errors.ts b/x-pack/plugins/enterprise_search/server/lib/ml_inference_pipeline/get_inference_errors.ts index 8386b16eae25..8419dd081d1e 100644 --- a/x-pack/plugins/enterprise_search/server/lib/ml_inference_pipeline/get_inference_errors.ts +++ b/x-pack/plugins/enterprise_search/server/lib/ml_inference_pipeline/get_inference_errors.ts @@ -36,11 +36,11 @@ export const getMlInferenceErrors = async ( esClient: ElasticsearchClient ): Promise => { const searchResult = await esClient.search< - unknown, - { - errors: AggregationsMultiBucketAggregateBase - } - >({ + unknown, + { + errors: AggregationsMultiBucketAggregateBase + } + >({ index: indexName, body: { aggs: { @@ -65,14 +65,16 @@ export const getMlInferenceErrors = async ( } }); - const processorBuckets = searchResult.aggregations?.errors.buckets; - if (!processorBuckets) { + const errorBuckets = searchResult.aggregations?.errors.buckets; + if (!errorBuckets) { return []; } - const buckets = Array.isArray(processorBuckets) - ? processorBuckets - : Object.values(processorBuckets); + // Buckets are either in an array or in a Record, we transform them to an array + const buckets = Array.isArray(errorBuckets) + ? errorBuckets + : Object.values(errorBuckets); + return buckets.map((bucket) => ({ message: bucket.key, doc_count: bucket.doc_count,