Magento 2 Reindex / Indexer Usages via Command Line

In this tutorial, we will talk about Reindex / Indexer Usages via Command Line in Command Line Series. With reindexing, Magento 2 store owners can quickly change the store data, decrease the waiting time for customers, and therefore, enhance user experience and conversion rate. As you know, from Magento 2, they add many commands in bin/magento. This may be difficult to get approach this topic, let me explain more detail about it.

Let show all reindex usages by running the following command:

php bin/magento indexer --help

It will show the following:

indexer                                                                                                                     
 indexer:info                              Shows allowed Indexers                                                           
 indexer:reindex                           Reindexes Data                                                                   
 indexer:reset                             Resets indexer status to invalid                                                 
 indexer:set-mode                          Sets index mode type                                                             
 indexer:show-mode                         Shows Index Mode                                                                 
 indexer:status                            Shows status of Indexer  

Indexer command line

Check indexer status by the following command

php bin/magento indexer:info

We will get result:

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
catalogsearch_fulltext                   Catalog Search
cataloginventory_stock                   Stock
catalogrule_rule                         Catalog Rule Product
catalogrule_product                      Catalog Product Rule

How to Reindexe Data

php bin/magento indexer:reindex

How to Reset indexer status to invalid

php bin/magento indexer:reset

How to Show Index Mode

php bin/magento indexer:show-mode

Result:

$ php bin/magento indexer:show-mode

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
Catalog Search:                                    Update on Save
Stock:                                             Update on Save
Catalog Rule Product:                              Update on Save
Catalog Product Rule:                              Update on Save

How to Set index mode type

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

E.g:

magento indexer:set-mode schedule catalog_category_product catalog_product_category

Wrap up

That’s how you can reindex via the command line in Magento 2. I hope this tutorial is helpful for you. If you have any questions, please let me know in the comment section. Thank you for reading!

Enjoyed the tutorial? Spread it to your friends!

magento-2-module-development
command
line
cli
console
indexer
reindex

Sam Thomas
Sam Thomas

CEO and Founder of Mageplaza. Pursueing a simple and healthy lifestyle. A friend, a husband and a dad of two children, a trainer and an influencer wannabe. He is a big fan of sports and travel, also.