Magento 2: How to Reindex via Command Line

In this blog, I am going to show you how to reindex Magento 2 indexers using command line interface.

Index Management:

Magento follows EAV (Entity Attribute Value) database structure that stores data (including catalog data, prices, users, stores, and so on) in many database tables. So to get the single record, we have to create multiple query relations in Magento. This will be affecting the performance of the web store. To overcome this performance issue, Magento stores most important data into special tables using indexers. But it’s very important to keep those indexers up-to-date to show actual data on the storefront.

For example, when updating a product price on Magento, the data should be reindexed to be correctly displayed on the storefront.

To reindex Magento 2 indexers, we can use the following ways

  • Reindex via a CRON job.
  • Reindex via command line interface.

Here, I am going to show you how to reindex Magento 2 indexers using command line interface.

Get List of Indexers:

Navigate to Magento 2 installed root directory on CLI and run the below command to get the list of all the indexers present in Magento 2.

php bin/magento indexer:info

This will be returned the output as follows:

design_config_grid               Design Config Grid
customer_grid                    Customer Grid
catalog_category_product         Category Products
catalog_product_category         Product Categories
catalog_product_price            Product Price
catalog_product_attribute        Product EAV
cataloginventory_stock           Stock
catalogsearch_fulltext           Catalog Search
catalogrule_rule                 Catalog Rule Product
catalogrule_product              Catalog Product Rule

View Indexer Status:

Run the below command on CLI to check the indexers status,

php bin/magento indexer:status

This will be returned the output as follows:

Design Config Grid:        Ready
Customer Grid:             Ready
Category Products:         Ready
Product Categories:        Ready
Product Price:             Reindex required
Product EAV:               Reindex required
Stock:                     Ready
Catalog Search:            Ready
Catalog Rule Product:      Reindex required
Catalog Product Rule:      Reindex required

Run the below command on CLI to check the specific indexer status,

php bin/magento indexer:status catalog_category_product

Reindex Magento 2 Indexers:

To reindex Magento 2 indexers, run the following command on CLI,

php bin/magento indexer:reindex

This will be returned the output as follows:

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

To reindex specific Magento 2 indexer, run the following command on CLI,

php bin/magento indexer:reindex catalog_category_product

To reindex two or more Magento 2 indexers, run the following command on CLI,

php bin/magento indexer:reindex catalog_category_product catalog_product_price

Indexer Mode Configuration:

To check Magento 2 indexers mode configuration, run the following command on CLI,

php bin/magento indexer:show-mode

This will be returned the output as follows:

Design Config Grid:      Update on Save
Customer Grid:           Update on Save
Category Products:       Update on Save
Product Categories:      Update on Save
Product Price:           Update on Save
Product EAV:             Update on Save
Stock:                   Update on Save
Catalog Search:          Update on Save
Catalog Rule Product:    Update on Save
Catalog Product Rule:    Update on Save

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *