Reindex Magento 2 is the way of transforming data on the front-end so that the users can see it. The data includes products, prices, users and categories etc.
To optimise the performance of your storefront and keep it updated, Magento gathers the data into individual tables using Indexers.
Whenever you change the data, it’s imperative to update/re-index the transformed data. For example, if you improve the price of a product from $5 to $6, Magento must re-index this change in price to make sure it appears on your storefront.
If the indexing is not done, Magento would have to calculate the price of every product on the go, which may take a lot of time.
It can result in cart abandonment and a reduction in sales.
Follow these tips to boost the speed of your Magento Store. Unlike Magento 1, Magento 2 doesn’t have any specific option to perform indexing from CLI. Indexing from Admin Panel is almost identical for both Magento 1 & 2.
As Magento 1 provides shell/indexer.php for indexing, we have Bin/Magento in Magento 2 to manage indexing and more.
#1 Steps to Reindex Magento 2 via Admin are:-
- Go to System > Index Management
- Check the status of Indexers.
- Select the items that are marked as “Reindex required”
- Go to Actions > Update on schedule.
- This will trigger a reindex for selected indexers.
Note:- Sometimes not all indexers can be reindexed using admin reindex. In that case, you have to use CLI/SSH.
#2 Steps to Reindex Magento 2 via SSH/CLI are:-
1. View Indexes
Run the following command to see list of indexes for your Magento site.
php bin/magento indexer:info
2. Different Indexing Modes
There are two indexing modes in Magento: Update on Save and Update by Schedule. Let’s know them better and learn how to use both for Magento reindex.
2.1 Update on Save (Real-time)
In Update on Save mode, data is indexed when the information is changed in the Admin. ( For, e.g. category products index is re-index after products added to a category in the Admin). This is the default.
Magento_Indexer — does the work of handling indexing stuff when the mode is “Update on Save”. It means, no particular line of code or command is required.
2.2 Update by Schedule (Schedule)
MagentoFrameworkMview — When the mode is “Update by Schedule”, Magento uses MagentoFrameworkMview (MySQL trigger) to add the ID of changed data to a changelog table (indexer_reindex_all_invalid) and marks the indexers as invalid.
Data is indexed according to the schedule set by your Magento cron job. Your hosting partner or development team can help you with the cron jobs configuration.
To manually reindex the invalidated indexes, you have to run the following command:
php bin/magento cron:run --group index.
3. How to Show & Set Indexing Modes
3.1 Showing Indexer Mode
Before Setting the indexes, know how to show the indexing modes. Here’s the command for displaying the indexer mode:
php bin/magento indexer:show-mode
3.2 Setting/Changing Indexer Mode
Now to change or set the indexing mode, follow the given command:
php bin/magento indexer:set-mode <indexer name>
Here, we’ve set the indexer mode to Update by Schedule for Catalog rule_Product by using the below command:
php bin/magento indexer:set-mode catalogrule_product.
4. Manual Indexing
There is no need for indexing manually for both the modes. Run the indexing for single or multiple indexers (space-separated list) using below command. Refer the image below for more clarity:
php bin/magento indexer:reindex index1 index2..indexN
This way, you can easy re-index different modes of indexing on your Magento 2 website.
If you still find it challenging to do reindexing in Magento, then you can contact our Magento experts for assistance. ServerGuy also offers Magento hosting services for a secure and high performing store.
You can also leave a comment below, and we will make sure to solve your query.