To sort search results by date in Shopify with Algolia, you need to use a numeric attribute rather than a date string.
Why this is required
Algolia does not sort date strings (such as ISO 8601 formats) directly. Instead, dates must be converted into a numeric format, such as a Unix timestamp, to be used for sorting. Using a numeric timestamp ensures accurate and consistent sorting of results by date.
How to implement date sorting
-
Convert your date to a Unix timestampTransform your date values into a numeric timestamp format.
-
Store the value in a Shopify metafield
- Create a metafield to store the timestamp
- Set the metafield type to Number
-
Index the metafield in AlgoliaEnsure the metafield is included in your records using the Algolia AI Search & Discovery app
-
Configure sorting in Algolia
- Go to Search options in the app
-
Add a custom sort order based on the numeric attribute
Resources