To set up sorting by attribute,
you need to understand how replica indices work.
Convert dates into Unix timestamps: an example
Before
Say you have an index calledarticles:
JSON
After
You want to create a replica that sorts your data by date. The problem is that thepost_date attribute has dates formatted as strings, which Algolia can’t process for sorting. Before creating a replica, you must transform these dates into Unix timestamps.
You don’t have to remove or change post_date. Add a post_date_timestamp attribute with the proper format instead.
JSON
Create a replica
Create a replica of yourarticles index.
The recommendation is to name your replica indices with a prefix or suffix describing its sorting strategy (for example, articles_date_desc).
1
Create replica
Create a standard or virtual replica (
articles_date_desc) from the primary index.
The primary index is likely sorted by relevance but you want to change that for articles_date_desc.2
Sort the records
Use the
post_date_timestamp attribute to sort the articles_date_desc virtual index by date in descending order:Sort a standard replica
Sort a standard replica
You can put other components inside Accordions.
Sort a virtual replica
Sort a virtual replica