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.

 

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.

 

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.

 

4) Shows Index Mode
This command is used to view the current configuration mode of all indexers.

 

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’.

 

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’

 

6) Reset indexer status to invalid
Below command is used to reset/invalidate all indexer.

 

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.

 

Additional information:
Magento2 provides a command “php bin/magento” to show all command line guide. The result will be like this:

 

Errors and solution
[Exception]
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.

 

Conclusion
Please note that reindexing all indexers can take a long time for stores with large numbers of products, customers, categories, and promotional rules.

You can find Magento 2 pre-launch check list here

Thank you for reading this post!!!