How to re-indexing in Magento2 is a common question. Right now there are two options ‘Update on save’ and ‘Update by schedule’. but there is no option for manual re-index in Magento2 admin side. You can change mode and reindex via commandline.
I) View indexer status from from store admin side:
You can view current index status from below admin side location:
admin-> System-> Tools-> Index management
II) Manage indexer from commandline:
To run Magento commands you need to login to terminal and then go to your project root using below commands (assume your project name is ‘magento213’):
Xampp : cd /opt/lampp/htdocs/magento213
Ubuntu : cd /var/www/magento213
CentOS : cd /var/www/html/magento213
Windows : cd /d/xampp/htdocs/magento213
1) Shows allowed Indexers
Below command is used to list all allowed indexers.
php bin/magento indexer:info
2) Shows status of Indexer
Below command is used to view the status of all indexers. It helps to determine whether indexers need to be reindexed or not.
php bin/magento indexer:status
3) Reindexes Data
This command is used to reindex all indexers. Reindexing all indexers can take a long time for stores with large numbers of products, customers, categories, and promotional rules.
php bin/magento indexer:reindex
4) Shows Index Mode
This command is used to view the current configuration mode of all indexers.
php bin/magento indexer:show-mode
5) Sets index mode type
This command is used to set all indexer mode. There are two options ‘Update on save’ and ‘Update by schedule’.
5a) Update on save (realtime): This is the default mode. Indexed data is updated as soon as a change is made in the Admin. (For example, the category products index is reindex after products are added to a category in the Admin).
Below command is used to set indexer mode into ‘Update by Save’.
php bin/magento indexer:set-mode realtime catalog_category_product
5b) Update by schedule (schedule): Data is indexed according to the schedule set by your Magento cron job.
Below command is used to set indexer mode into ‘Update by Schedule’
php bin/magento indexer:set-mode schedule catalog_category_product
6) Reset indexer status to invalid
Below command is used to reset/invalidate all indexer.
php bin/magento indexer:reset
Also you can manage single indexer by specifying its name with command. For example if you want to reindex ‘Category Products’ indexer then run below command in terminal.
php bin/magento indexer:reindex catalog_category_product
Errors and solution
Warning: file_put_contents(/opt/lampp/htdocs/magento213/var/cache//mage-tags/mage—977_CONFIG): failed to open stream: Permission denied in /opt/lampp/htdocs/magent
o213/vendor/colinmollenhour/cache-backend-file/File.php on line 663
Solution: Give full permission (777) to ‘var/’ folder will resolve this issue.
Please note that reindexing all indexers can take a long time for stores with large numbers of products, customers, categories, and promotional rules.
Thank you for reading this post!!!