diff --git a/src/storage/elasticsearch/aggregations.ts b/src/storage/elasticsearch/aggregations.ts index 114755ba..d7bdcadb 100644 --- a/src/storage/elasticsearch/aggregations.ts +++ b/src/storage/elasticsearch/aggregations.ts @@ -64,7 +64,7 @@ export function parseAggregations( // this should always be true in theory... if (isESTermsFilter(field) && isBucketAggregation(realField) && realField.buckets.length > 0) { - facets.push({ + const facet: SCFacet = { buckets: realField.buckets.map((bucket) => { return { count: bucket.doc_count, @@ -72,9 +72,12 @@ export function parseAggregations( }; }), field: fieldName, - onlyOnType: isESAggMatchAllFilter(type.filter) - ? undefined : type.filter.type.value as SCThingType, - }); + }; + // if it's not for all types then create the appropriate field and set the type name + if (!isESAggMatchAllFilter(type.filter)) { + facet.onlyOnType = type.filter.type.value as SCThingType; + } + facets.push(facet); } } }