Indexer in Magento 2

This tutorial is about Indexer in Magento 2. First of all lets discuss what is indexing in magento 2? The answer is how Magento 2 transforms data ( products, categories) to improve the performance of your storefront is called indexing.To optimize storefront performance, Magento accumulates data into special tables using indexers. As magento stores lots of data (including catalog data, prices, users, stores) in many database tables.

Lets have an example to clarify the concept. Suppose you changed the price of an item from $4.99 to $3.99. Magento must reindex the changed price to display it on your storefront. Otherwise loading the product information would take a long time, which may result in cart abandonment.

So this was a brief introduction of indexing.Now, lets come to our topic. In this tutorial we will look at different aspects and functionalities of indexing.

Above all lets start learning

indexing in magento 2

We will start with Magento 2 indexers.

Magento 2 indexers

There are basically 10 indexers. we can say that there are 10 default indexers. Which are as follows:

– Design Config Grid ( name: design_config_grid )
– Customer Grid ( name : customer_grid )
– Category products ( name: catalog_category_product )
– Product categories ( name: catalog_product_category)
– Product price ( name: catalog_product_price)
– Product entity attribute value ( name: catalog_product_attribute)
– Catalog search ( name: catalogsearch_fulltext)
– Stock ( name: cataloginventory_stock)
– Catalog rule product ( name: catalogrule_rule)
– Catalog product rule ( name: catalogrule_product)

Furthermore you can look indexer info using following command:

php bin/magento indexer:info

Now we will discuss Indexer status.

Indexer status

An indexer status can be one of following:

– valid: data is synchronized, no reindex required
– invalid: the original data was changed, the index should be updated
– working: indexing is in progress

Similarly you can get indexer status using the following command:

php bin/magento indexer:status

Furthermore lets have a look at Indexing modes.

Indexing modes

Re-indexing can be performed in two modes:

Update on Save: index tables are updated immediately after the dictionary data ( product, category, store…) is changed.
Update by Schedule: index tables are updated by cron job according to the configured schedule.

Similarly you can get indexer status using the following command:

php bin/magento indexer:show-mode

Following command can change indexer mode:

php bin/magento indexer:set-mode {realtime|schedule} [indexer-name]

For the reason that “realtime” is equal to “Update on Save” and “schedule” is equal to “Update by Schedule”.

Re-index

Rather using “System -> Index Management” in Magento backend, we can also re-index using the following command:

php bin/magento indexer:reindex [indexer-name]

You will get the result like:
1 Customer Grid index has been rebuilt successfully in

Futhermore reset indexer when it’s locked.h3>

Reset indexer

During re-index process, you may get the message like:

Stock index is locked by another reindex process. Skipping.

So we need to reset that indexer status to be able to re-index ( in this case, it’s “cataloginventory_stock” )

Similarly you can reset indexer using following command:

php bin/magento indexer:reset [indexer-name]

That’s it from this tutorial. I hope it serves the purpose.

Since these tutorials are for learning purpose please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply