Skip to content

Commit

Permalink
fix(elasticsearch-plugin): Fix search multichannel indexing issue
Browse files Browse the repository at this point in the history
Relates to #3012
  • Loading branch information
michaelbromley committed Sep 2, 2024
1 parent 75ed6e1 commit 9d6f9cf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/elasticsearch-plugin/src/indexing/indexer.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
if (!product) {
return;
}

let updatedProductVariants: ProductVariant[] = [];
try {
updatedProductVariants = await this.connection.rawConnection.getRepository(ProductVariant).find({
Expand Down Expand Up @@ -541,6 +540,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
languageVariants.push(...variant.translations.map(t => t.languageCode));

const uniqueLanguageVariants = unique(languageVariants);
const originalChannel = ctx.channel;
for (const channel of product.channels) {
ctx.setChannel(channel);
const variantsInChannel = updatedProductVariants.filter(v =>
Expand Down Expand Up @@ -623,6 +623,7 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes
}
}
}
ctx.setChannel(originalChannel);

// Because we can have a huge amount of variant for 1 product, we also chunk update operations
await this.executeBulkOperationsByChunks(
Expand Down Expand Up @@ -944,7 +945,13 @@ export class ElasticsearchIndexerController implements OnModuleInit, OnModuleDes

const productCustomMappings = Object.entries(this.options.customProductMappings);
for (const [name, def] of productCustomMappings) {
item[`product-${name}`] = await def.valueFn(v.product, variants, languageCode, this.injector, ctx);
item[`product-${name}`] = await def.valueFn(
v.product,
variants,
languageCode,
this.injector,
ctx,
);
}
return item;
} catch (err: any) {
Expand Down

0 comments on commit 9d6f9cf

Please sign in to comment.