refactor: provide 'onlyOnType' facet field only if defined

This commit is contained in:
Jovan Krunić
2020-10-23 09:38:10 +02:00
committed by Rainer Killinger
parent 7d4c27ec26
commit 8dbb3ca19a

View File

@@ -64,7 +64,7 @@ export function parseAggregations(
// this should always be true in theory... // this should always be true in theory...
if (isESTermsFilter(field) && isBucketAggregation(realField) && realField.buckets.length > 0) { if (isESTermsFilter(field) && isBucketAggregation(realField) && realField.buckets.length > 0) {
facets.push({ const facet: SCFacet = {
buckets: realField.buckets.map((bucket) => { buckets: realField.buckets.map((bucket) => {
return { return {
count: bucket.doc_count, count: bucket.doc_count,
@@ -72,9 +72,12 @@ export function parseAggregations(
}; };
}), }),
field: fieldName, 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);
} }
} }
} }