This commit is contained in:
parent
4ff9bfd113
commit
86d4054930
|
@ -47,10 +47,15 @@ function getMaxImpactScore(scores: number[]) {
|
|||
export function processSignificantTermAggs({
|
||||
sigTermAggs,
|
||||
}: {
|
||||
sigTermAggs: Record<string, SigTermAgg>;
|
||||
sigTermAggs: Record<string, SigTermAgg | object>;
|
||||
}) {
|
||||
const significantTerms = Object.entries(sigTermAggs).flatMap(
|
||||
([fieldName, agg]) => {
|
||||
const significantTerms = Object.entries(sigTermAggs)
|
||||
// filter entries with buckets, i.e. Significant terms aggs
|
||||
.filter((entry): entry is [string, SigTermAgg] => {
|
||||
const [, agg] = entry;
|
||||
return 'buckets' in agg;
|
||||
})
|
||||
.flatMap(([fieldName, agg]) => {
|
||||
return agg.buckets.map((bucket) => ({
|
||||
fieldName,
|
||||
fieldValue: bucket.key,
|
||||
|
@ -58,8 +63,7 @@ export function processSignificantTermAggs({
|
|||
valueCount: bucket.doc_count,
|
||||
score: bucket.score,
|
||||
}));
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const maxImpactScore = getMaxImpactScore(
|
||||
significantTerms.map(({ score }) => score)
|
||||
|
|
Loading…
Reference in a new issue