Magento 2 Index Management

In this tutorial, we cover such important Magento 2 aspect as index management. The below post provides all necessary code, as well as descriptions and explanations related to Magento 2 Index Management.
Table of contents
Prerequisites
-
You should be logged in to the Magento server as a user with permission to write to the file system of Magento. For instance, it is enough to switch to the web server user.
-
Now, it’s time to enable Magento commands from any directory; you only have to add the code below to the system PATH.
|
1 |
<your Magento install dir>/bin |
-
Please not that shells often have differing syntax; therefore, you should check or a similar source for more help. This is how the bash shell CentOS example looks like:
|
1 |
export PATH=$PATH://var/www/html/magento2/bin |
These are some other ways to run the commands:
1.
|
1 |
cd <your Magento install dir>/bin |
run them as:
|
1 |
./magento <command name> |
2.
|
1 |
php <your Magento install dir>/bin/magento <command name> |
Please note that <your Magento install dir> is a subdirectory of your web server’s docroot. If you have troubles with locating the docroot, click for help.
More arguments: .
How to view the indexers list
Indexers, used in the commands discussed here, can be displayed with the help of the following command:
|
1 |
magento indexer:info |
The list should look like the following one:
|
1 2 3 4 5 6 7 8 |
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 |
How to get indexer status
By using the below command, you can easily check the status of all indexers, or view just selected ones. This is useful when, for example, you need to know whether indexers need to be reindexed.
|
1 |
magento indexer:status [indexer] |
Please note that by omitting [indexer] you get status of all indexers. If you don’t need all indexers, enter a space-separated list of indexers in [indexer].
The command below will show you the list of indexers:
|
1 |
magento indexer:info |
If you enter the following one:
|
1 |
magento indexer:status |
you will get the below result
|
1 2 3 4 5 6 7 8 |
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
Use the following command to perform reindexing:
|
1 |
magento reindex [indexer] |
By omitting [indexer] you will reindex all indexers. If you don’t need all indexers to be reindexed, place a space-separated list of indexers in [indexer].
Enter
|
1 |
magento indexer:info |
and you will get the list of indexers.
Having run this command:
|
1 |
magento indexer:reindex |
you get the following result:
|
1 2 3 4 5 6 7 8 |
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> |
Please note that reindexing can take a long time in case of large numbers of sore data such as products, categories, customers, and promotional rules.
Indexers Configurations
Additionally, you can set some indexer options. Firstly, you can update on save by using (realtime). This option starts the update of indexed data after every change the Admin. The option is default.
Secondly, it is possible to update indexers by schedule (schedule), so data is indexed according to the Magento cron job schedule.
Additional information about .
How to view current configurations
If you need current indexer configurations, enter the following command:
|
1 |
magento indexer:show-mode [indexer] |
The situation with [indexer] is the same as in the previous cases: it is a space-separated list of indexers, or you can omit it to get all indexers’ modes.
Thus, by using the below command
|
1 |
magento indexer:show-mode |
you will get the following result:
|
1 2 3 4 5 6 7 8 |
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 |
How to configure indexers
Now, we can explain how to to specify the indexer configuration. You just need to enter the following command
|
1 |
magento indexer:set-mode {realtime|schedule} [indexer] |
where
realtime, schedule, and indexer are described above. Choose between realtime and schedule, and perform a necessary action with indexer.
Again, you can view the list of indexers with
|
1 |
magento indexer:info |
Let’s look at an example when you need to change indexers of category products and product categories; you are going to update them on schedule. Your command should look like the following one:
|
1 |
magento indexer:set-mode schedule catalog_category_product catalog_product_category |
You will get the below result:
|
1 2 |
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' |
As you can see, Magento 2 Index Management is a simple task. Now, you can easily perform all the described actions. In case of problems, live your comments below – the Firebear team will always help you.
To check the official documentation, related to index management of Magento 2, visit this page: .
More Magento 2 features, tutorials, and rumours on Firebear





