I know I can programatically trigger the indexer to index a list of product ids with the following:

 * @var \Magento\Framework\Indexer\IndexerInterfaceFactory
protected $indexerFactory;

public function __construct(
    \Magento\Framework\Indexer\IndexerInterfaceFactory $indexerFactory,
) {
    $this->indexerFactory = $indexerFactory;


public function execute()
    $productIds = [1,2,3];
    $indexer = $this->indexerFactory->create()->load('catalog_product_flat');

But is there not a cleanest way to do this?

Something like firing and event and passing the ids that need to be reindexed.

| improve this question | | | | |

You can use something like

public function reindexByProductsIds($productIds, $indexLists)
        foreach($indexLists as $indexList) {
            $categoryIndexer = $this->indexerRegistry->get($indexList);
            if (!$categoryIndexer->isScheduled()) {

where $indexLists is an array like ['catalog_product_category', 'catalog_product_attribute']

| improve this answer | | | | |
  • I am already doing something similar, what I am looking for is to do using an observer so I can remove the DI. Thanks for taking the time anyway. – diazwatson Aug 1 '18 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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