🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API Reference / API Parameters / searchableAttributes
Type: list of strings
Engine default: [] (all string attributes)
Formerly: attributesToIndex
Parameter syntax
'searchableAttributes' => [
  'attribute1',
  'attribute2, attribute3', // both attributes have the same priority
  'unordered(attribute4)'
]

Can be used in these methods:

About this parameter

The complete list of attributes used for searching.

This setting is crucial for two reasons:

  • It narrows the search area to specific attributes. By selecting which attributes can be searched, you control what the search engine looks at. Avoid including attributes that don’t help with searching, such as URLs or images. For more information, see Searchable attributes.

  • It sets a priority order for the attributes. The position of attributes in the list of searchableAttributes determines their priority in the search. Records matching higher-priority attributes score better than those matching lower-priority attributes.

Updating the searchableAttributes parameter rebuilds your index. If you need near real-time indexing, avoid changing the index configuration during high-traffic times.

Usage notes

Default
By default, or if you set searchableAttributes to an empty list, Algolia searches in all attributes. This turns off the Attributes ranking criterion.
Order
To determine how Algolia searches within an attribute, use modifiers. By default, the engine favors matches at the beginning of an attribute, but you can change it to ignore positioning and consider any match within an attribute of equal importance.
Attributes with the same priority
To make two attributes equally important, include them in the same comma-separated string. Attributes with the same priority as others are always unordered.
Nested attributes
When you specify an attribute with nested attributes, Algolia indexes them all. If you don’t want to search the entire nested attribute, you can reference a child attribute, such as categories.lvl0.child_attribute.sub_child_attribute.

There’s no limit to the number of attributes in the list, but having many attributes slows down calls to getSettings. This can make the Algolia dashboard slower and less responsive.

Modifiers

unordered

Ignores the position of the match within the attribute.

By default, searchableAttributes added from the API are ordered. Matches at the beginning of an attribute are more relevant than matches towards the end. Setting them as unordered makes all matches equal regardless of their position in the attribute.

searchableAttributes with the same priority are always unordered.

If you add searchableAttributes through the dashboard, the UI defaults to setting your attribute as unordered.

Examples

In this example, Algolia searches for matches in the title, alternativeTitle, author, text, and email.personal attributes. Matches in the title attribute rank higher than matches in the author attribute. Matches in the title and alternativeTitle attributes rank equally. Matches at the start of an attribute rank higher, except in the text attribute, where all matches rank equally. The email attribute is nested, but only the personal child attribute is searchable.

1
2
3
4
5
6
7
8
$index->setSettings([
  'searchableAttributes' => [
    'title,alternative_title',
    'author',
    'unordered(text)',
    'emails.personal'
  ]
]);
Did you find this page helpful?