numericFilters

scope search
type array of strings
default []
description

Filter hits based on values of numeric attributes.

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

Each string represents a filter on a numeric attribute. Two forms are supported:

  • Comparison: ${attributeName} ${operator} ${operand} matches all objects where the specified numeric attribute satisfies the numeric condition expressed by the operator and the operand. The operand must be a numeric value. Supported operators are <, <=, =, !=, >= and >, with the same semantics as in virtually all programming languages. Example: inStock > 0.

  • Range: ${attributeName}:${lowerBound} TO ${upperBound} matches all objects where the specified numeric attribute is within the range [${lowerBound}, ${upperBound}] (inclusive on both ends). Example: price: 0 TO 1000.

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

Examples

Apply numeric filters filters on a search query

<?php
$results = $index->search('query', [
  'numericFilters' => [
    [
      "inStock > 0",
      "deliveryDate < 1441755506"
    ],
    "price < 1000"
  ]
]);
results = index.search('query', {
  numericFilters: [
    [
      'inStock > 0',
      'deliveryDate < 1441755506'
    ],
    'price < 1000'
  ]
})
index.search({
  query: 'query',
  numericFilters: [
    ['inStock > 0', 'deliveryDate < 1441755506'],
    'price < 1000'
  ]
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
    'numericFilters': [
        [
            "inStock > 0",
            "deliveryDate < 1441755506"
        ],
        "price < 1000"
    ]
})
let query = Query(query: "query")
query.numericFilters = [
    [
        "inStock > 0",
        "deliveryDate < 1441755506"
    ],
    "price < 1000"
]

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setNumericFilters(new JSONArray()
    .put("inStock > 0 AND deliveryDate < 1441755506").put("price < 1000")));
index.search(
  new Query("query").SetNumericFilters("inStock > 0 AND deliveryDate < 1441755506, price < 1000")
);
index.search(
  new Query("query").setNumericFilters(Arrays.asList(
    "inStock > 0 AND deliveryDate < 1441755506",
    "price < 1000"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
    "numericFilters": []interface{}{
        []string{
            "inStock > 0",
            "deliveryDate < 1441755506",
        },
        "price < 1000",
    },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    numericFilters = Some(Seq(
      "inStock > 0" AND deliveryDate < 1441755506",
      "price < 1000"
    ))
  )
}
  • ["inStock > 0", "price < 1000"] translates as inStock > 0 AND price < 1000
  • [["inStock > 0", "deliveryDate < 1441755506"], "price < 1000"] translates as (inStock > 0 OR deliveryDate < 1441755506) AND price < 1000
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala