You can reindex only prices for the products in the Magento 2 store by their IDs.
The indexer id used for the prices is catalog_product_price. We need to reindex only prices programmatically to reflect the price changes on the backend. you can do it using the CLI command also,
php bin/magento indexer:reindex catalog_product_price
Using code, check the demo,
<?php namespace Jesadiya\PriceIndexer\Model; use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceIndexerProcessor; class PriceIndexer { public function __construct( private readonly PriceIndexerProcessor $priceIndexProcessor ) { } /** * reindex price * * @param array $productIds * @return void */ public function reindexPrice(array $productIds): void { $this->priceIndexProcessor->reindexList($productIds); } }
Call method with required IDs,
$productIds = [1,2,3];
$this->reindexPrice($productIds);