Close [x]

Manage the indexers

Edit this page on GitHub

Contents

First steps

  1. Log in to the Magento server as, or switch to, a user who has permissions to write to the Magento file system. One way to do this is to switch to the Magento file system owner.

    If you use the bash shell, you can also use the following syntax to switch to the Magento file system owner and enter the command at the same time:

    su <Magento file system owner> -s /bin/bash -c <command>
    
  2. To run Magento commands from any directory, add <your Magento install dir>/bin to your system PATH.

    Because shells have differing syntax, consult a reference like unix.stackexchange.com.

    bash shell example for CentOS:

    export PATH=$PATH:/var/www/html/magento2/bin
    

You can also run the commands in the following ways:

  • cd <your Magento install dir>/bin and run them as ./magento <command name>
  • php <your Magento install dir>/bin/magento <command name>

<your Magento install dir> is a subdirectory of your web server's docroot. Need help locating the docroot? Click here.

In addition to the command arguments discussed here, see Common arguments.

View the list of indexers

To view the list of indexers to use in the commands discussed in this topic, enter

magento indexer:info

The list displays as follows:

catalog_category_product                 Category Products
catalog_product_category                 Product Categories
catalog_product_price                    Product Price
catalog_product_attribute                Product EAV
cataloginventory_stock                   Stock
catalogrule_rule                         Catalog Rule Product
catalogrule_product                      Catalog Product Rule
catalogsearch_fulltext                   Catalog Search

View indexer status

This command enables you to view the status of all or selected indexers (for example, shows whether indexers need to be reindexed).

Command options:

magento indexer:status [indexer]

where [indexer] is a space-separated list of indexers. Omit [indexer] to view status of all indexers.

To view the list of indexers, enter

magento indexer:info

A sample follows:

magento indexer:status

Sample result:

Category Products:                                 Reindex required
Product Categories:                                Reindex required
Product Price:                                     Reindex required
Product EAV:                                       Reindex required
Stock:                                             Reindex required
Catalog Rule Product:                              Reindex required
Catalog Product Rule:                              Reindex required
Catalog Search:                                    Reindex required

Reindexing is discussed in the next section.

Reindex

This command enables you to reindex all or selected indexers one time only.

This command reindexes one time only. To keep indexers up-to-date, you must set up a cron job.

Command options:

magento indexer:reindex [indexer]

where [indexer] is a space-separated list of indexers. Omit [indexer] to reindex all indexers.

To view the list of indexers, enter

magento indexer:info

A sample follows:

magento indexer:reindex

Sample result:

Category Products index has been rebuilt successfully in <time>
Product Categories index has been rebuilt successfully in <time>
Product Price index has been rebuilt successfully in <time>
Product EAV index has been rebuilt successfully in <time>
Stock index has been rebuilt successfully in <time>
Catalog Rule Product index has been rebuilt successfully in <time>
Catalog Product Rule index has been rebuilt successfully in <time>
Catalog Search index has been rebuilt successfully in <time>

Reindexing all indexers can take a long time for stores with large numbers of products, customers, categories, and promotional rules.

Configure indexers

This command enables you to set the following indexer options:

  • Update on save (realtime): Indexed data is updated as soon as a change is made in the Admin. (For example, the category products index is reindex after products are added to a category in the Admin.) This is the default.
  • Update by schedule (schedule): Data is indexed according to the schedule set by your Magento cron job.

More information about indexing.

Display the current configuration

To view the current indexer configuration, enter

magento indexer:show-mode [indexer]

where [indexer] is a space-separated list of indexers or omit [indexer] to show all indexers’ modes.

For example, to show the mode of all indexers:

magento indexer:show-mode 

Sample result:

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

Configure indexers

To specify the indexer configuration, enter

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

where

realtime sets the selected indexers to update on save. schedule sets the specified indexers to save according to the cron schedule. indexer is a space-separated list of indexers or omit indexer to configure all indexers the same way.

To view the list of indexers, enter

magento indexer:info

For example, to change only the category products and product categories indexers to update on schedule, enter

magento indexer:set-mode schedule catalog_category_product catalog_product_category

Sample result:

Index mode for Indexer Category Products was changed from 'Update on Save' to 'Update by Schedule'
Index mode for Indexer Product Categories was changed from 'Update on Save' to 'Update by Schedule'