This specification describes the searchableAttributes
index setting API endpoints.
N/A
Documents in Meilisearch are composed of multiple fields. A field can either be searchable or non-searchable.
When a search query is performed, all searchable fields are checked for matching query words and used to assess document relevancy, while non-searchable fields are ignored entirely.
By default, Meilisearch looks for matches in every field, but the searchableAttributes
setting object allow to customize that behavior.
Suppose a database of movies with the following fields: id
, overview
, genres
, title
, release_date
. These fields all contain useful information; however, some are more useful to search than others. To make the id
and release_date
fields non-searchable and re-order the remaining fields by importance, it can be specified in the following way.
Request payload PUT
- /indexes/movies/settings/searchable-attributes
["overview", "genres", "title"]
Meilisearch uses an ordered list to determine which attributes are searchable. The order in which attributes appear in this list also determines their impact on relevancy, from most impactful to least.
In other words, the searchableAttributes
setting serves two purposes:
- It designates the fields that are searchable.
- It dictates the attribute ranking order.
There are two possible modes for the searchableAttributes
setting.
By default, all attributes are automatically added to the searchableAttributes
list in their order of appearance.
This means that the initial order will be based on the order of attributes in the first document indexed, with each new attribute found in subsequent documents added at the end of this list.
This default behavior is indicated by a searchableAttributes
value of ["*"]
.
To make some attributes non-searchable, or change the attribute ranking order. Attributes must be described from most important to least important.
Request payload PUT
- /indexes/movies/settings/searchable-attributes
["title", "overview", "genres"]
title
is considered more important than overview
while overview
is considered more important than genres
.
The Attribute Ranking Rule ranks search results by the order defined in the searchableAttributes
setting. Documents that contain query terms in the more important searchable attribute will be returned first.
Manually updating searchableAttributes
will change the displayed order of document fields in the JSON response.
A document field that is not defined in the list of searchableAttributes
will not be considered by the following ranking rules to match and rank search results.
searchableAttributes
is a sub-resource of /indexes/:index_uid/settings
.
See Settings API.
Manipulate the searchableAttributes
setting of a Meilisearch index.
Fetch the searchableAttributes
setting of a Meilisearch index.
- Type: Array of String
- Default:
["*"]
- 🔴 Sending an invalid index uid format for the
:index_uid
path parameter returns an invalid_index_uid error. - 🔴 If the requested
index_uid
does not exist, the API returns an index_not_found error.
Modify the searchableAttributes
setting of a Meilisearch index.
- Type: Array of String /
null
Setting null
is equivalent to using the 3.3.3. DELETE
- indexes/:index_uid/settings/searchable-attributes
API endpoint.
Specifying a document attribute that does not exist as a searchableAttributes
index setting returns no error.
Specifying []
for the searchableAttributes
index setting allows to specify that all fields are non-searchable.
When the request is successful, Meilisearch returns the HTTP code 202 Accepted
. The response's content is the summarized representation of the received asynchronous task.
See Summarized task
Object for 202 Accepted
.
- 🔴 Omitting Content-Type header returns a missing_content_type error.
- 🔴 Sending an empty Content-Type returns an invalid_content_type error.
- 🔴 Sending a different Content-Type than
application/json
returns an invalid_content_type error. - 🔴 Sending an empty payload returns a missing_payload error.
- 🔴 Sending an invalid JSON payload returns a malformed_payload error.
- 🔴 Sending an invalid index uid format for the
:index_uid
path parameter returns an invalid_index_uid error. - 🔴 Sending a request payload value type different of
Array of String
,[]
ornull
returns an invalid_settings_searchable_attributes error.
- 🔴 When Meilisearch is secured, if the API Key do not have the
indexes.create
action defined, the API returns an index_not_found error in the related asynchronoustask
resource. See 3.3.2.2. Response Definition.
Otherwise, Meilisearch will create the index in a lazy way. See 3.2.2.4. Lazy Index Creation.
If the requested index_uid
does not exist, and the authorization layer allows it (See 3.3.2.3.1. Async Errors), Meilisearch will create the index when the related asynchronous task resource is executed. See 3.3.2.2. Response Definition.
Reset the searchableAttributes
setting of a Meilisearch index to the default value ["*"]
.
When the request is in a successful state, Meilisearch returns the HTTP code 202 Accepted
. The response's content is the summarized representation of the received asynchronous task.
See Summarized task
Object for 202 Accepted
.
- 🔴 Sending an invalid index uid format for the
:index_uid
path parameter returns an invalid_index_uid error.
- 🔴 If the requested
index_uid
does not exist, the API returns an index_not_found error in the related asynctask
resource. See 3.3.3.1. Response Definition.
These errors apply to all endpoints described here.
The auth layer can return the following errors if Meilisearch is secured (a master-key is defined).
- 🔴 Accessing this route without the
Authorization
header returns a missing_authorization_header error. - 🔴 Accessing this route with a key that does not have permissions (i.e. other than the master-key) returns an invalid_api_key error.
Meilisearch favors search speed and makes a trade-off on indexing speed by computing internal data structures to get search results as fast as possible.
Modifying this index setting cause documents to be re-indexed.
- Fix the reordering issue of document representation when
searchableAttributes
is specified.