Skip to content

Commit 885456e

Browse files
Add documentation for index renaming (#3351)
1 parent 41975b1 commit 885456e

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

.code-samples.meilisearch.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ webhooks_patch_1: |-
15081508
webhooks_delete_1: |-
15091509
curl \
15101510
-X DELETE 'MEILISEARCH_URL/webhooks/WEBHOOK_UUID'
1511+
rename_an_index_1: |-
1512+
curl \
1513+
-X PATCH 'MEILISEARCH_URL/indexes/INDEX_A' \
1514+
-H 'Content-Type: application/json' \
1515+
--data-binary '{ "uid": "INDEX_B" }'
1516+
15111517
15121518
### Code samples for experimental features
15131519
experimental_get_metrics_1: |-

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@
277277
{
278278
"group": "Indexing",
279279
"pages": [
280+
"learn/indexing/rename_an_index",
280281
"learn/indexing/indexing_best_practices",
281282
"learn/indexing/ram_multithreading_performance",
282283
"learn/indexing/tokenization"

learn/getting_started/indexes.mdx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ While implicit index creation is more convenient, requiring only a single API re
3737

3838
The `uid` is the **unique identifier** of an index. It is set when creating the index and must be an integer or string containing only alphanumeric characters `a-z A-Z 0-9`, hyphens `-` and underscores `_`.
3939

40-
**Once defined, the `uid` cannot be changed**, and you cannot create another index with the same `uid`.
41-
4240
```json
4341
{
4442
"uid": "movies",
@@ -47,6 +45,8 @@ The `uid` is the **unique identifier** of an index. It is set when creating the
4745
}
4846
```
4947

48+
You can change an index's `uid` using the [`/indexes` API route](/reference/api/indexes#update-an-index).
49+
5050
## Primary key
5151

5252
Every index has a primary key: a required attribute that must be present in all documents in the index. Each document must have a unique value associated with this attribute.
@@ -61,19 +61,6 @@ You can set the primary key for an index or let it be inferred by Meilisearch. R
6161

6262
Index settings can be thought of as a JSON object containing many different options for customizing search behavior.
6363

64-
You can customize the following index settings:
65-
66-
- [Displayed and searchable attributes](#displayed-and-searchable-attributes)
67-
- [Distinct attribute](#distinct-attribute)
68-
- [Faceting](#faceting)
69-
- [Filterable attributes](#filterable-attributes)
70-
- [Pagination](#pagination)
71-
- [Ranking rules](#ranking-rules)
72-
- [Sortable attributes](#sortable-attributes)
73-
- [Stop words](#stop-words)
74-
- [Synonyms](#synonyms)
75-
- [Typo tolerance](#typo-tolerance)
76-
7764
To change index settings, use the [update settings endpoint](/reference/api/settings#update-settings) or any of the child routes.
7865

7966
### Displayed and searchable attributes

learn/indexing/rename_an_index.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Rename an index
3+
description: Use the PATCH endpoint of the /indexes route to rename an index
4+
---
5+
6+
import CodeSamplesRenameAnIndex1 from '/snippets/samples/code_samples_rename_an_index_1.mdx';
7+
8+
This guide shows you how to change the name of an index.
9+
10+
## Requirements
11+
12+
- A Meilisearch project with at least one index
13+
- A command-line terminal
14+
15+
## Choose the target index and its new name
16+
17+
Decide which index you want to rename and keep note of its `uid`. This guide changes the name of an index called `INDEX_A`.
18+
19+
Also choose the new name you wish to assign the index. This guide uses `INDEX_B` for the new name of the index.
20+
21+
## Query the `/indexes/{index_uid}` route
22+
23+
Send a `PATCH` request targeting the index you want to rename:
24+
25+
<CodeSamplesRenameAnIndex1 />
26+
27+
Replace `INDEX_A` with the current name of your index, and `INDEX_B` with its new name.

reference/api/indexes.mdx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ Update an index's [primary key](/learn/getting_started/primary_key#primary-key).
164164

165165
To change the primary key of an index that already contains documents, you must first delete all documents in that index. You may then change the primary key and index your dataset again.
166166

167-
<Note>
168-
It is not possible to change an index's `uid`.
169-
</Note>
170-
171167
### Path parameters
172168

173169
| Name | Type | Description |
@@ -179,6 +175,7 @@ It is not possible to change an index's `uid`.
179175
| Name | Type | Default value | Description |
180176
| :----------------- | :-------------- | :------------ | :---------------------------------------------------------------------------------------- |
181177
| **`primaryKey`** * | String / `null` | N/A | [`Primary key`](/learn/getting_started/primary_key#primary-field) of the requested index |
178+
| **`uid`** * | String / `null` | N/A | New `uid` of the requested index |
182179

183180
### Example
184181

@@ -230,33 +227,28 @@ You can use the response's `taskUid` to [track the status of your request](/refe
230227

231228
## Swap indexes
232229

233-
```http
234-
POST /swap-indexes
235-
```
236-
237230
<RouteHighlighter method="POST" path="/swap-indexes" />
238231

239-
Swap the documents, settings, and task history of two or more indexes. **You can only swap indexes in pairs.** However, a single request can swap as many index pairs as you wish.
232+
Swap the documents, settings, and task history of two or more indexes. **You can only swap indexes in pairs.** A single request can swap as many index pairs as you wish.
240233

241-
Swapping indexes is an atomic transaction: **either all indexes are successfully swapped, or none are.**
234+
Swapping indexes is an atomic transaction: **either all indexes in a request are successfully swapped, or none are.** You can swap multiple pairs of indexes with a single request. To do so, there must be one object for each pair of indexes to be swapped.
242235

243236
Swapping `indexA` and `indexB` will also replace every mention of `indexA` by `indexB` and vice-versa in the task history. `enqueued` tasks are left unmodified.
244237

245238
[To learn more about index swapping, refer to this short guide.](/learn/getting_started/indexes#swapping-indexes)
246239

247240
### Body
248241

249-
An array of objects. Each object has only one key: `indexes`.
242+
An array of objects with the following fields:
250243

251-
| Name | Type | Default value | Description |
252-
| :------------- | :--------------- | :------------ | :----------------------------------------- |
253-
| **`indexes`*** | Array of strings | N/A | Array of the two `indexUid`s to be swapped |
244+
| Name | Type | Default value | Description |
245+
| :------------- | :--------------- | :------------ | :------------------------------------------------- |
246+
| **`indexes`** | Array of strings | N/A | Array of the two `indexUid`s to be swapped |
247+
| **`rename`** | Boolean | `false` | If `true`, renames an index instead of swapping it |
254248

255249
Each `indexes` array must contain only two elements: the `indexUid`s of the two indexes to be swapped. Sending an empty array (`[]`) is valid, but no swap operation will be performed.
256250

257-
<Note>
258-
You can swap multiple pairs of indexes with a single request. To do so, there must be one object for each pair of indexes to be swapped.
259-
</Note>
251+
Use `rename: false` if you are swapping two existing indexes. Use `rename: true` if the second index in your array does not exist.
260252

261253
### Example
262254

0 commit comments

Comments
 (0)