Catalog index not updating
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Catalog index not updating
Laravel framework version: 9.52.4
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
My catalog index is not updating.
I am importing and updating products the following way:
I'm using ElasticSearch indexing.
The categories just won't appear in the frontend until I do a full index rebuild, using the following console command:
What am I doing wrong here?
By the way the example code here is a very cut down version of what I'm actually using, which includes adding attributes, properties, stock items, checking if the individual items exist before updating them, etc.
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
My catalog index is not updating.
I am importing and updating products the following way:
Code: Select all
// Create managers
$product_manager = \Aimeos\MShop::create( $this->context, 'product' );
$catalog_manager = \Aimeos\MShop::create( $this->context, 'catalog' );
$index_manager = \Aimeos\MShop::create( $this->context, 'index' );
// Begin product changes
$product_manager->begin();
// Get product
$product_item = $product_manager->get( <product id> );
// Remove category list items from product
$category_list_items = $product_item->getListItems( 'catalog', 'default', null, false );
$product_item->deleteListItems( $category_list_items );
// Get category item
$category_item = $catalog_manager->get( <category id> );
// Add category list item to product
$category_list_item = $catalog_manager->createListItem();
$product_item->addListItem( 'catalog', $category_list_item, $category_item );
// Save product
$product_manager->save( $product_item );
// Commit product changes
$product_manager->commit();
Code: Select all
'mshop' => [
'index' => [
'manager' => [
'name' => 'ElasticIndex', // Only index existing products from DB
]
],
],
Code: Select all
php artisan aimeos:jobs index/rebuild
By the way the example code here is a very cut down version of what I'm actually using, which includes adding attributes, properties, stock items, checking if the individual items exist before updating them, etc.
Last edited by kdim95 on 07 Apr 2023, 10:31, edited 1 time in total.
Re: Catalog index not updating
Use the index manager instead of the product manager because the index manager saves the products and updates the index in one step:
Also, you can speed up the import drastically if you use optimized code like this one:
https://github.com/aimeos/ai-controller ... #L133-L140
Code: Select all
$product_manager = \Aimeos\MShop::create( $this->context, 'product' );
$index_manager = \Aimeos\MShop::create( $this->context, 'index' );
$index_manager->begin();
// Get products
$filter = $product_manager->filter()->add( 'product.id', '==', <product ids> );
$product_items = $product_manager->search( $filter );
// Update products ...
// Save products
$index_manager->save( $product_items );
// Finally commit all product changes after e.g. 100 products
$index_manager->commit();
https://github.com/aimeos/ai-controller ... #L133-L140
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Catalog index not updating
Thank you!
By the way I think there is a problem when saving single product items as opposed to arrays of product items
By the way I think there is a problem when saving single product items as opposed to arrays of product items
Code: Select all
$index_manager->begin(); // This is not taken in account
$index_manager->save( $single_product_item ); // Item is saved here without calling $manager->commit()
$index_manager->commit(); // This is not taken in account
Re: Catalog index not updating
What would you say is the average time in seconds to save and index 5,000 products?
It currently takes about 1 minute, maybe less for me.
There are properties, attribute items, catalog items, configs, text items, media items, price items added for each product that is being saved using $index_manager->save( $products ).
It currently takes about 1 minute, maybe less for me.
There are properties, attribute items, catalog items, configs, text items, media items, price items added for each product that is being saved using $index_manager->save( $products ).
Re: Catalog index not updating
It depends a bit on your hardware but you may get more products updated in the same timeframe with optimized code and when saving batches of products at once (250-500 is a good value if you have no memory contraints).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star