Magento 2 Indexer

Magento 2 Indexer, what is it and why is it needed in your Magento 2 store and how do you reindex.

Magento 2 - How to reindex ? #

Indexer #

What is a Indexer ?

A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure.

Magento has a complicated architecture that stores merchant data in many database tables:

  • Catalog Data
  • Prices
  • Users
  • Stores

What Does Reindexing Do #

To optimize frontend performance, data in the list above is accumulated into special tables using indexers called index tables.

Indexer List #

View list of all Magento 2 indexers via command line:

bin/magento indexer:info

Above output for indexer info can be the following:

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

Indexer status #

View the status of all Magento 2 indexers via command line:

php bin/magento indexer:status

The output of index status can be:

+----------------------+--------+-----------+-----------------+------------------+
| Title                | Status | Update On | Schedule Status | Schedule Updated |
+----------------------+--------+-----------+-----------------+------------------+
| Catalog Product Rule | Ready  | Save      |                 |                  |
| Catalog Rule Product | Ready  | Save      |                 |                  |
| Catalog Search       | Ready  | Save      |                 |                  |
| Category Products    | Ready  | Save      |                 |                  |
| Customer Grid        | Ready  | Save      |                 |                  |
| Design Config Grid   | Ready  | Save      |                 |                  |
| Product Categories   | Ready  | Save      |                 |                  |
| Product EAV          | Ready  | Save      |                 |                  |
| Product Price        | Ready  | Save      |                 |                  |
| Stock                | Ready  | Save      |                 |                  |
+----------------------+--------+-----------+-----------------+------------------+

Indexer Mode #

Magento can perform indexing in 2 modes:

  • Update on Save - index tables are updated immediately after data, ex Products, are changed.
  • Update by Schedule - index tables are updated by cron job, ignoring immediate changes, according to the configured schedule.

To view the index mode set for each type you can run the following command:

php bin/magento indexer:show-mode

This will show the modes each index is set to:

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

Indexer Mode Set #

Indexer Mode Set Command Line #

To Specify a index mode for a index type, for example Category Products, you can use command:

php bin/magento indexer:set-mode realtime <type>

To set it to Update on Save or for setting it to Cron schedule, also known as Update by Schedule :

php bin/magento indexer:set-mode schedule <type>

Where <type> is one or multiple of Index list

The output of the mode set can be:

Index mode for Indexer Design Config Grid was changed from 'Update on Save' to 'Update by Schedule'

or

Index mode for Indexer Design Config Grid was changed from 'Update by Schedule' to 'Update on Save'

depending on the <type you chose.

Reindex #

How to reindex in Magento 2 ? This can be done using different ways:

Reindex Command Line #

Magento 2 reindex command line by executing following command:

php bin/magento indexer:reindex

The output of the reindex command should look like:

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

Reindex Backend #

Magento 2 reindex trigger via Admin Area has been removed by decision of the Magento team. Only the option to change the Indexer Mode has been left available to configure. We recommend to have the Indexer Mode on Update on save.

  • Login into the Admin Area
  • Go to System in left area and select Index Management
  • On the Index Management page, in the grid list use Select All or click on the desired Indexer thick.
  • Use the Actions select and set to Updated on save, then click Submit

Reindex Without SSH #

Magento 2 reindex without SSH on demand is not a possibility as the Reindex Backend functionality has been removed.

Need help with Magento 2 Indexer ?