This feature isn’t available on every plan.
Refer to your pricing plan to see if it’s included.
Update your records
Since optional filters only work with exact matches, you might need to update your records. Using the fast food delivery website as an example, flag restaurants that can deliver within 20 minutes by adding a boolean attribute calledcan_deliver_quickly
and set it to true
or false
for each record.
JSON
How to apply optional filters
To use optional filters, you need to:- Set the attribute as an
attributeForFaceting
at indexing time. You can do this either through the API or the Algolia dashboard. - Add the optional filter to your query with the API.
Using the dashboard
Set the attribute to use for faceting in your Algolia dashboard:- Go to the Algolia dashboard and select your Algolia application.
- On the left sidebar, select Search.
- Select your Algolia index and go to the Configuration tab.
- Under Filtering and Faceting > Facets, click Add an attribute and select the optional filter attributes (for example,
can_deliver_quickly
). - Save your changes.
- In the sidebar, select [Enhance > Rules] Rules.
- Click New rule and select Visual Editor.
- Under Conditions, select Set query condition(s).
- Click Filters. In the Name field, enter the name of your optional filter (for example,
can_deliver_quickly
). In the Value field, entertrue
. - Type something into the Query box, such as
*
(to display all matching records) - Click Apply.

Using the API
Set the attribute to use for faceting withattributesForFaceting
.
For example:
Optional or facet filters
Whether to use optional filters or facet filters depends on your goals:- Use optional filters to boost records.
- Use facet filters if you need to filter out records.