Skip to content

Commit 431c864

Browse files
bors[bot]guimachiavellimaryamsulemani97
authored
Merge #1759
1759: v0.28: Pagination settings r=maryamsulemani97 a=guimachiavelli Closes #1722 Note for reviewers: you may ignore the failed CI checks, as they are currently failing due to a link to a document created in another PR. Co-authored-by: gui machiavelli <[email protected]> Co-authored-by: gui machiavelli <[email protected]> Co-authored-by: Maryam Sulemani <[email protected]> Co-authored-by: Maryam <[email protected]> Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
2 parents 9cffdb1 + 16b334d commit 431c864

File tree

9 files changed

+199
-42
lines changed

9 files changed

+199
-42
lines changed

.code-samples.meilisearch.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ update_settings_1: |-
183183
"twoTypos": 10
184184
},
185185
"disableOnAttributes": ["title"]
186+
},
187+
"pagination": {
188+
"maxTotalHits": 5000
186189
}
187190
}'
188191
reset_settings_1: |-
@@ -958,3 +961,23 @@ getting_started_typo_tolerance: |-
958961
--data-binary '{
959962
"minWordSizeForTypos": { "oneTypo": 4 }
960963
}'
964+
settings_guide_pagination_1: |-
965+
curl \
966+
-X PATCH 'http://localhost:7700/indexes/movies/settings/pagination' \
967+
-H 'Content-Type: application/json' \
968+
--data-binary '{
969+
"maxTotalHits": 50
970+
}'
971+
get_pagination_settings_1: |-
972+
curl \
973+
-X GET 'http://localhost:7700/indexes/books/settings/pagination'
974+
update_pagination_settings_1: |-
975+
curl \
976+
-X PATCH 'http://localhost:7700/indexes/books/settings/pagination' \
977+
-H 'Content-Type: application/json' \
978+
--data-binary '{
979+
"maxTotalHits": 100
980+
}'
981+
reset_pagination_settings_1: |-
982+
curl \
983+
-X DELETE 'http://localhost:7700/indexes/books/settings/pagination'

.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ module.exports = {
324324
'/reference/api/displayed_attributes',
325325
'/reference/api/distinct_attribute',
326326
'/reference/api/filterable_attributes',
327+
'/reference/api/pagination',
327328
'/reference/api/ranking_rules',
328329
'/reference/api/searchable_attributes',
329330
'/reference/api/sortable_attributes',

.vuepress/public/sample-template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@ updating_guide_retrieve_documents_old: |-
146146
updating_guide_update_settings_old: |-
147147
updating_guide_add_documents_old: |-
148148
getting_started_typo_tolerance: |-
149+
settings_guide_pagination_1: |-
150+
get_pagination_settings_1: |-
151+
update_pagination_settings_1: |-
152+
reset_pagination_settings_1: |-

learn/advanced/known_limitations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ user = 1 OR user = 2 […] OR user = 1500 OR user = 1501 […] OR user = 2000 OR
9797

9898
## Maximum number of results per search
9999

100-
**Limitation:** Meilisearch returns up to 1000 documents per search.
100+
**Limitation:** By default, Meilisearch returns up to 1000 documents per search.
101101

102-
**Explanation:** This non-customizable limit ensures the database is protected from malicious scraping. This limit only applies to the [search route](/reference/api/search.md). If you want to get all documents in your database, you can use the [get documents endpoint](/reference/api/documents.md#get-documents) instead.
102+
**Explanation:** Meilisearch limits the maximum amount of returned search results to protect your database from malicious scraping. You may change this by using the `maxTotalHits` property of the [pagination index settings](/reference/api/pagination.md#maxtotalhits). `maxTotalHits` only applies to the [search route](/reference/api/search.md) and has no effect on the [get documents endpoint](/reference/api/documents.md#get-documents).

learn/configuration/settings.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This page describes the **index-level settings** available in Meilisearch and ho
77
| **[displayedAttributes](/learn/configuration/settings.md#displayed-attributes)** | Fields displayed in the returned documents | All attributes found in the documents |
88
| **[distinctAttribute](/learn/configuration/settings.md#distinct-attribute)** | Search returns documents with distinct (different) values of the given field | `null` |
99
| **[filterableAttributes](/learn/configuration/settings.md#filterable-attributes)** | List of attributes that can be used for filtering | `null` |
10+
| **[pagination](/learn/advanced/pagination.md)** | Pagination settings | `{}`
1011
| **[rankingRules](/learn/configuration/settings.md#ranking-rules)** | List of ranking rules sorted by order of importance | [A list of ordered built-in ranking rules](/learn/core_concepts/relevancy.md#built-in-rules) |
1112
| **[searchableAttributes](/learn/configuration/settings.md#searchable-attributes)** | Fields in which to search for matching query words sorted by order of importance | All attributes found in the documents | |
1213
| **[sortableAttributes](/learn/configuration/settings.md#sortable-attributes)** | List of attributes to use when sorting search results | `[]` |
@@ -95,6 +96,22 @@ To be able to filter search results on `director` and `genres` in a movie databa
9596

9697
<CodeSamples id="faceted_search_update_settings_1" />
9798

99+
## Pagination
100+
101+
The maximum number of results Meilisearch can return. By default, this value is `1000` which means you cannot access results beyond `1000`.
102+
103+
[Learn more about pagination in our dedicated guide.](/learn/advanced/pagination.md)
104+
105+
### Example
106+
107+
The code sample below updates `maxTotalHits` to `50`:
108+
109+
<CodeSamples id="settings_guide_pagination_1" />
110+
111+
::: note
112+
`maxTotalHits` takes priority over search parameters such as [`limit`](/reference/api/search.md#limit) and [`offset`](/reference/api/search.md#offset).
113+
:::
114+
98115
## Ranking rules
99116

100117
Built-in ranking rules that **ensure relevancy in search results**. Ranking rules are applied in a default order which can be changed in the settings. You can add or remove rules and change their order of importance.

learn/core_concepts/indexes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ You can customize the following index settings:
5959
- [Stop words](#stop-words)
6060
- [Displayed and searchable attributes](#displayed-and-searchable-attributes)
6161
- [Typo tolerance](#typo-tolerance)
62+
- [Pagination](#pagination)
6263

6364
To change index settings, use the [update settings endpoint](/reference/api/settings.md#update-settings) or any of the [child routes](/reference/api/settings.md#all-settings).
6465

@@ -130,3 +131,9 @@ Typo tolerance is a built-in feature that helps you find relevant results even w
130131
You can update the typo tolerance settings using the [update settings endpoint](/reference/api/settings.md#update-settings) or the [update typo tolerance endpoint](/reference/api/typo_tolerance.md#update-typo-tolerance).
131132

132133
[Learn more about typo tolerance](/learn/configuration/typo_tolerance.md)
134+
135+
### Pagination
136+
137+
To protect your database from malicious scraping, Meilisearch only returns up to `1000` results for a search query. You can change this limit using the [update settings endpoint](/reference/api/settings.md#update-settings) or the [update pagination settings endpoint](/reference/api/pagination.md#update-pagination-settings).
138+
139+
[Learn more about pagination](/learn/advanced/pagination.md)

reference/api/pagination.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Pagination
2+
3+
_Child route of the [settings route](/reference/api/settings.md)._
4+
5+
This route allows you to configure the pagination settings for an index.
6+
7+
Pagination settings can also be updated directly through the [global settings route](/reference/api/settings.md#update-settings) along with the other settings.
8+
9+
To learn more about paginating search results with Meilisearch, refer to our [dedicated guide](/learn/advanced/pagination.md).
10+
11+
::: warning
12+
Updating the settings means overwriting the default settings of Meilisearch. You can reset to default values using the `DELETE` routes.
13+
:::
14+
15+
## Get pagination settings
16+
17+
<RouteHighlighter method="GET" route="/indexes/{index_uid}/settings/pagination"/>
18+
19+
Get the pagination settings of an index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.
20+
21+
### Example
22+
23+
<CodeSamples id="get_pagination_settings_1" />
24+
25+
#### Response: `200 OK`
26+
27+
```json
28+
{
29+
"maxTotalHits": 1000
30+
}
31+
```
32+
33+
### Returned fields
34+
35+
#### `maxTotalHits`
36+
37+
The maximum number of results Meilisearch can return.
38+
39+
## Update pagination settings
40+
41+
<RouteHighlighter method="PATCH" route="/indexes/{index_uid}/settings/pagination"/>
42+
43+
Partially update the pagination settings for an index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.
44+
45+
### Body
46+
47+
#### `maxTotalHits`
48+
49+
**Type:** integer
50+
**Default value:** `1000`
51+
52+
An integer indicating the maximum number of search results Meilisearch can return. `maxTotalHits` takes priority over search parameters such as `limit` and `offset`.
53+
54+
For example, if you set `maxTotalHits` to 100, you will not be able to access search results beyond 100 no matter the value configured for `offset`.
55+
56+
::: note
57+
Setting `maxTotalHits` to a high value might negatively impact performance and expose instance data to malicious scraping.
58+
:::
59+
60+
#### Example
61+
62+
<CodeSamples id="update_pagination_settings_1" />
63+
64+
#### Response: `200 OK`
65+
66+
```json
67+
{
68+
"taskUid": 1,
69+
"indexUid": "books",
70+
"status": "enqueued",
71+
"type": "settingsUpdate",
72+
"enqueuedAt": "2022-04-14T20:56:44.991039Z"
73+
}
74+
```
75+
76+
You can use the returned `taskUid` to get more details on [the status of the task](/reference/api/tasks.md#get-task).
77+
78+
## Reset pagination settings
79+
80+
Reset an index's pagination settings to their default value. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.
81+
82+
#### Example
83+
84+
<CodeSamples id="reset_pagination_settings_1" />
85+
86+
#### Response: `200 OK`
87+
88+
```json
89+
{
90+
"taskUid": 1,
91+
"indexUid": "books",
92+
"status": "enqueued",
93+
"type": "settingsUpdate",
94+
"enqueuedAt": "2022-04-14T20:53:32.863107Z"
95+
}
96+
```
97+
98+
You can use the returned `taskUid` to get more details on [the status of the task](/reference/api/tasks.md#get-task).

reference/api/search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Other than the differences mentioned above, the two routes are strictly equivale
2020
Search for documents matching a specific query in the given index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.
2121

2222
::: note
23-
This endpoint has a [non-customizable limit of 1000 results](/learn/advanced/known_limitations.md#maximum-number-of-results-per-search). If you want to scrape your database, use the [get documents endpoint](/reference/api/documents.md#get-documents) instead.
23+
By default, [this endpoint returns a maximum of 1000 results](/learn/advanced/known_limitations.md#maximum-number-of-results-per-search). If you want to scrape your database, use the [get documents endpoint](/reference/api/documents.md#get-documents) instead.
2424
:::
2525

2626
This is the preferred route to perform search when an API key is required, as it allows for [preflight requests](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) to be cached. Caching preflight requests **considerably improves search speed**.
@@ -111,7 +111,7 @@ Query terms enclosed in double quotes are treated as [phrase searches](#query-q)
111111
Search for documents matching a specific query in the given index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.
112112

113113
:::note
114-
This endpoint has a [non-customizable limit of 1000 results](/learn/advanced/known_limitations.md#maximum-number-of-results-per-search). If you want to scrape your database, you can use the [get documents endpoint](/reference/api/documents.md#get-documents) instead.
114+
By default, [this endpoint returns a maximum of 1000 results](/learn/advanced/known_limitations.md#maximum-number-of-results-per-search). If you want to scrape your database, use the [get documents endpoint](/reference/api/documents.md#get-documents) instead.
115115
:::
116116

117117
This route should only be used when no API key is required. If an API key is required, use the POST route instead.

0 commit comments

Comments
 (0)