Read algolia Magento 2 reindex for more information.
Before the Magento data is searchable, it needs to be uploaded to Algolia’s servers and indexed. The indexing queue manages all the synchronization with Algolia’s servers automatically.
The indexing queue processes updates to products, categories, pages, and any other data by sending the updates to Algolia’s servers asynchronously. This way, the data in Magento and on Algolia’s servers will be up to date at all times, providing the best user experience for the customers.
Because the queue processes asynchronously, the Magento administrator does not have to wait after every change until the index is updated.
All queued operations will be stored in the database, in a table called
algoliasearch_queue. By default, the queue will run no more than 10 operations at a time. This amount can be scaled up or down in the settings, to better suit the resources available on the server.
To enable the indexing queue, navigate to System > Configuration > Algolia Search > Indexing Queue/Cron in the Magento administration
To find out how many operations the server can handle, the following process can be followed:
- Turn off the cron job.
- Set the number of operations to process to 10.
- Manually run the indexer.
- Measure how long one run takes.
- If it’s lower than 4 minutes, increase the number of jobs to process.
- Repeat from point 3 until the highest possible value has been found.
Note: the steps mention 4 minutes, and not 5. This is to keep a safe margin with the running of the cron job. It’s best practice to keep a margin in case the cron job is slower than normal due to unforeseen circumstances, like a high server load.
Whenever an operation fails during the processing of the queue, it will be re-triggered to be processed the next time the queue runs. In order to prevent operations from being re-triggered infinitely, the maximum amount of retries can be configured in the settings.
Once the queue is enabled, the process to run it needs to be set up. There are two ways to achieve this.
The preferred way to handle the queue is by processing it at a regular time interval. To do this, the following crontab entry has to be configured.
This crontab will run every five minutes, running the amount of operations set in the configuration (10 by default).
While the crontab entry is preferred to get regular updates to the data when necessary, it’s also possible to manually trigger the indexing jobs. To process the queue manually, run the following command from the command line:
php path/to/magento/bin/magento indexer:reindex algolia_queue_runner
When all operations queued need to be processed at once, the
PROCESS_FULL_QUEUE=1 the parameter needs to be passed when manually processing the queue. Run the following command in the command line to process the complete queue at once:
PROCESS_FULL_QUEUE=1 php path/to/magento/bin/magento indexer:reindex algolia_queue_runner