Skip to main content
Sometimes, specific terms can act as cues that you can use to filter search results. You can use positive, negative, or numerical filters:
  • Positive filters include a specific subset of matching records in the results. For example, if a user types “diet” on a restaurant website, return every record that has “low-carb” or “low-fat”.
  • Negative filters exclude matching records from results. For example, if a user types “gluten-free” on a restaurant website, you could filter out any gluten-containing meal.
  • Numerical filters convert text queries into a numerical range. For example, if a user types “cheap” on a website for kitchen appliances, you could filter out anything costing more than $50.

Positive filters

If you want to filter out every non-diet-friendly meal whenever user’s search queries contain the term “diet”, you could use the _tags attribute to categorize meals depending on their individual qualities:
JSON
When users include the term “diet” in their search, you want to automatically return every record that has “low-carb” or “low-fat” in their _tags attribute. Because _tags is already optimized for filtering, you don’t have to set it as an attribute for faceting. You can directly create a new Rule that detects the term “diet” in a query and applies a positive filter on tags “low-carb” and “low-fat”.
To use the term “diet” only for filtering and not as a search term, add a consequence in your rule to remove the word from your query.

Using the API

To run the code examples on this page, install the latest API client. To add a rule, use the saveRule method. When creating a rule, you must define a condition and a consequence.

Using the dashboard

You can add rules 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, and enter diet. Click Apply.
  3. In Consequences, select Filter results. Select _tags as the attribute and low-carb as the value. Add low-fat as another value and join the values with Or. Click Apply.
  4. Click Add Consequence, expand More consequences, and select Remove word. Enter diet in Word(s) and click Apply.
  5. Review the results, click Review and Publish, and click Publish.

Negative filters

To exclude gluten-containing foods from the search results when a user searches for gluten-free meals, do the following:
  1. Create an allergens attribute (with “gluten” as one of the potential values).
  2. Create a rule that filters out records with “gluten” in that attribute.

Example records

JSON

Using the API

Set allergens as an attributesForFaceting in your index:
  • Use the saveRule method to create a rule that detects the term “gluten-free” in a query and applies a negative filter on facet value allergens:gluten.
  • Add a consequence in your rule to remove the word “gluten-free” from your query. This way, it won’t be used as a search term, only for filtering purposes.

Using the dashboard

You can add rules from the Algolia dashboard using either the Visual Editor or the Manual Editor. Before creating the rule, open Configuration > Filtering and Faceting > Facets for your index and add the allergens attribute.
  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, and enter gluten-free. Click Apply.
  3. In Consequences, select Filter results. Select allergens as the attribute, is not as the operator, and gluten as the value. Click Apply.
  4. Click Add Consequence, expand More consequences, and select Remove word. Enter gluten-free in Word(s) and click Apply.
  5. Review the results, click Review and Publish, and click Publish.

Numerical filters

Consider the query “cheap toaster 800w”. You can use Rules to filter the results by “toaster” and “prices under $10” so that the only textual search is the remaining term, “800w”, which could further be used to limit the results with that wattage.

Rule

If query = "cheap toaster" then price < 10 and product_type:toaster.
This requires two rules because each query term applies a different filter.

Using the API

Using the dashboard

You can configure this example from the Algolia dashboard using either the Visual Editor or the Manual Editor.

Preparation

  1. Go to the Algolia dashboard and select your Algolia application.
  2. On the left sidebar, select Search.
  3. Select your Algolia index and open the Configuration tab.
  4. On the Filtering and Facets page, click Add an attribute and select the product_type attribute. Repeat to add price.
In the Visual Editor, set up separate rules for toaster and cheap.
  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, and enter toaster. Click Apply.
  3. In Consequences, select Filter results. Select product_type as the attribute and toaster as the value. Click Apply.
  4. Click Add Consequence, expand More consequences, and select Remove word. Enter toaster in Word(s), then 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 < 10.

See also

Last modified on September 28, 2026