Bläddra i källkod

fix(elastic-search-plugin): fix bug with facetValueMaxSize (#1098)

Relates to #1086
Artem Danilov 4 år sedan
förälder
incheckning
725392fe2a
1 ändrade filer med 7 tillägg och 6 borttagningar
  1. 7 6
      packages/elasticsearch-plugin/src/elasticsearch.service.ts

+ 7 - 6
packages/elasticsearch-plugin/src/elasticsearch.service.ts

@@ -267,7 +267,7 @@ export class ElasticsearchService implements OnModuleInit, OnModuleDestroy {
         enabledOnly: boolean = false,
     ): Promise<Array<{ facetValue: FacetValue; count: number }>> {
         const { groupByProduct } = input;
-        const buckets = await this.getDistinctBucketsOfField(ctx, input, enabledOnly, `facetValueIds`);
+        const buckets = await this.getDistinctBucketsOfField(ctx, input, enabledOnly, `facetValueIds`,this.options.searchConfig.facetValueMaxSize);
 
         const facetValues = await this.facetValueService.findByIds(
             ctx,
@@ -297,7 +297,7 @@ export class ElasticsearchService implements OnModuleInit, OnModuleDestroy {
         enabledOnly: boolean = false,
     ): Promise<Array<{ collection: Collection; count: number }>> {
         const { groupByProduct } = input;
-        const buckets = await this.getDistinctBucketsOfField(ctx, input, enabledOnly, `collectionIds`);
+        const buckets = await this.getDistinctBucketsOfField(ctx, input, enabledOnly, `collectionIds`,this.options.searchConfig.collectionMaxSize);
 
         const collections = await this.collectionService.findByIds(
             ctx,
@@ -323,6 +323,7 @@ export class ElasticsearchService implements OnModuleInit, OnModuleDestroy {
         input: ElasticSearchInput,
         enabledOnly: boolean = false,
         field: string,
+        aggregation_max_size: number,
     ): Promise<Array<{ key: string; doc_count: number; total: { value: number } }>> {
         const { indexPrefix } = this.options;
         const { groupByProduct } = input;
@@ -336,16 +337,16 @@ export class ElasticsearchService implements OnModuleInit, OnModuleDestroy {
         elasticSearchBody.from = 0;
         elasticSearchBody.size = 0;
         elasticSearchBody.aggs = {
-            collection: {
+            aggregation_field: {
                 terms: {
                     field,
-                    size: this.options.searchConfig.collectionMaxSize,
+                    size: aggregation_max_size
                 },
             },
         };
 
         if (groupByProduct) {
-            elasticSearchBody.aggs.collection.aggs = {
+            elasticSearchBody.aggs.aggregation_field.aggs = {
                 total: {
                     cardinality: {
                         field: `productId`,
@@ -366,7 +367,7 @@ export class ElasticsearchService implements OnModuleInit, OnModuleDestroy {
             throw e;
         }
 
-        return body.aggregations ? body.aggregations.collection.buckets : [];
+        return body.aggregations ? body.aggregations.aggregation_field.buckets : [];
     }
 
     async priceRange(ctx: RequestContext, input: ElasticSearchInput): Promise<SearchPriceData> {