Skip to content

v0.28: Pagination settings #1759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
693de12
pagination settings: API reference scaffolding
guimachiavelli Jun 23, 2022
6d624d5
pagination: new API reference page
guimachiavelli Jun 27, 2022
b2c4659
pagination: new API code samples
guimachiavelli Jun 27, 2022
dcd96bb
pagination: fix code sample key
guimachiavelli Jun 27, 2022
6ce7068
pagination: add API reference to menu
guimachiavelli Jun 27, 2022
88e9fc5
pagination: update global settings reference
guimachiavelli Jun 27, 2022
aec2da0
pagination: update known limitations
guimachiavelli Jun 28, 2022
b0572e0
pagination: update HTTP method
guimachiavelli Jun 28, 2022
1e88a91
Apply suggestions from code review
guimachiavelli Jun 29, 2022
df1d260
pagination settings: address review feedback
guimachiavelli Jun 29, 2022
f5653cf
pagination settings: improve note on side effects of high `maxTotalHits`
guimachiavelli Jun 29, 2022
2e8e715
pagination settings: fix broken hash
guimachiavelli Jun 29, 2022
b397e1f
pagination settings: update boxes with warnings on non-customizable m…
guimachiavelli Jun 29, 2022
6a618ad
Update reference/api/pagination.md
guimachiavelli Jun 30, 2022
f48fe20
Update reference/api/pagination.md
guimachiavelli Jun 30, 2022
213c326
Add pagination to core concepts/indexes
maryamsulemani97 Jun 30, 2022
0a340c2
Update learn/core_concepts/indexes.md
maryamsulemani97 Jun 30, 2022
752f0b3
Update indexes.md
maryamsulemani97 Jun 30, 2022
511f904
update setings
maryamsulemani97 Jun 30, 2022
8d01e10
settings_guide_pagination_1
maryamsulemani97 Jun 30, 2022
085dcb4
Update .code-samples.meilisearch.yaml
maryamsulemani97 Jun 30, 2022
486e470
Update learn/core_concepts/indexes.md
maryamsulemani97 Jun 30, 2022
31a1443
Apply suggestions from code review
guimachiavelli Jul 4, 2022
4827ac3
Update .code-samples.meilisearch.yaml
guimachiavelli Jul 4, 2022
4257e90
Update .code-samples.meilisearch.yaml
guimachiavelli Jul 4, 2022
3d3d3de
add return to code samples file
guimachiavelli Jul 4, 2022
24a46eb
Merge branch 'v0.28-pagination-settings' into update-indexes.md-to-ad…
guimachiavelli Jul 4, 2022
16b334d
Merge #1766
bors[bot] Jul 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ update_settings_1: |-
"twoTypos": 10
},
"disableOnAttributes": ["title"]
},
"pagination": {
"maxTotalHits": 5000
}
}'
reset_settings_1: |-
Expand Down Expand Up @@ -958,3 +961,23 @@ getting_started_typo_tolerance: |-
--data-binary '{
"minWordSizeForTypos": { "oneTypo": 4 }
}'
settings_guide_pagination_1: |-
curl \
-X PATCH 'http://localhost:7700/indexes/movies/settings/pagination' \
-H 'Content-Type: application/json' \
--data-binary '{
"maxTotalHits": 50
}'
get_pagination_settings_1: |-
curl \
-X GET 'http://localhost:7700/indexes/books/settings/pagination'
update_pagination_settings_1: |-
curl \
-X PATCH 'http://localhost:7700/indexes/books/settings/pagination' \
-H 'Content-Type: application/json' \
--data-binary '{
"maxTotalHits": 100
}'
reset_pagination_settings_1: |-
curl \
-X DELETE 'http://localhost:7700/indexes/books/settings/pagination'
1 change: 1 addition & 0 deletions .vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ module.exports = {
'/reference/api/displayed_attributes',
'/reference/api/distinct_attribute',
'/reference/api/filterable_attributes',
'/reference/api/pagination',
'/reference/api/ranking_rules',
'/reference/api/searchable_attributes',
'/reference/api/sortable_attributes',
Expand Down
4 changes: 4 additions & 0 deletions .vuepress/public/sample-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ updating_guide_retrieve_documents_old: |-
updating_guide_update_settings_old: |-
updating_guide_add_documents_old: |-
getting_started_typo_tolerance: |-
settings_guide_pagination_1: |-
get_pagination_settings_1: |-
update_pagination_settings_1: |-
reset_pagination_settings_1: |-
4 changes: 2 additions & 2 deletions learn/advanced/known_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ user = 1 OR user = 2 […] OR user = 1500 OR user = 1501 […] OR user = 2000 OR

## Maximum number of results per search

**Limitation:** Meilisearch returns up to 1000 documents per search.
**Limitation:** By default, Meilisearch returns up to 1000 documents per search.

**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.
**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).
17 changes: 17 additions & 0 deletions learn/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This page describes the **index-level settings** available in Meilisearch and ho
| **[displayedAttributes](/learn/configuration/settings.md#displayed-attributes)** | Fields displayed in the returned documents | All attributes found in the documents |
| **[distinctAttribute](/learn/configuration/settings.md#distinct-attribute)** | Search returns documents with distinct (different) values of the given field | `null` |
| **[filterableAttributes](/learn/configuration/settings.md#filterable-attributes)** | List of attributes that can be used for filtering | `null` |
| **[pagination](/learn/advanced/pagination.md)** | Pagination settings | `{}`
| **[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) |
| **[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 | |
| **[sortableAttributes](/learn/configuration/settings.md#sortable-attributes)** | List of attributes to use when sorting search results | `[]` |
Expand Down Expand Up @@ -95,6 +96,22 @@ To be able to filter search results on `director` and `genres` in a movie databa

<CodeSamples id="faceted_search_update_settings_1" />

## Pagination

The maximum number of results Meilisearch can return. By default, this value is `1000` which means you cannot access results beyond `1000`.

[Learn more about pagination in our dedicated guide.](/learn/advanced/pagination.md)

### Example

The code sample below updates `maxTotalHits` to `50`:

<CodeSamples id="settings_guide_pagination_1" />

::: note
`maxTotalHits` takes priority over search parameters such as [`limit`](/reference/api/search.md#limit) and [`offset`](/reference/api/search.md#offset).
:::

## Ranking rules

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.
Expand Down
7 changes: 7 additions & 0 deletions learn/core_concepts/indexes.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ You can customize the following index settings:
- [Stop words](#stop-words)
- [Displayed and searchable attributes](#displayed-and-searchable-attributes)
- [Typo tolerance](#typo-tolerance)
- [Pagination](#pagination)

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).

Expand Down Expand Up @@ -130,3 +131,9 @@ Typo tolerance is a built-in feature that helps you find relevant results even w
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).

[Learn more about typo tolerance](/learn/configuration/typo_tolerance.md)

### Pagination

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).

[Learn more about pagination](/learn/advanced/pagination.md)
98 changes: 98 additions & 0 deletions reference/api/pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Pagination

_Child route of the [settings route](/reference/api/settings.md)._

This route allows you to configure the pagination settings for an index.

Pagination settings can also be updated directly through the [global settings route](/reference/api/settings.md#update-settings) along with the other settings.

To learn more about paginating search results with Meilisearch, refer to our [dedicated guide](/learn/advanced/pagination.md).

::: warning
Updating the settings means overwriting the default settings of Meilisearch. You can reset to default values using the `DELETE` routes.
:::

## Get pagination settings

<RouteHighlighter method="GET" route="/indexes/{index_uid}/settings/pagination"/>

Get the pagination settings of an index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.

### Example

<CodeSamples id="get_pagination_settings_1" />

#### Response: `200 OK`

```json
{
"maxTotalHits": 1000
}
```

### Returned fields

#### `maxTotalHits`

The maximum number of results Meilisearch can return.

## Update pagination settings

<RouteHighlighter method="PATCH" route="/indexes/{index_uid}/settings/pagination"/>

Partially update the pagination settings for an index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.

### Body

#### `maxTotalHits`

**Type:** integer
**Default value:** `1000`

An integer indicating the maximum number of search results Meilisearch can return. `maxTotalHits` takes priority over search parameters such as `limit` and `offset`.

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`.

::: note
Setting `maxTotalHits` to a high value might negatively impact performance and expose instance data to malicious scraping.
:::

#### Example

<CodeSamples id="update_pagination_settings_1" />

#### Response: `200 OK`

```json
{
"taskUid": 1,
"indexUid": "books",
"status": "enqueued",
"type": "settingsUpdate",
"enqueuedAt": "2022-04-14T20:56:44.991039Z"
}
```

You can use the returned `taskUid` to get more details on [the status of the task](/reference/api/tasks.md#get-task).

## Reset pagination settings

Reset an index's pagination settings to their default value. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.

#### Example

<CodeSamples id="reset_pagination_settings_1" />

#### Response: `200 OK`

```json
{
"taskUid": 1,
"indexUid": "books",
"status": "enqueued",
"type": "settingsUpdate",
"enqueuedAt": "2022-04-14T20:53:32.863107Z"
}
```

You can use the returned `taskUid` to get more details on [the status of the task](/reference/api/tasks.md#get-task).
4 changes: 2 additions & 2 deletions reference/api/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Other than the differences mentioned above, the two routes are strictly equivale
Search for documents matching a specific query in the given index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.

::: note
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.
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.
:::

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**.
Expand Down Expand Up @@ -111,7 +111,7 @@ Query terms enclosed in double quotes are treated as [phrase searches](#query-q)
Search for documents matching a specific query in the given index. The index [`uid`](/learn/core_concepts/indexes.md#index-uid) is required.

:::note
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.
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.
:::

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