Indexing is how Magento transforms data ( products, categories … ), to improve the performance of your storefront.
Magento stores lots of data (including catalog data, prices, users, stores … ) in many database tables. To optimize storefront performance, Magento accumulates data into special tables using indexers.
For example, you change the price of an item from $4.99 to $3.99. Magento must reindex the price change to display it on your storefront.
Let’s see how to manage, refresh indexers in Magento 2 using command line via SSH
1. Magento 2 indexers
In default, there are 10 indexers:
- Design Config Grid ( name: design_config_grid )
- Customer Grid ( name : customer_grid )
- Category products ( name: catalog_category_product )
- Product categories ( name: catalog_product_category)
- Product price ( name: catalog_product_price)
- Product entity attribute value ( name: catalog_product_attribute)
- Catalog search ( name: catalogsearch_fulltext)
- Stock ( name: cataloginventory_stock)
- Catalog rule product ( name: catalogrule_rule)
- Catalog product rule ( name: catalogrule_product)
We can get indexer info using command:
1 |
php bin/magento indexer:info |
2. Indexer status
An indexer status can be one of following:
- valid: data is synchronized, no reindex required
- invalid: the original data was changed, the index should be updated
- working: indexing is in progress
We can get indexer status using command:
1 |
php bin/magento indexer:status |
3. Indexing modes
Re-indexing can be performed in two modes:
- Update on Save: index tables are updated immediately after the dictionary data ( product, category, store…) is changed.
- Update by Schedule: index tables are updated by cron job according to the configured schedule.
We can check indexer’s mode using command:
1 |
php bin/magento indexer:show-mode |
To change indexer mode, we use command
1 |
php bin/magento indexer:set-mode {realtime|schedule} [indexer-name] |
“realtime” is equal to “Update on Save” and “schedule” is equal to “Update by Schedule”.
4. Re-index
Besides using “System -> Index Management” in Magento backend, we also can re-index using command:
1 |
php bin/magento indexer:reindex [indexer-name] |
We will get the result like:
1 2 3 4 5 6 7 8 9 |
Customer Grid index has been rebuilt successfully in <time> 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> |
5. Reset indexer when it’s locked.
During re-index process, you may get the message like:
1 |
Stock index is locked by another reindex process. Skipping. |
So we need to reset that indexer status to be able to re-index ( in this case, it’s “cataloginventory_stock” )
We can reset indexer using command:
1 |
php bin/magento indexer:reset [indexer-name] |
That’s how we can manage Magento 2 indexers. Please leave a comment or contact us if you have any question.
Thank you!