Magento 2 Reindexing - One or more indexers are invalid. Make sure your Magento cron job is running

magento.stackexchange https://magento.stackexchange.com/questions/329496

  •  15-04-2021
  •  | 
  •  

Question

I couldn't find the way to do reindexing in mass actions on magento 2.

Seems like you need to run it from cronjob. Is there an alternative way to reindex data in magento 2 from backend or command line just like it used to be in Magento 1.x (php shell/indexer.php -reindexall) ?

enter image description here

Was it helpful?

Solution

to reindex in magento 2, go to the CLI and then the root folder of your magento installation and run the below command :

php bin/magento indexer:reindex

OTHER TIPS

Run this command in your CLI

php bin/magento indexer:reindex

and if you want to reindex only one indexer then write following command:

php bin/magento indexer:reindex indexer_name.

where indexer_name can be found by typing following command :

php bin/magento indexer:info

Here is how you can get things done using Magento 2 CLI indexing commands

Get into your Magento CLI command file available in Magento/bin directory cd magento_folder/bin and run your comamnd directly using magento in terminal or putty.

Here is how it will work for indexing in Magento 2

Get list of available indexer in Magento 2

php bin/magento indexer:info

How to check status of indexer

Following command will get you the status of all the indexer whether indexing is required or ready.

php bin/magento indexer:status

You can also check status of individual indexer: let say i want to check status of catalog_category_product

php bin/magento indexer:status catalog_category_product

How to reindex all available indexing in Magento 2

php bin/magento indexer:reindex

In case you fill memory limit, try this command

php bin/magento -dmemory_limit=2G magento indexer:reindex

Use Magento CLI. Run php bin/magento indexer:reindex from project root directory.

If any index is looping You can reset all index by using
indexer:reset
then use normal reindex

To Reindex from command prompt run below command:

php bin/magento indexer:reindex

Above command should be run from magento root directory

a. Reindex from Magento admin *sometimes not all indexers are reindexed using admin reindex > check also reindex via SSH

  1. Go to System > Index Management and check indexers status
  2. Select the items that are marked as "Reindex required" and go to Actions > Update on schedule

This will trigger a reindex for selected indexers.

Important: Sometimes not all indexers are reindexed using admin reindex even if time & date is showing as updated in magento admin. We recommend to double check the reindex process using the SSH/CLI reindex method presented below.

Reindex mode: You can set your indexers as "Update on Save" and store entities will be indexed when saving admin configurations or as "Update by Schedule" and indexers will be reindexed recurrently (default once / day) . In order for "Update by Schedule" to work ok, make sure your cron jobs are running correctly on your server. Your hosting partner or development team can help you with the cron jobs configuration.

enter image description here

Done!

b. Reindex via SSH / CLI (recommended)

  1. Connect to your Magento 2 installation in the root of your project. (usually in public_html or under yourmagentoinstallation.com/html)

  2. Reindex all Magento 2 indexers using below command:

php bin/magento indexer:reindex

You will receive a similar result as presented below:

Design Config Grid index has been rebuilt successfully in 00:00:00

Customer Grid index has been rebuilt successfully in 00:00:00

Category Products index has been rebuilt successfully in 00:00:00

Product Categories index has been rebuilt successfully in 00:00:00

Product Price index has been rebuilt successfully in 00:00:01

Product EAV index has been rebuilt successfully in 00:00:01

Catalog Search index has been rebuilt successfully in 00:00:01

Stock index has been rebuilt successfully in 00:00:00

Catalog Rule Product index has been rebuilt successfully in 00:00:01

Catalog Product Rule index has been rebuilt successfully in 00:00:00

enter image description here

  1. Check the status of the indexers and identify indexers that still need to be individually reindexed, sometimes general reindex does not work for all indexers

    php bin/magento indexer:status

You will receive a similar result as presented below:

Design Config Grid: Ready

Customer Grid: Ready

Category Products: Ready

Product Categories: Ready

Product Price: Ready

Product EAV: Ready

Catalog Search: Ready

Stock: Ready

Catalog Rule Product: Reindex required

Catalog Product Rule: Ready

enter image description here

  1. Show the list of the indexers and corresponding indexer id that need to be used for individual re-index.

    php bin/magento indexer:info

You will receive a similar result as presented below:

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

enter image description here

  1. Reindex each indexer that has status "Reindex required" using below commands

    php bin/magento indexer:reindex [catalog_category_flat]

Example: php bin/magento indexer:reindex catalogrule_rule

php bin/magento indexer:reindex design_config_grid customer_grid
php bin/magento indexer:reindex catalog_category_product
php bin/magento indexer:reindex catalog_product_category
php bin/magento indexer:reindex catalog_product_price
php bin/magento indexer:reindex catalog_product_attribute
php bin/magento indexer:reindex catalogsearch_fulltext
php bin/magento indexer:reindex cataloginventory_stock
php bin/magento indexer:reindex catalogrule_rule
php bin/magento indexer:reindex catalogrule_product
  1. Check again the status of the indexers using the command from step 2, now all indexers should be "Ready".

Done!

On the Magento root CLI, run the below command

php bin/magento indexer:reset

Then run the below command

php bin/magento indexer:reindex

Alternative solution add php bin/magento indexer:reindex command at cronjob.

I have follow this and it has been working at my system

solved with php bin/magento indexer:reindex

Sometimes to make it easy, you may want to re-index directly from the admin without involving cron (especially if you haven't setup your cron jobs and the site is still in development). In such cases, you can use the free extension Admin Reindex [M2] which allows you to reindex from the admin.

You can re-index by using two different methods.

1- Re-Index from Admin Panel enter image description here

To do so-

Go to System > Tools > Index Management

Select the checkbox next to each type of Indexer to change

Select Indexing Mode from the Acton Dropdown Click Submit

2- Re-Index Using CLI (Command Line Interface)

Run the following Command in your CLI

Bin/magento indexer : reindex [indexer]

To view the list of Indexers-

Run the following Command-

bin/magento indexer : info

Still facing any issue/error, you can read this detailed article on

Magento 2 reindex using command line SSH:
php bin/magento indexer:reset && php bin/magento indexer:reindex

Note:
For performance reasons, Magento recommends that you set all indexers to run on "Update by Schedule" and let cron reindex data. Otherwise, every time an object is saved reindex will happen and lead to high CPU usage and MySQL errors. As a best practice, Magento recommend that you use scheduled indexing.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top