Magento 2 Reindex: Everything You Need to Know

Magento operates huge loads of information related to categories, products, prices, search results, etc. As you know, all this info is organized in separate tables so the needed details can be fetched promptly.

That's when Magento 2 reindex comes into play. It's a crucial process that keeps all the data relevant and helps to manage your store effectively both on the frontend and backend. Thus, the more you know about reindex in Magento the better.

In this guide, you'll learn what Magento reindex is, how to run it, how to fix reindex-related errors if any, and more. So, let's get to the point. 

What is Magento 2 Reindex?

Magento 2 utilizes indexers to organize all the data it works with. Each data type has its indexer which in turn is responsible for the corresponding index table.

Therefore, there are separate index tables for prices, search terms, and products, to name a few. This way, when the request is sent, Magento fetches the data from these separate tables instead of the main table. 

Whenever you make any changes when operating your store, the data in the corresponding tables must be updated. To do this, you need to reindex your Magento 2. So, reindex is the process of updating the information in the index tables to keep it up-to-date and relevant. 

If you keep your store data relevant you not only enhance the store operation processes but the customer experience as well. This way, your clients will always have relevant information regarding prices, discounts, item availability, and other catalogue details. 

All this leads us to a question: how do you reindex Magento 2? Let's find out!

How to Reindex Magento 2?

Magento 2 reindex runs automatically and is triggered by the applied changes. Yet, in some cases, you might need to reindex Magento manually.

There are two ways to reindex your Magento. First of all, you can do it via the CLI. Alternatively, you can run reindex in the admin panel.

Let's have a look at each of these methods.

Reindex Magento via CLI

To begin with, you can reindex your Magento 2 via the command line. To do that, navigate to your Magento root folder and run the following command:

php bin/magento indexer:reindex

You will get a correspoding result:

Design Config Grid index has been rebuilt successfully in 00:00:00
Customer Grid index has been rebuilt successfully in 00:00:00
Category Products index has been rebuilt successfully in 00:00:01
Product Categories index has been rebuilt successfully in 00:00:00
Catalog Rule Product index has been rebuilt successfully in 00:00:01
Product EAV index has been rebuilt successfully in 00:00:02
Stock index has been rebuilt successfully in 00:00:00
Product Price index has been rebuilt successfully in 00:00:01
Catalog Product Rule index has been rebuilt successfully in 00:00:00
Catalog Search index has been rebuilt successfully in 00:00:02

If there are any particular index types you need to reindex, specify their names in the command shared above:

php bin/magento indexer:reindex [index_type]

Instead of the [index_type] you can use the following:

Design Config Grid

design_config_grid

Customer Grid

customer_grid 

Category Products

catalog_category_product

Product Categories

catalog_product_category

Catalog Rule Product

catalogrule_rule 

Product EAV

catalog_product_attribute

Inventory

inventory

Catalog Product Rule

catalogrule_product

Stock

cataloginventory_stock

Product/Target Rule

targetrule_product_rule

Target Rule/Product

targetrule_rule_product

Product Price

catalog_product_price

Catalog Search

catalogsearch_fulltext

Sales Rule

salesrule_rule

Reindex Magento via Admin Panel

By default, you can't initiate reindex in the admin panel. What you can do is change the Inxeder Mode. To do that, go to System > Index Management, choose the needed indexers, select the Mode from the Action dropdown, and press the Submit button. 

So, once again, you don't reindex Magento 2 from the admin panel. You only change the indexer mode. Then the reindex takes place according to the selected mode.

Magento indexer modes

However, if you have Magento 2 Command Line Extension, you can run the reindex command right from the admin panel. Check out the following video to see how it works.

Magento 2 Reindexing Modes

There are two indexer modes in Magento — Update on Save and Update by Schedule. The first one updates indexes right after the data is changed, while the latter updates indexes by cron.

Using the Update on Schedule mode is recommended since immediate reindexing on every save can slow down your website. This is the case for big stores and large updating volumes.

There is an exception, though. The Customer Grid (customer_grid ) index doesn't support the Update by Schedule reindexing mode. It only works with the Update on Save mode. 

Magento 2 Reindexing Commands

Magento 2 offers some other commands for effective reindex management. Let's review the list of the most common reindex commands and determine what each of them does.

Command

Description 

php bin/magento indexer:reindex

Initiates the reindex of all indexers

php bin/magento indexer:reindex [index_type]

Reindexes a specific index type

php bin/magento indexer:info

Shows the list of all available indexers

php bin/magento indexer:status

Displays the indexers' status

php bin/magento indexer:show-mode

Shows the indexers' mode

php bin/magento indexer:set-mode

Sets the Indexer mode

php bin/magento indexer:reset

Sets the indexer status to Invalid

As useful as Magento 2 reindex is, there is always a risk that something does wrong in the process. The best way to handle those inconsistencies is to be aware of them beforehand.

Let's review some of the common reindex-related issues to see how to fix them.

"Index is locked by another reindex process. Skipping"

As the error message suggests, this error appears when some index type gets locked. Many factors, like limited memory, timeout, PHP issues, etc may cause it. But once the index type gets locked, it is always skipped when running reindex.

This doesn't benefit the process at all. So to fix this error, you need to identify what indexer got locked by running the following command:

php bin/magento indexer:status

If some of the indexers have the Processing status in the list you get, it means they are locked. Thus, you need to reset the corresponding index types:

php bin/magento indexer:reset [index_type]

Then, check the status of the indexer again and run the reindex command for this particular indexer:

php bin/magento indexer:reindex [index_type]

"One or more indexers are invalid"

Another common error you may face — is "One or more indexers are invalid". As you know, usually Magento 2 reindex is performed automatically using crons. But when something goes wrong during the indexing, expect to get this error.

Magento error one or more indexers are invalid

To fix it, you need to check what indexers are not valid, and then reindex them manually using any of the methods described above. Once done, have to double-check the status of your indexers to make sure the issue is resolved.

Magento 2 reindex takes too much time

Magento 2 structure is quite complicated, especially when it comes to the numerous index tables and their complexity. Thus, the reindexing process can sometimes take much more time than expected. This leads to slow data processing and updating.

That's why, you need to optimize Magento 2 reindex. Generally, you need to alter the batch size of the corresponding indexers. Since each of the indexers has its specifics, make sure to learn about them in advance.

Hopefully, now you understand the Magento 2 reindex and issues that may arise during the reindexing process better. With the provided tips, you can continue operating your store and be sure that all the data stays relevant and accurate.