Filtering result based on date range?

My index is full of Post objects. Posts contain a published_at attribute that reflects when the post went live on our site. I’d like the user to be able to dynamically filter search results so that they can see results from the last day, last week, last month, and last year.

With our current Elastisearch implementation I’m able to achieve this by filtering for results with a published date that is greater than X.

I’m not entirely sure how to do this/if it’s even possible with Algolia. I’ve found this, but it doesn’t seem to achieve what I want since I’m using the ruby gem and making search requests via the backend (which I know isn’t preferred, but works best for our set up).

Any ideas?

1 Like

Actually, I figured this out.

I can use the numericFilters option in the search request.

Yes, you found it!

For future onlookers, here’s a link to some documentation about filters. Since dates in Algolia are represented as numbers, numericFilters are what you want to use in this situation.

1 Like

What would an InstantSearch widget with numericFilters look like?


Using shopify app, indexing is automatic

Unfortunately dates looks like strings :

published_at: 2018-04-12T22:14:11.000-04:00

Or is it just on display and works internally ?

1 Like