Algolia limits individual record size for performance reasons. The limits depend on your plan. If a record is larger than the threshold, Algolia returns the error message Record is too big
.
To reduce the amount of errors thrown, the extension truncates or skips attributes with values that are larger than a certain size.
The function below throws the warning error:
\Algolia\AlgoliaSearch\Helper\AlgoliaHelper::prepareRecords()
The private method handleTooBigRecord()
evaluates attributes and flags large ones.
This preventive strategy isn’t always perfect as some attributes are important for search.
How to resolve
There are two options that can resolve this error: upgrading your plan or reducing attribute size.
Upgrading your plan
As mentioned before, record size limits depend on your plan. Upon installation, the extension fetches your plan’s record size limit and saves it to Magento’s configuration data under this path:
algoliasearch_advanced/advanced/max_record_size_limit
If you upgraded your limit, unset this value in the core_config_data
table. This forces the extension to fetch the plan value again and store it. The default value is 10 KB.
From 3.9.1 Algolia extension version and later you can increase the limit in your Magento admin by navigating to Stores > Algolia Search > Credentials and Basic Setup > Advanced > Max record size limit per record.
Reducing attribute size
Attributes like description
, have a lot of content or hidden script tags that aren’t necessary for search. To reduce the size of this attribute, strip the HTML tags before indexing.
To change attributes before indexing, create an observer on the dispatched event for the entity you need.
For products, this event is: algolia_after_create_product_object
Refer to the customization guide for more details on updating attribute data. For this example, you can leverage the native PHP function strip_tags()
to strip the HTML tags out.
Below is an example of the product observer to update the description attribute:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php namespace Your\CustomModule\Observer; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; class AlgoliaAfterCreateProductObject implements ObserverInterface { public function execute(Observer $observer) { $data = $observer->getData('custom_data'); $product = $observer->getData('productObject'); // modify description to strip tags $description = $data->getData('description'); $data->setData('description', strip_tags($description)); } } |