In some situations,
it makes sense to index a numeric representation of a string attribute,
for example for sorting by clothing size.
Size is usually a string (S, M, L, etc),
but sorting alphabetically will yield strange results (S, L, M).
It makes sense to replace these values with a numeric attribute to sort.
Itβs possible to add a new attribute containing this value by implementing a custom observer.
To make changes to the attributes being indexed, observe the algolia_after_create_product_object event with a custom observer.
Create observer
Create the Observer/TransformAttribute.php file, and add a new Observer class in it.
Modify the code in the execute block as needed.
In this example, the clothing sizes are transformed into numeric values.
Register the observer
To register your observer,
add the following snippet to the etc/events.xml file:
Reindex data
With the custom observer in place, the catalog needs to be reindexed for the changes to take effect. Last modified on August 26, 2026