From 0c43be2dbe1546409466ccf953e34da638e0976e Mon Sep 17 00:00:00 2001 From: Rainer Killinger Date: Wed, 23 Sep 2020 13:55:23 +0200 Subject: [PATCH] refactor: omit useless facets in response --- src/storage/elasticsearch/aggregations.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/elasticsearch/aggregations.ts b/src/storage/elasticsearch/aggregations.ts index 396c08d2..114755ba 100644 --- a/src/storage/elasticsearch/aggregations.ts +++ b/src/storage/elasticsearch/aggregations.ts @@ -63,7 +63,7 @@ export function parseAggregations( const realField = realType[fieldName]; // this should always be true in theory... - if (isESTermsFilter(field) && isBucketAggregation(realField)) { + if (isESTermsFilter(field) && isBucketAggregation(realField) && realField.buckets.length > 0) { facets.push({ buckets: realField.buckets.map((bucket) => { return { @@ -79,7 +79,7 @@ export function parseAggregations( } } // the last part here means that it is a bucket aggregation - } else if (isESTermsFilter(type) && !isNestedAggregation(realType)) { + } else if (isESTermsFilter(type) && !isNestedAggregation(realType) && realType.buckets.length > 0) { facets.push({ buckets: realType.buckets.map((bucket) => { return {