Is there any way in magento to achieve to reindex only single product or some items.

I have a inventory existing /update call on product page load and cart page load.

Right now doing indexing for all catalog on product page and cart page which is not feasible way.

Any way that can be done get this done?

  • How many products you have?
    – Aman Alam
    Commented Aug 7, 2018 at 19:40
  • 50k simple products.
    – sandip
    Commented Aug 7, 2018 at 19:41
  • Ahh then update on save should not be feasible
    – Aman Alam
    Commented Aug 7, 2018 at 19:42
  • However set cron properly it should update indexer as soon as any value changes.
    – Aman Alam
    Commented Aug 7, 2018 at 19:43
  • 1
    cron should like this php MAGENTO_ROOT/bin/magento indexer:reindex cataloginventory_stock
    – Aman Alam
    Commented Aug 7, 2018 at 19:49

1 Answer 1


Source / Credit / Main article - How to Magento 2 Reindex one Product Programmatically?

Adding code for reference

use Magento\Framework\App\Bootstrap;
require '../app/bootstrap.php';
ini_set('display_errors', 1);
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('Magento\Framework\App\State');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$childIds = $objectManager->get('Magento\ConfigurableProduct\Model\Product\Type\Configurable')->getChildrenIds('371009');//get configurable child item
$productIds = $childIds[0]; 
//$productIds = ['25206']; //pass product id
//list of indexers
$indexLists = ['catalog_category_product', 'catalog_product_category', 'catalog_product_attribute', 'cataloginventory_stock', 'inventory', 'catalogsearch_fulltext', 'catalog_product_price', 'catalogrule_product', 'catalogrule_rule'];
foreach ($indexLists as $indexList) {
    $categoryIndexer = $objectManager->get('Magento\Framework\Indexer\IndexerRegistry')->get($indexList);
    if (!$categoryIndexer->isScheduled()) {
    try {
        echo $indexList . '<br>';
    } catch (\Exception $e) {
        echo $e->getMessage();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.