API Reference / API Parameters / optionalFilters
Feb. 26, 2019


Type: list of strings
Engine default: []
Parameter syntax
'optionalFilters' => [
    ['attribute1:value', 'attribute2:value'],

Can be used in these methods:

About this parameter

Create filters for ranking purposes, where records that match the filter are ranked highest.

Optional filtering behaves like normal filters, meaning that it returns records that match both the query and the filters. However, it also returns records that do not match the filters. The effect is on the ranking: records matching the filters are ranked higher than records that do not match the filters.

Usage notes:

  • The boolean syntax is the same as facetFilters, except for negative syntax. If you use negative syntax, for example categories:-Book, it will not work; it will be transformed into categories:Book.

  • Promoting results: See how you can use optionalFilters to promote filters and facets.

  • Ranking Formula: This setting will only work if the Filters criterion is part of the ranking. Filters is by default part of the ranking; so if you’ve removed it, and yet wish to use option filters, you’ll need to add it back to the ranking formula.

For customers on the Community, Essential and Plus legacy plans who signed up before December 15, 2018, optional filters are limited to only one per query. Free plans do not have access to optional filters.

For all other plans (Enterprise, Pro, Starter), optional filters are unlimited.


Apply optional filters on a search query

$results = $index->search('query', [
  'optionalFilters' => [
    "author:John Doe"

Did you find this page helpful?