Field properties

By default, whenever a document is added to MeiliSearch, all new attributes found in it are automatically added to two lists:

This means that by default, every field in a document is searchable and displayed. These properties can be modified in the settings.

Searchable fields

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.

TIP

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.

The searchableAttributes list

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:

  1. It designates the fields that are searchable.
  2. It dictates the attribute ranking order.

There are two possible modes for the searchableAttributes list.

Default: Automatic

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.

If you’d like to restore your searchable attributes list to this default behavior, simply set searchableAttributes to an empty array [] or use the reset searchable attributes endpoint.

Manual

You may want to make some attributes non-searchable, or change the attribute ranking order after documents have been indexed. To do so, simply 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.

WARNING

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.

Example

Suppose that you manage a database of movies with the following fields: id, description, genre, 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, you might update the searchable attributes list in the following way.

cURL
  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "searchableAttributes": [
  5. "title",
  6. "description",
  7. "genre"
  8. ]
  9. }'
JavaScript
  1. client.index('movies').updateSettings({
  2. searchableAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre'
  6. ]
  7. })
Python
  1. client.index('movies').update_settings({
  2. 'searchableAttributes': [
  3. 'title',
  4. 'description',
  5. 'genre'
  6. ]})
PHP
  1. $client->index('movies')->updateSearchableAttributes([
  2. 'title',
  3. 'description',
  4. 'genre'
  5. ]);
Ruby
  1. client.index('movies').update_searchable_attributes([
  2. 'title',
  3. 'description',
  4. 'genre'
  5. ])
Go
  1. searchableAttributes := []string{
  2. "title",
  3. "description",
  4. "genre",
  5. }
  6. client.Index("movies").UpdateSearchableAttributes(&searchableAttributes)
Rust
  1. let searchable_attributes = [
  2. "title",
  3. "description",
  4. "genre"
  5. ];
  6. let progress: Progress = movies.set_searchable_attributes(&searchable_attributes).await.unwrap();

Displayed fields

The fields whose attributes are added to the displayedAttributes list are displayed in each matching document.

Documents returned upon search contain only displayed fields.

By default, all field attributes are set as displayed.

Therefore, if a field attribute is not in the displayed-attribute list, the field won’t be added to the returned documents.

This list can be restricted to a selected set of attributes in the settings.

Example

Suppose you manage a database that contains information about movies. By adding the following settings, documents returned upon search will contain the fields title, description, release_date and genre.

cURL
  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/settings' \
  3. --data '{
  4. "displayedAttributes": [
  5. "title",
  6. "description",
  7. "genre",
  8. "release_date"
  9. ]
  10. }'
JavaScript
  1. client.index('movies').updateSettings({
  2. displayedAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date'
  7. ]
  8. })
Python
  1. client.index('movies').update_settings({
  2. 'displayedAttributes': [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date'
  7. ]})
PHP
  1. $client->index('movies')->updateDisplayedAttributes([
  2. 'title',
  3. 'description',
  4. 'genre',
  5. 'release_date'
  6. ]);
Ruby
  1. client.index('movies').update_settings({
  2. displayedAttributes: [
  3. 'title',
  4. 'description',
  5. 'genre',
  6. 'release_date'
  7. ]
  8. })
Go
  1. displayedAttributes := []string{
  2. "title",
  3. "description",
  4. "genre",
  5. "release_date",
  6. }
  7. client.Index("movies").UpdateDisplayedAttributes(&displayedAttributes)
Rust
  1. let displayed_attributes = [
  2. "title",
  3. "description",
  4. "genre",
  5. "release_date"
  6. ];
  7. let progress: Progress = movies.set_displayed_attributes(&displayed_attributes).await.unwrap();

Data storing

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.