Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit dec7cc4

Browse files
committed
Documents API - displayedAttributes should not impact the documents API / Rename attributesToRetrieve to fields (#143)
* Specifies that displayedAttributes setting does not impact the GET documents endpoint * Rename attributeToRetrieve to fields on /documents * Add a future possibily to rejectt a field from a document in the given response * Precise behavior details about fields query parameter * Add fields query parameter on GET /indexes/{index}/documents/{docId}
1 parent 7863ed3 commit dec7cc4

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

open-api.yaml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ components:
156156
type:
157157
- string
158158
- number
159-
description: Retrieve attributes of the document. `attributesToRetrieve` controls these fields.
159+
description: Retrieve attributes of a search result. `attributesToRetrieve` controls these fields.
160160
_geoDistance:
161161
type: number
162162
description: 'Using _geoPoint({lat}, {lng}) built-in sort rule at search leads the engine to return a _geoDistance within the search results. This field represents the distance in meters of the document from the specified _geoPoint.'
@@ -815,6 +815,16 @@ components:
815815
816816
> warn
817817
> Attribute(s) used in `filter` should be declared as filterable attributes. See [Filtering and Faceted Search](https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html).
818+
fields:
819+
name: fields
820+
in: query
821+
description: 'Comma-separated list of fields to display for an API resource. By default it contains all fields of an API resource.'
822+
schema:
823+
type: string
824+
items:
825+
type: string
826+
example: 'uid,createdAt'
827+
default: '*'
818828
Content-Type:
819829
name: Content-Type
820830
in: header
@@ -1255,7 +1265,7 @@ paths:
12551265
parameters:
12561266
- $ref: '#/components/parameters/limit'
12571267
- $ref: '#/components/parameters/offset'
1258-
- $ref: '#/components/parameters/attributesToRetrieve'
1268+
- $ref: '#/components/parameters/fields'
12591269
post:
12601270
operationId: indexes.documents.create
12611271
summary: Add or replace documents
@@ -1431,6 +1441,8 @@ paths:
14311441
$ref: '#/components/responses/401'
14321442
'404':
14331443
description: Not Found
1444+
parameters:
1445+
- $ref: '#/components/parameters/fields'
14341446
delete:
14351447
operationId: indexes.documents.remove
14361448
summary: Delete one document

text/0124-documents-api.md

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
This specification describes the documents API endpoints permitting to list, fetch, add/replace, and delete index documents.
66

7+
It is an API dedicated to document management within the Meilisearch index.
8+
79
## 2. Motivation
810
N/A
911

@@ -53,8 +55,8 @@ Unique identifier of an index.
5355
| Field | Type | Required |
5456
|--------------------------|--------------------------|----------|
5557
| `offset` | Integer / `null` | false |
56-
| `limit` | Integer / `null` | false |
57-
| `attributesToRetrieve` | String / `null` | false |
58+
| `limit` | String / `null` | false |
59+
| `fields` | String / `null` | false |
5860

5961
###### 3.1.1.2.1. `offset`
6062

@@ -72,19 +74,24 @@ Sets the starting point in the results, effectively skipping over a given number
7274

7375
Sets the maximum number of documents to be returned by the current request.
7476

75-
###### 3.1.1.2.3. `attributesToRetrieve`
77+
###### 3.1.1.2.3. `fields`
7678

7779
- Type: String
7880
- Required: False
79-
- Default: `null`
81+
- Default: `*`
8082

8183
Configures which attributes will be retrieved in the returned documents.
8284

83-
If no value is specified, `attributesToRetrieve` uses the `displayedAttributes` list, which by default contains all attributes found in the documents.
85+
If `fields` is not specified, all attributes from the documents are returned in the response. It's equivalent to `fields=*`.
86+
87+
- Sending `fields` without specifying a value, returns empty documents ressources. `fields=`.
88+
- Sending `fields` with a non-existent field as part of the value will not return an error, the non-existent field will not be displayed.
8489

85-
> If an attribute has been removed from `displayedAttributes` index settings, `attributesToRetrieve` will silently ignore it and the field will not appear in the returned documents.
90+
> `fields` values are case-sensitive.
8691
87-
> Specified fields have to be separated by a comma. e.g. `&attributesToRetrieve=title,description`
92+
> Specified fields have to be separated by a comma. e.g. `&fields=title,description`
93+
94+
> The index setting `displayedAttributes` has no impact on this endpoint.
8895
8996
##### 3.1.1.3. Response Definition
9097

@@ -153,7 +160,7 @@ Gives the total number of documents that can be browsed in the related index.
153160

154161
- 🔴 Sending a value with a different type than `Integer` or `null` for `offset` will return a [bad_request](0061-error-format-and-definitions.md#bad_request) error.
155162
- 🔴 Sending a value with a different type than `Integer` or `null` for `limit` will return a [bad_request](0061-error-format-and-definitions.md#bad_request) error.
156-
- 🔴 Sending a value with a different type than `String` or `null` for `attributesToRetrieve` will return a [bad_request](0061-error-format-and-definitions.md#bad_request) error.
163+
- 🔴 Sending a value with a different type than `String` or `null` for `fields` will return a [bad_request](0061-error-format-and-definitions.md#bad_request) error.
157164

158165
#### 3.1.2. `GET` - `indexes/:index_uid/documents/:document_id`
159166

@@ -180,14 +187,39 @@ Unique identifier of an index.
180187

181188
Unique identifier of a document.
182189

183-
##### 3.1.2.1. Request Payload Definition
190+
##### 3.1.2.2. Query Parameters
191+
192+
| Field | Type | Required |
193+
|--------------------------|--------------------------|----------|
194+
| `fields` | String / `null` | false |
195+
196+
###### 3.1.2.2.1. `fields`
197+
198+
- Type: String
199+
- Required: False
200+
- Default: `*`
201+
202+
Configures which attributes will be retrieved in the returned documents.
203+
204+
If `fields` is not specified, all attributes from the documents are returned in the response. It's equivalent to `fields=*`.
205+
206+
- Sending `fields` without specifying a value, returns empty documents ressources. `fields=`.
207+
- Sending `fields` with a non-existent field as part of the value will not return an error, the non-existent field will not be displayed.
208+
209+
> `fields` values are case-sensitive.
210+
211+
> Specified fields have to be separated by a comma. e.g. `&fields=title,description`
212+
213+
> The index setting `displayedAttributes` has no impact on this endpoint.
214+
215+
##### 3.1.2.3. Request Payload Definition
184216
N/A
185217

186-
##### 3.1.2.2. Response Definition
218+
##### 3.1.2.4. Response Definition
187219

188220
A document represented as a JSON object.
189221

190-
##### 3.1.2.2.1. Example
222+
##### 3.1.2.4.1. Example
191223

192224
```json
193225
{
@@ -199,10 +231,11 @@ A document represented as a JSON object.
199231
}
200232
```
201233

202-
##### 3.1.2.3. Errors
234+
##### 3.1.2.5. Errors
203235

204236
- 🔴 If the requested `index_uid` does not exist, the API returns an [index_not_found](0061-error-format-and-definitions.md#index_not_found) error.
205237
- 🔴 If the requested `document_id` does not exist, the API returns an [document_not_found](0061-error-format-and-definitions.md#document_not_found) error.
238+
- 🔴 Sending a value with a different type than `String` or `null` for `fields` will return a [bad_request](0061-error-format-and-definitions.md#bad_request) error.
206239

207240
#### 3.1.3. `POST` - `indexes/:index_uid/documents`
208241

@@ -489,4 +522,5 @@ The auth layer can return the following errors if Meilisearch is secured (a mast
489522
N/A
490523

491524
## 5. Future Possibilities
492-
N/A
525+
526+
- Introduce a way to reject fields from a document in the response. e.g. `?fields=-createdAt`

0 commit comments

Comments
 (0)