Skip to content

Commit

Permalink
Minor style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
demjened committed Oct 5, 2022
1 parent 60360fe commit 2f28e1c
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export const getMlInferenceErrors = async (
esClient: ElasticsearchClient
): Promise<MlInferenceError[]> => {
const searchResult = await esClient.search<
unknown,
{
errors: AggregationsMultiBucketAggregateBase<ErrorAggregationBucket>
}
>({
unknown,
{
errors: AggregationsMultiBucketAggregateBase<ErrorAggregationBucket>
}
>({
index: indexName,
body: {
aggs: {
Expand All @@ -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,
Expand Down

0 comments on commit 2f28e1c

Please sign in to comment.