Skip to content

Commit

Permalink
Merge pull request #265 from swisstopo/bug/assets-263_search-stats-in…
Browse files Browse the repository at this point in the history
…complete

Fix search filter stats
  • Loading branch information
vej-ananas authored Sep 10, 2024
2 parents 7f97dbd + 728c713 commit 2cacac1
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
BulkOperationContainer,
QueryDslNumberRangeQuery,
QueryDslQueryContainer,
SearchRequest,
SearchTotalHits,
} from '@elastic/elasticsearch/lib/api/types';
import { Injectable } from '@nestjs/common';
Expand Down Expand Up @@ -231,16 +232,26 @@ export class AssetSearchService {
doc_count: number;
}

const aggregateGroup = async (query: AssetSearchQuery, operator: string, groupName: string, fieldName?: string) => {
const aggregateGroup = async (
query: AssetSearchQuery,
operator: 'terms' | 'min' | 'max',
groupName: string,
fieldName?: string
) => {
const NUMBER_OF_BUCKETS = 10_000;
const elasticDslQuery = mapQueryToElasticDsl({ ...query, [groupName]: undefined });
const field: { field: string; size?: number } = { field: fieldName ?? groupName, size: NUMBER_OF_BUCKETS };
if (operator !== 'terms') {
delete field.size;
}
return (
await this.elastic.search({
index: INDEX,
size: 0,
query: elasticDslQuery,
track_total_hits: true,
aggs: {
agg: { [operator]: { field: fieldName ?? groupName } },
aggregations: {
agg: { [operator]: field },
},
})
).aggregations?.agg;
Expand Down

0 comments on commit 2cacac1

Please sign in to comment.