1
0
Эх сурвалжийг харах

feat(elasticsearch-plugin): Allow facetValues size to be configured

Michael Bromley 6 жил өмнө
parent
commit
3a5aff4a4b

+ 4 - 1
packages/elasticsearch-plugin/src/elasticsearch.service.ts

@@ -100,7 +100,10 @@ export class ElasticsearchService {
         elasticSearchBody.size = 0;
         elasticSearchBody.aggs = {
             facetValue: {
-                terms: { field: 'facetValueIds.keyword' },
+                terms: {
+                    field: 'facetValueIds.keyword',
+                    size: this.options.facetValueMaxSize,
+                },
             },
         };
         const { body }: { body: SearchResponseBody<VariantIndexItem> } = await this.client.search({

+ 10 - 1
packages/elasticsearch-plugin/src/plugin.ts

@@ -55,6 +55,15 @@ export interface ElasticsearchOptions {
      * 2000
      */
     batchSize?: number;
+    /**
+     * @description
+     * The maximum number of FacetValues to return from the search query. Internally, this
+     * value sets the "size" property of an Elasticsearch aggregation.
+     *
+     * @default
+     * 50
+     */
+    facetValueMaxSize?: number;
 }
 
 /**
@@ -115,7 +124,7 @@ export class ElasticsearchPlugin implements OnVendureBootstrap, OnVendureClose {
      */
     static init(options: ElasticsearchOptions): Type<ElasticsearchPlugin> {
         const { host, port } = options;
-        this.options = { indexPrefix: 'vendure-', batchSize: 2000, ...options };
+        this.options = { indexPrefix: 'vendure-', batchSize: 2000, facetValueMaxSize: 50, ...options };
         this.client = new Client({
             node: `${host}:${port}`,
         });