在 Magento 2 中重新索引的步骤:
第 1 步:索引锁定时重新索引
运行以下命令来重新索引:
1
|
php bin/magento indexer:reindex
|
您会发现库存流程被跳过,如下所示
1
2
3
4
5
6
7
8
9
10
|
Design Config Grid index has been rebuilt successfully in 00:00:04
Customer Grid index has been rebuilt successfully in 00:00:06
Category Products index has been rebuilt successfully in 00:00:02
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:00
Catalog Search index has been rebuilt successfully in 00:00:04
Stock index is locked by another reindex process. Skipping.
Catalog Rule Product index has been rebuilt successfully in 00:00:00
Catalog Product Rule index has been rebuilt successfully in 00:00:00
|
第 2 步:获取索引类型信息
首先,您必须查看 Magento 2 的索引类型列表,然后运行以下命令:
1
|
php bin/magento indexer:info
|
运行该命令后,您将得到以下输出:
1
2
3
4
5
6
7
8
9
10
|
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
|
步骤 3:检查索引类型状态
现在通过运行下面给出的命令检查所有索引类型的状态:
1
|
php bin/magento indexer:status
|
运行该命令后,您将得到以下输出:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
+---------------------------+----------------------+--------+-----------+-----------------+------------------+
| ID | Title | Status | Update On | Schedule Status | Schedule Updated |
+---------------------------+----------------------+--------+-----------+-----------------+------------------+
| catalogrule_product | Catalog Product Rule | Ready | Save | | |
| catalogrule_rule | Catalog Rule Product | Ready | Save | | |
| catalogsearch_fulltext | Catalog Search | Ready | Save | | |
| catalog_category_product | Category Products | Ready | Save | | |
| customer_grid | Customer Grid | Ready | Save | | |
| design_config_grid | Design Config Grid | Ready | Save | | |
| inventory | Inventory | Ready | Save | | |
| catalog_product_category | Product Categories | Ready | Save | | |
| catalog_product_attribute | Product EAV | Ready | Save | | |
| catalog_product_price | Product Price | Ready | Save | | |
| cataloginventory_stock | Stock |Processing| Save | | |
+---------------------------+----------------------+--------+-----------+-----------------+------------------+
|
步骤 4: 重置索引类型
为了解决这个问题,您必须重置在给定命令下运行的锁定索引类型:
1
|
php bin/magento indexer:reset
|
要重置多个索引类型,请运行以下命令:
1
|
php bin/magento indexer:reset IndexType1 IndexType2 IndexType3
|
这里只有一种索引类型被锁定,因此我们将运行以下给出的命令:
1
|
php bin/magento indexer:reset cataloginventory_stock
|
运行上述命令后的输出将类似于:
1
|
Stock indexer has been invalidated.
|
第 5 步:重新索引索引类型
您必须再次检查索引器状态,因此再次运行以下命令:
1
|
php bin/magento indexer:status
|
运行上述命令后的输出将是:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
+---------------------------+----------------------+------------------+-----------+-----------------+------------------+
| ID | Title | Status | Update On | Schedule Status | Schedule Updated |
+---------------------------+----------------------+------------------+-----------+-----------------+------------------+
| catalogrule_product | Catalog Product Rule | Ready | Save | | |
| catalogrule_rule | Catalog Rule Product | Ready | Save | | |
| catalogsearch_fulltext | Catalog Search | Ready | Save | | |
| catalog_category_product | Category Products | Ready | Save | | |
| customer_grid | Customer Grid | Ready | Save | | |
| design_config_grid | Design Config Grid | Ready | Save | | |
| inventory | Inventory | Ready | Save | | |
| catalog_product_category | Product Categories | Ready | Save | | |
| catalog_product_attribute | Product EAV | Ready | Save | | |
| catalog_product_price | Product Price | Ready | Save | | |
| cataloginventory_stock | Stock | Reindex required | Save |
|