Skip to main content
Algolia supports the following operators, which must be in capital letters:
  • OR: must match any of the combined conditions
  • AND: must match all the combined conditions
  • NOT: negates a filter

Use of parentheses

Use parentheses ( and ) to combine several OR conditions. These rules apply:
  • Donโ€™t group ANDs within ORs. For example, A OR (B AND C) OR (D AND E) isnโ€™t supported.
  • Donโ€™t use parentheses with top-level AND combinations. For example, (A AND (B OR C)) isnโ€™t supported. (But A AND (B OR C) is supported)
  • Donโ€™t use parentheses to negate a group of expressions. For example, NOT (filter1 OR filter2) isnโ€™t supported.

Examples of valid combinations

The following examples are valid combinations of filter expressions:
  • A AND (B OR C)
  • (A OR B) AND C
  • A AND (B OR C) AND (D OR E)
  • A AND B AND (C OR D) AND (E OR F)
  • (A OR B) AND (C OR D) AND E

Example scenarios for filter combinations

The filters parameter gives precise control over search results with a SQL-like syntax. Use the following examples to learn how to apply different filters and combine them with boolean logic.

Basic filters

Filter typeExampleFilter
Numeric comparisonShow products that cost $13 or moreprice > 12.99
Numeric rangeShow products with a price between 5.99and5.99 and 100price:5.99 TO 100
FacetsShow records categorized as โ€œBookโ€category:Book
Tag filtersShow records marked with the โ€œpublishedโ€ tag_tags:published
Boolean filtersShow records where the isEnabled attribute is trueisEnabled:true
Filter by dateShow records published between two dates Unix timestampsdate: 1441745506 TO 1441755506
NegationExclude discontinued productsNOT is_discontinued:true

Combine filters

  • Find books not written by a specific author: (category:Book OR category:Ebook) AND NOT author:"JK Rowling"
  • Filter products by price range and category: price:10 TO 50 AND (category:Electronics OR category:Accessories)
  • Complex filter with several conditions: inStock:true AND (category:Phones OR category:Tablets) AND (brand:Apple OR brand:Samsung) AND price>500

Donโ€™t mix filter types in OR conditions

You canโ€™t compare different filter types (string, numeric, tags) with an OR. For example, num=3 OR tag1 OR facet:value isnโ€™t allowed.

Apps and user actions change filter expressions

If a user or app selects a filter, Algolia omits the filters that donโ€™t apply from the expression. For example, if the original filter expression is ((category:Electronics OR category:Home) AND NOT brand:LG) AND NOT price:100 TO 500 and the user selects the Electronics category, the expression simplifies to (category:Electronics AND NOT brand:LG) AND NOT price:100 TO 500.
โŒ˜I