Skip to main content
To help users find what they’re looking for straight from the search box, you can use Algolia Rules to automatically apply a filter to results if the query matches a facet value.

Before you begin

Add the records from the example dataset to an Algolia index. Configure color, product_type, and brand as attributes for faceting.

How to create a dynamic filtering rule

In this example for a product catalog, you create a rule that displays products with the “red” value in the color facet if the query contains the word “red”. With the example dataset, this rule limits results to records with “red” in the color attribute. It ignores “red” in other attributes such as brand.

Create the rule in the dashboard

You can add this rule from the Algolia dashboard using either the Visual Editor or the Manual Editor.
  1. In the Algolia dashboard, select your application and index, open Rules, and select New rule > Visual Editor.
  2. Click Set query condition(s), select contains, enter red, and click Apply.
  3. In Consequences, select Filter results. Select the color attribute and the red value, then click Apply. To boost red products while keeping other colors in the results, use Boost categories instead.
  4. Click Add Consequence, expand More consequences, and select Remove word. Enter red in Word(s) and click Apply.
  5. Review the results, click Review and Publish, and click Publish.

Create the rule with the API

To run the code examples on this page, install the latest API client. This example uses the filters parameter. With this approach, you need one rule per filter value. If you have 10 color options, you need 10 rules, one for each color.

Example: one rule per facet

Use one rule to detect values of the color facet and apply the corresponding filter. For example, the query red applies color:red, while black applies color:black. This avoids creating a separate rule for each color.

Create the rule in the dashboard

You can add this rule from the Algolia dashboard using either the Visual Editor or the Manual Editor.
  1. Create a rule with Visual Editor.
  2. Click Set query condition(s) and select contains. Select Match any value of a facet and choose color. Click Apply.
  3. In Consequences, expand More consequences and select Filter / Boost matching attribute. Select color in Facet. The facet must be present in every query condition.
  4. Choose Filter to keep only matching records or Boost to promote them without excluding other records. Set Score from 1 to 50 to control the filter score. If your plan doesn’t support optional filters in rules, select Filter facets to filter the results.
  5. Under Filter type, select Conjunctive to require all matching values or Disjunctive to accept any of them. Click Apply.
  6. Review the results for different color queries, click Review and Publish, and click Publish.

Create the rule with the API

To show the filters applied by this rule as selected options in your search UI, see Show automatically applied filters.

Numerical dynamic filtering

For the query cheap toaster 800w, use one rule to filter by product_type:toaster and another to filter by price < 15. Remove toaster and cheap from the query so the search uses 800w to find matching products. With the example dataset, the query returns the Essentials 800w toaster, priced at $14.99.

Create the rules in the dashboard

You can add these rules from the Algolia dashboard using either the Visual Editor or the Manual Editor.
  1. Open Rules and select New rule > Visual Editor.
  2. Click Set query condition(s), select contains, enter toaster, and click Apply.
  3. In Consequences, select Filter results. Select product_type as the attribute and toaster as the value, then click Apply.
  4. Click Add Consequence, expand More consequences, and select Remove word. Enter toaster in Word(s) and click Apply.
  5. Review the results, click Review and Publish, and click Publish.
Repeat these steps to create the second rule. Use cheap for the condition and removed word, and filter on price < 15.

Create the rules with the API

Filter by brand

Users can enter apple headphones to search for Apple headphones. The rule applies a filter for the Apple brand and removes the matched brand value from the query, leaving headphones as the search term. This extends one rule per facet by also removing the matched brand value from the query. With the example dataset, the query returns Airpods Max. It excludes the Sony headphones, even though their color attribute contains Apple.

Create the rule in the dashboard

You can add this rule from the Algolia dashboard using either the Visual Editor or the Manual Editor.
  1. Open Rules and select New rule > Visual Editor.
  2. Click Set query condition(s) and select contains. Select Match any value of a facet and choose brand. Clear the checkbox for matching plurals, synonyms, and typos, then click Apply.
  3. In Consequences, expand More consequences and select Filter / Boost matching attribute. Select brand in Facet, choose Filter, and click Apply.
  4. Click Add Consequence, expand More consequences, and select Remove word. Select {facet:brand} in Word(s) and click Apply.
  5. Review the results, click Review and Publish, and click Publish.

Create the rule with the API

Example dataset

The examples on this page use the following product catalog records:
JSON

See also

Last modified on September 28, 2026