Skip to content

Commit cd0905a

Browse files
v1.14: New filterableAttributes format (#3207)
--------- Co-authored-by: Many the fish <[email protected]>
1 parent d7da819 commit cd0905a

File tree

2 files changed

+65
-12
lines changed

2 files changed

+65
-12
lines changed

.code-samples.meilisearch.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,17 @@ update_filterable_attributes_1: |-
262262
-H 'Content-Type: application/json' \
263263
--data-binary '[
264264
"genres",
265-
"director"
265+
"director",
266+
{
267+
"attributePatterns": ["*_ratings"],
268+
"features": {
269+
"facetSearch": false,
270+
"filters": {
271+
"equality": true,
272+
"comparison": false
273+
}
274+
}
275+
}
266276
]'
267277
reset_filterable_attributes_1: |-
268278
curl \

reference/api/settings.mdx

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ If the provided index does not exist, it will be created.
162162
| **[`displayedAttributes`](#displayed-attributes)** | Array of strings | All attributes: `["*"]` | Fields displayed in the returned documents |
163163
| **[`distinctAttribute`](#distinct-attribute)** | String | `null` | Search returns documents with distinct (different) values of the given field |
164164
| **[`faceting`](#faceting)** | Object | [Default object](#faceting-object) | Faceting settings |
165-
| **[`filterableAttributes`](#filterable-attributes)** | Array of strings | Empty | Attributes to use as filters and facets |
165+
| **[`filterableAttributes`](#filterable-attributes)** | Array of strings or objects | Empty | Attributes to use as filters and facets |
166166
| **[`pagination`](#pagination)** | Object | [Default object](#pagination-object) | Pagination settings |
167167
| **[`proximityPrecision`](#proximity-precision)** | String | `"byWord"` | Precision level when calculating the proximity ranking rule |
168168
| **[`facetSearch`](#facet-search)** | Boolean | `true` | Enable or disable [facet search](/reference/api/facet_search) functionality |
@@ -684,13 +684,43 @@ You can use the returned `taskUid` to get more details on [the status of the tas
684684

685685
## Filterable attributes
686686

687-
Attributes in the `filterableAttributes` list can be used as filters or facets.
687+
Attributes in the `filterableAttributes` list can be used as [filters](/learn/filtering_and_sorting/filter_search_results) or [facets](/learn/filtering_and_sorting/search_with_facet_filters).
688688

689689
<Capsule intent="warning">
690-
Updating filterable attributes will re-index all documents in the index, which can take some time. We recommend updating your index settings first and then adding documents as this reduces RAM consumption.
690+
Updating filterable attributes will re-index all documents in the index, which can take some time. To reduce RAM consumption, first update your index settings and then add documents.
691691
</Capsule>
692692

693-
[To learn more about filterable attributes, refer to our dedicated guide.](/learn/filtering_and_sorting/filter_search_results)
693+
### Filterable attribute object
694+
695+
`filterableAttributes` may be an array of either strings filterable attribute objects.
696+
697+
Filterable attribute objects must contain the following fields:
698+
699+
| Name | Type | Default value | Description |
700+
| ----------------------- | ---------------- | ------------- | -------------------------------------------------------- |
701+
| **`attributePatterns`** | Array of strings | `[]` | A list of strings indicating filterable fields |
702+
| **`features`** | Object | `{"facetSearch": false, "filters": {"equality": true, "comparison": false}` | A list outlining filter types enabled for the specified attributes |
703+
704+
#### `attributePatterns`
705+
706+
Attribute patterns may begin or end with a * wildcard to match multiple fields: `customer_*`, `attribute*`.
707+
708+
#### `features`
709+
710+
`features` allows you to decide which filter features are allowed for the specified attributes. It accepts the following fields:
711+
712+
- `facetSearch`: Whether facet search should be enabled for the specified attributes. Boolean, defaults to `false`
713+
- `filter`: A list outlining the filter types for the specified attributes. Must be an object and accepts the following fields:
714+
- `equality`: Enables `=`, `!=`, `IN`, `EXISTS`, `IS NULL`, `IS EMPTY`, `NOT`, `AND`, and `OR`. Boolean, defaults to `true`
715+
- `comparison`: Enables `>`, `>=`, `<`, `<=`, `TO`, `EXISTS`, `IS NULL`, `IS EMPTY`, `NOT`, `AND`, and `OR`. Boolean, defaults to `false`
716+
717+
Calculating `comparison` filters is a resource-intensive operation. Disabling them may lead to better search and indexing performance. `equality` filters use fewer resources and have limited impact on performance.
718+
719+
<Capsule intent="warning" title="Filterable attributes and reserved attributes">
720+
Use the simple string syntax to match reserved attributes. Reserved Meilisearch fields are always prefixed with an underscore (`_`), such as `_geo` and `_vector`.
721+
722+
If set as a filterable attribute, reserved attributes ignore the `features` field and automatically activate all search features. Reserved fields will not be matched by wildcard `attributePatterns` such as `_*`.
723+
</Capsule>
694724

695725
### Get filterable attributes
696726

@@ -736,15 +766,28 @@ Update an index's filterable attributes list.
736766
[<String>, <String>, …]
737767
```
738768

739-
An array of strings containing the attributes that can be used as filters at query time.
769+
An array of strings containing the attributes that can be used as filters at query time. All filter types are enabled for the specified attributes when using the array of strings format.
740770

741-
If an attribute contains an object, you can use dot notation to set one or more of its keys as a value for this setting: `"filterableAttributes": ["release_date.year"]`.
771+
You may also use an array of objects:
742772

743-
<Capsule intent="warning">
744-
If the field does not exist, no error will be thrown.
745-
</Capsule>
773+
```
774+
[
775+
{
776+
"attributePatterns": [<String>, <String>, …],
777+
"features": {
778+
"facetSearch": <Boolean>,
779+
"filter": {
780+
"equality": <Boolean>,
781+
"comparison": <Boolean>
782+
}
783+
}
784+
}
785+
]
786+
```
787+
788+
If the specified field does not exist, Meilisearch will silently ignore it.
746789

747-
[To learn more about filterable attributes, refer to our dedicated guide.](/learn/filtering_and_sorting/filter_search_results)
790+
If an attribute contains an object, you can use dot notation to set one or more of its keys as a value for this setting: `"filterableAttributes": ["release_date.year"]` or `"attributePatterns": ["release_date.year"]`.
748791

749792
#### Example
750793

@@ -821,7 +864,7 @@ Locale objects must have the following fields:
821864
| Name | Type | Default value | Description |
822865
| :----------------- | :------ | :------------ | :---------------------------------------------------------- |
823866
| **`locales`** | Array of strings | `[]` | A list of strings indicating one or more ISO-639 locales |
824-
| **`attribute_patterns`** | Array of strings | `[]` | A list of strings indicating which fields correspond to the specified locales |
867+
| **`attributePatterns`** | Array of strings | `[]` | A list of strings indicating which fields correspond to the specified locales |
825868

826869
#### `locales`
827870

0 commit comments

Comments
 (0)