索引
/indexes
路由允许您创建、管理和删除索引。
索引对象
{
"uid": "movies",
"createdAt": "2022-02-10T07:45:15.628261Z",
"updatedAt": "2022-02-21T15:28:43.496574Z",
"primaryKey": "id"
}
列出所有索引
GET/indexes
列出所有索引。结果可以使用 offset
和 limit
查询参数进行分页。
查询参数
查询参数 | 描述 | 默认值 |
---|---|---|
offset | 要跳过的索引数量 | 0 |
limit | 要返回的索引数量 | 20 |
响应
名称 | 类型 | 描述 |
---|---|---|
results | 数组 | 索引的数组 |
offset | offset | 整数 |
limit | offset | 跳过的索引数量 |
limit | offset | 返回的索引数量 |
total
curl \
-X GET 'MEILISEARCH_URL/indexes?limit=3'
Rust
{
"results": [
{
"uid": "books",
"createdAt": "2022-03-08T10:00:27.377346Z",
"updatedAt": "2022-03-08T10:00:27.391209Z",
"primaryKey": "id"
},
{
"uid": "meteorites",
"createdAt": "2022-03-08T10:00:44.518768Z",
"updatedAt": "2022-03-08T10:00:44.582083Z",
"primaryKey": "id"
},
{
"uid": "movies",
"createdAt": "2022-02-10T07:45:15.628261Z",
"updatedAt": "2022-02-21T15:28:43.496574Z",
"primaryKey": "id"
}
],
"offset": 0,
"limit": 3,
"total": 5
}
Swift
Dart
响应: 200 Ok
获取一个索引
名称 | 类型 | 描述 |
---|---|---|
GET/indexes/{index_uid} * | 字符串 | 获取关于一个索引的信息。 |
total
curl \
-X GET 'MEILISEARCH_URL/indexes/movies'
Rust
{
"uid": "movies",
"createdAt": "2022-02-10T07:45:15.628261Z",
"updatedAt": "2022-02-21T15:28:43.496574Z",
"primaryKey": "id"
}
路径参数
index_uid
字符串
请求索引的 uid
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
uid * | 字符串 | N/A | 获取关于一个索引的信息。 |
primaryKey | 字符串 / null | null | 创建索引 |
{
"uid": "movies",
"primaryKey": "id"
}
total
curl \
-X POST 'MEILISEARCH_URL/indexes' \
-H 'Content-Type: application/json' \
--data-binary '{
"uid": "movies",
"primaryKey": "id"
}'
POST/indexes
{
"taskUid": 0,
"indexUid": "movies",
"status": "enqueued",
"type": "indexCreation",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
创建索引。
请求体
primaryKey
字符串
响应: 202 Accepted
您可以使用响应的 taskUid
来跟踪您的请求状态。
获取一个索引
名称 | 类型 | 描述 |
---|---|---|
GET/indexes/{index_uid} * | 字符串 | 获取关于一个索引的信息。 |
请求索引的 uid
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
primaryKey * | 字符串 / null | N/A | 创建索引 |
total
curl \
-X PATCH 'MEILISEARCH_URL/indexes/movies' \
-H 'Content-Type: application/json' \
--data-binary '{ "primaryKey": "id" }'
POST/indexes
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "indexUpdate",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
创建索引。
更新索引
PATCH/indexes/{index_uid}
更新索引的主键。只要索引不包含任何文档,您就可以自由更新索引的主键。
获取一个索引
名称 | 类型 | 描述 |
---|---|---|
GET/indexes/{index_uid} * | 字符串 | 获取关于一个索引的信息。 |
total
curl \
-X DELETE 'MEILISEARCH_URL/indexes/movies'
POST/indexes
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "indexDeletion",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
创建索引。
要更改已包含文档的索引的主键,您必须首先删除该索引中的所有文档。然后,您可以更改主键并再次索引您的数据集。
注意
无法更改索引的 uid
。
删除索引
DELETE/indexes/{index_uid}
请求索引的 uid
交换索引
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
POST/swap-indexes * | 交换两个或多个索引的文档、设置和任务历史记录。您一次只能交换成对的索引。 但是,单个请求可以交换任意多对索引。 | N/A | 交换索引是一个原子事务:要么所有索引都成功交换,要么都不交换。 |
交换 indexA
和 indexB
也会在任务历史记录中将所有提及 indexA
的地方替换为 indexB
,反之亦然。enqueued
任务保持不变。
响应: 202 Accepted
要了解更多关于索引交换的信息,请参考这份简短指南。
total
curl \
-X POST 'MEILISEARCH_URL/swap-indexes' \
-H 'Content-Type: application/json' \
--data-binary '[
{
"indexes": [
"indexA",
"indexB"
]
},
{
"indexes": [
"indexX",
"indexY"
]
}
]'
响应
{
"taskUid": 3,
"indexUid": null,
"status": "enqueued",
"type": "indexSwap",
"enqueuedAt": "2021-08-12T10:00:00.000000Z"
}
响应: 202 Accepted
请求体
创建索引。