One of the common errors that Magento 2 users may face is the “One or more indexers are invalid” error. This error means that some of the indexers in your Magento 2 store are not up to date and need to be reindexed.
Indexers are processes that transform data from the database into a format that is optimized for faster queries and display on the frontend. For example, indexers can create flat tables for products and categories, calculate prices and discounts, update stock status and availability, etc. Indexing is essential for the performance and functionality of your Magento 2 store.
However, sometimes the indexers may become invalid due to various reasons, such as changes in the configuration, products, categories, attributes, etc. When this happens, you may see the “One or more indexers are invalid” error message in the admin panel or on the command line. This error can affect the accuracy and speed of your store and cause problems for your customers.
Fortunately, fixing this error is not very difficult. You just need to run the reindex command to update the indexers and make them valid again. There are two ways to do this: using the admin panel or using the command line.
Using the Admin Panel
The easiest way to reindex your Magento 2 store is to use the admin panel. Here are the steps to follow:
- Log in to your Magento 2 admin panel and navigate to System > Tools > Index Management.
- You will see a list of all the indexers in your store and their status. The ones that are invalid will have a red icon and a message saying “Reindex required”.
- Select the checkbox next to the invalid indexers that you want to reindex. You can also select all of them by clicking on the checkbox in the header row.
- From the Actions dropdown menu, choose Update on Save or Update by Schedule, depending on your preference. The former option will reindex the selected indexers immediately, while the latter option will reindex them according to a cron schedule that you can configure in Stores > Configuration > Advanced > System > Cron.
- Click on Submit to apply the changes.
- Wait for a few minutes until the reindexing process is completed. You can check the progress by refreshing the page or by looking at the status column. The indexers that are valid will have a green icon and a message saying “Ready”.
- Congratulations! You have successfully fixed the “One or more indexers are invalid” error in Magento 2 using the admin panel.
Using the Command Line
Another way to reindex your Magento 2 store is to use the command line. This method may be faster and more convenient for some users, especially if you have access to SSH or a terminal emulator. Here are the steps to follow:
- Connect to your Magento 2 server via SSH or open a terminal emulator on your local machine.
- Navigate to your Magento 2 root directory using the
cd
command. For example, if your Magento 2 installation is located at/var/www/html/magento2
, then typecd /var/www/html/magento2
and press Enter. - Run the following command to see a list of all the indexers in your store and their status:
php bin/magento indexer:status
- You will see something like this:
+----------------------+------------------+-----------+-----------------+------------------+
| Title | Status | Update On | Schedule Status | Schedule Updated |
+----------------------+------------------+-----------+-----------------+------------------+
| Catalog Product Rule | Ready | Save | idle | 2021-05-20 00:40 |
| Catalog Rule Product | Ready | Save | idle | 2021-05-20 00:40 |
| Catalog Search | Reindex required | Save | idle | 2021-05-20 00:40 |
| Category Products | Ready | Save | idle | 2021-05-20 00:40 |
| Customer Grid | Ready | Save | idle | 2021-05-20 00:40 |
| Design Config Grid | Ready | Save | idle | 2021-05-20 00:40 |
| Product Categories | Ready | Save | idle | 2021-05-20 00:40 |
| Product EAV | Reindex required | Save | idle | 2021-05-20 00:40 |
| Product Price | Reindex required | Save | idle | 2021-05-20 00:40 |
| Stock | Reindex required | Save | idle | 2021-05-20 00:40 |
+----------------------+------------------+-----------+-----------------+------------------+
The ones that are invalid will have a status of “Reindex required”.
- Run the following command to reindex all the invalid indexers at once:
php bin/magento indexer:reindex
- Wait for a few minutes until the reindexing process is completed. You will see something like this:
Catalog Search indexer process unknown error:
No alive nodes found in your cluster
Product EAV indexer process unknown error:
No alive nodes found in your cluster
Product Price indexer process unknown error:
No alive nodes found in your cluster
Stock indexer process unknown error:
No alive nodes found in your cluster
This means that the reindexing process has finished successfully.
- Run the following command again to verify that all the indexers are valid:
php bin/magento indexer:status
- You will see something like this:
“`
+———————-+——–+———–+—————–+——————+
| Title | Status | Update On | Schedule Status | Schedule Updated |
+———————-+——–+———–+—————–+——————+
| Catalog Product Rule | Ready | Save | idle | 2021-05-20 00:46 |
| Catalog Rule Product | Ready | Save | idle | 2021-05-20 00:46 |
| Catalog Search | Ready | Save | idle | 2021-05-20 00:46 |
| Category Products | Ready | Save | idle | 2021-05-20 00:46 |
| Customer Grid | Ready | Save | idle | 2021-05-20 00:46 |
| Design Config Grid | Ready | Save | idle | 2021-05-20 00:46 |
| Product Categories | Ready | Save | idle |
We hope this article has helped you to troubleshoot and resolve this common Magento 2 error. If you have any questions or feedback, please feel free to leave a comment below.