Preparing your documents
To filter and sort search results chronologically, your documents must have at least one field containing a UNIX timestamp. You may also use a string with a date in a format that can be sorted lexicographically, such as"2025-01-13"
.
As an example, consider a database of video games. In this dataset, the release year is formatted as a timestamp:
games
index:
Filtering by date
To filter search results based on their timestamp, add your document’s timestamp field to the list offilterableAttributes
:
filterableAttributes
, you can filter search results by date. The following query only returns games released between 2018 and 2022:
Sorting by date
To sort search results chronologically, add your document’s timestamp field to the list ofsortableAttributes
:
sortableAttributes
, you can sort your search results based on their timestamp. The following query returns all games sorted from most recent to oldest: