I can reindex a specific indexer method by following way in Magento 1.x
$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price');
$process->reindexAll();
How to reindex catalog_product_price
indexer in Magento 2.x
We can try with Magento\Framework\Indexer\IndexerInterfaceFactory
.
/**
* @var \Magento\Framework\Indexer\IndexerInterfaceFactory
*/
protected $indexerFactory;
/**
* @param IndexerInterfaceFactory $indexerFactory
*/
public function __construct(
\Magento\Framework\Indexer\IndexerInterfaceFactory $indexerFactory,
) {
$this->indexerFactory = $indexerFactory;
}
/**
* @param string $indexerId
* @return \Magento\Framework\Indexer\IndexerInterface
*/
public function getIndexer($indexerId)
{
return $this->indexerFactory->create()->load($indexerId);
}
public function executeIndex() {
this->getIndexer('catalog_product_price')->reindexAll();
}
\Magento\Framework\Indexer\IndexerInterfaceFactory
to the current constructor.
Commented
Dec 7, 2016 at 12:59
$this->indexerFactory->create()->load('catalog_product_price')->reindexAll()
in the execute method.
Commented
Dec 7, 2016 at 13:08