En este Tutorial veremos como se configuraran y gestionan los índices en Magento2.
Magento2 nos provee una interfaz de línea de comandos a través de la cual podremos realizar todo tipo de tareas, desde la propia instalación de Magento hasta limpiezas de caches, creación de diccionarios de traducción, etc …
Nos vamos a centrar en un comando en concreto con el que podremos gestionar los índices de Magento2.
Recuerda que son comandos de un solo uso por lo que si queremos que nuestros índices se mantengan actualizados de cualquier tipo de modificación que se realice deberemos crear una tarea programada (cron job) en nuestro servidor.
Si queremos obtener una lista de todos los índices disponibles en Magento2 usaremos el comando indexer:info
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 catalogrule_rule Catalog Rule Product catalog_product_attribute Product EAV catalog_product_price Product Price catalogrule_product Catalog Product Rule cataloginventory_stock Stock catalogsearch_fulltext Catalog Search |
Para comprobar el estado de todos los índices usaremos el comando indexer:status
1 |
$ php ./bin/magento indexer:status |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
+----------------------+--------+-----------+----------------------+---------------------+ | Title | Status | Update On | Schedule Status | Schedule Updated | +----------------------+--------+-----------+----------------------+---------------------+ | Catalog Product Rule | Ready | Schedule | idle (19 in backlog) | 2018-12-30 14:35:41 | | Catalog Rule Product | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:31 | | Catalog Search | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:35 | | Category Products | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:30 | | Customer Grid | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:29 | | Design Config Grid | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:28 | | Product Categories | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:25:59 | | Product EAV | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:32 | | Product Price | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:32 | | Stock | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:33 | +----------------------+--------+-----------+----------------------+---------------------+ |
Si queremos comprobar solo el estado de un índice ó índices:
1 2 3 4 5 6 7 8 |
$ php ./bin/magento indexer:status catalog_product_category catalogrule_rule +----------------------+--------+-----------+---------------------+---------------------+ | Title | Status | Update On | Schedule Status | Schedule Updated | +----------------------+--------+-----------+---------------------+---------------------+ | Catalog Rule Product | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:18:31 | | Product Categories | Ready | Schedule | idle (0 in backlog) | 2019-01-02 11:25:59 | +----------------------+--------+-----------+---------------------+---------------------+ |
Para poder reindexar todos los indices usaremos el comando indexer:reindex
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:01 Customer Grid index has been rebuilt successfully in 00:00:00 Category Products index has been rebuilt successfully in 00:00:01 Product Categories index has been rebuilt successfully in 00:00:00 Catalog Rule Product index has been rebuilt successfully in 00:00:00 Product EAV index has been rebuilt successfully in 00:00:00 Product Price index has been rebuilt successfully in 00:00:00 Catalog Product Rule index has been rebuilt successfully in 00:00:00 Stock index has been rebuilt successfully in 00:00:00 Catalog Search index has been rebuilt successfully in 00:00:02 |
Sino queremos reindexar todos los índices, podremos indicar uno o varios índices a nuestra elección.
1 |
$ php ./bin/magento indexer:reindex catalog_product_category |
Si tenemos problemas con la memoria a la hora de realizar cualquier reindexamiento de índices podemos usar el comando de PHP -dmemory_limit:
1 |
$ php -dmemory_limit=2G ./bin/magento indexer:reindex |
Configuración de índices
Tenemos dos opciones de configuración de índices:
- Actualización en tiempo real (update on save): Por ejemplo, el índice category products será reindexado después de que se incluyan más productos a su categoría.
- Actualización programada (schedule): Los datos son indexados por una tarea programada (cron job).
El comando que usaremos para comprobar nuestra configuración actual es:
1 2 3 4 5 6 7 8 9 10 11 12 |
$ php ./bin/magento indexer:show-mode Design Config Grid: Update by Schedule Customer Grid: Update by Schedule Category Products: Update by Schedule Product Categories: Update by Schedule Catalog Rule Product: Update by Schedule Product EAV: Update by Schedule Product Price: Update by Schedule Catalog Product Rule: Update by Schedule Stock: Update by Schedule Catalog Search: Update by Schedule |
Si queremos comprobar como está configurado un índice seleccionado:
1 |
$ php ./bin/magento indexer:show-mode catalog_product_category |
Para cambiar la configuración de un índice usaremos el comando indexer:set-mode (realtime|schedule)
1 2 3 |
php ./bin/magento indexer:set-mode realtime catalog_product_category Index mode for Indexer Product Categories was changed from 'Update by Schedule' to 'Update on Save' |
Si lo que queremos es cambiarlos todos de una vez bastaría con teclear:
1 |
php ./bin/magento indexer:set-mode schedule |