Displayed and searchable attributes
By default, whenever a document is added to Meilisearch, all new attributes found in it are automatically added to two lists:
displayedAttributes: Attributes whose fields are displayed in documents
searchableAttributes: Attributes whose values are searched for matching query words
By default, every field in a document is displayed and searchable. These properties can be modified in the settings.
The fields whose attributes are added to the
displayedAttributes list are displayed in each matching document.
Documents returned upon search contain only displayed fields. If a field attribute is not in the displayed-attribute list, the field won't be added to the returned documents.
By default, all field attributes are set as displayed.
Suppose you manage a database that contains information about movies. By adding the following settings, documents returned upon search will contain the fields
-X PUT 'http://localhost:7700/indexes/movies/settings/displayed-attributes' \
-H 'Content-Type: application/json' \
A field can either be searchable or non-searchable.
When you perform a search, all searchable fields are checked for matching query words and used to assess document relevancy, while non-searchable fields are ignored entirely. By default, all fields are searchable.
Non-searchable fields are most useful for internal information that's not relevant to the search experience, such as URLs, sales numbers, or ratings used exclusively for sorting results.
Even if you make a field non-searchable, it will remain stored in the database and can be made searchable again at a later time.
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 list serves two purposes:
- It designates the fields that are searchable
- It dictates the attribute ranking order
There are two possible modes for the
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 verify the current value of your
searchableAttributes list, use the get searchable attributes endpoint.
You may want to make some attributes non-searchable, or change the attribute ranking order after documents have been indexed. To do so, place the attributes in the desired order and send the updated list using the update searchable attributes endpoint.
After manually updating the
searchableAttributes list, subsequent new attributes will no longer be automatically added unless the settings are reset.
Due to an implementation bug, manually updating
searchableAttributes will change the displayed order of document fields in the JSON response. This behavior is inconsistent and will be fixed in a future release.
Suppose that you manage a database of movies with the following fields:
release_date. These fields all contain useful information. However, some are more useful to search than others. To make the
release_date fields non-searchable and re-order the remaining fields by importance, you might update the searchable attributes list in the following way.
-X PUT 'http://localhost:7700/indexes/movies/settings/searchable-attributes' \
-H 'Content-Type: application/json' \
Customizing attributes to search on at search time
By default, all queries search through all attributes in the
searchableAttributes list. Use the
attributesToSearchOn search parameter to restrict specific queries to a subset of your index's
All fields are stored in the database. This behavior cannot be changed.
Thus, even if a field is missing from both the
displayedAttributes list and the
searchableAttributes list, it is still stored in the database and can be added to either or both lists at any time.