API Reference / API Parameters / numericFilters
Type: list of strings
Engine default: []
Parameter syntax
'numericFilters' => [
  'numeric_attribute [= | != | > | >= | < | <=](#numeric-comparisons) numeric_value',
  'attribute:lower_value TO higher_value',
  ...
]

Can be used in these methods:

About this parameter

Filter on numeric attributes.

The filters parameter provides an easier to use, SQL-like syntax. We recommend using it instead of this setting.

Numeric Comparisons

Format: ${attributeName} ${operator} ${operand}
Example: inStock = 1.

Supported operators are <, <=, =, !=, >= and >, with the same semantics as in virtually all programming languages.


Numeric Range

Format: ${attributeName}:${lowerBound} TO ${upperBound}
Example: price:5.99 TO 100

${lowerBound} and ${upperBound} must be numeric. Both are inclusive.


Usage notes

  • No boolean operators: You cannot use boolean operators like AND and OR.

  • Multiple filters: If you specify multiple filters, they are interpreted as a conjunction (AND). If you want to use a disjunction (OR), use a nested array.

  • Supported values: You can use positive or negative numbers whose absolute value is up to 4611686018427387.

  • Precision limit: numeric filters support up to the third decimal point. Digits after the fourth decimal point are lost when filtering.

Examples

Apply numeric filters on a search query

1
2
3
4
5
6
7
8
9
$results = $index->search('query', [
  'numericFilters' => [
    [
      "inStock = 1",
      "deliveryDate < 1441755506"
    ],
    "price < 1000"
  ]
]);
  • [["inStock = 1", "deliveryDate < 1441755506"], "price < 1000"] translates as (inStock = 1 OR deliveryDate < 1441755506) AND price < 1000
Did you find this page helpful?