Indexes
An index is an entity that gathers a set of documents with its own settings.
List all indexes
GET
/indexes
List all indexes.
Example
curl \
-X GET 'http://localhost:7700/indexes'
client.listIndexes()
client.get_indexes()
$client->getAllIndexes();
client.indexes
client.Indexes().List()
let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();
Response: 200 Ok
[
{
"uid": "movies",
"primaryKey": "movie_id",
"createdAt": "2019-11-20T09:40:33.711324Z",
"updatedAt": "2019-11-20T10:16:42.761858Z"
},
{
"uid": "movie_reviews",
"primaryKey": null,
"createdAt": "2019-11-20T09:40:33.711324Z",
"updatedAt": "2019-11-20T10:16:42.761858Z"
}
]
Get one index
GET
/indexes/:index_uid
Get information about an index.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
curl \
-X GET 'http://localhost:7700/indexes/movies'
client.index('movies').getRawInfo()
client.get_index('movies')
$client->index('movies')->fetchRawInfo();
client.fetch_index('movies')
client.Indexes().Get("movies")
let movies: Index = client.get_index("movies").await.unwrap();
Response: 200 Ok
{
"uid": "movies",
"primaryKey": "movie_id",
"createdAt": "2019-11-20T09:40:33.711324Z",
"updatedAt": "2019-11-20T10:16:42.761858Z"
}
Create an index
POST
/indexes
Create an index.
This route takes as parameter an unique uid
and optionally the primary key.
NOTE
An index is automatically created when adding documents or settings to an index that does not already exist.
Body
Variable | Description |
---|---|
index_uid | The index unique identifier (mandatory) |
primaryKey | The of the documents |
{
"uid": "movies",
"primaryKey": "movie_id"
}
Example
curl \
-X POST 'http://localhost:7700/indexes' \
--data '{
"uid": "movies",
"primaryKey": "movie_id"
}'
client.createIndex('movies', { primaryKey: 'movie_id' })
client.create_index('movies', {'primaryKey': 'movie_id'})
$client->createIndex('movies', ['primaryKey' => 'movie_id']);
client.create_index('movies', primaryKey: 'movie_id')
client.Indexes().Create(meilisearch.CreateIndexRequest{
UID: "movies",
PrimaryKey: "movie_id",
})
let movies: Index = client.create_index("movies", Some("movie_id")).await.unwrap();
Response: 201 created
{
"uid": "movies",
"primaryKey": "movie_id",
"createdAt": "2019-11-20T09:40:33.711476Z",
"updatedAt": "2019-11-20T09:40:33.711476Z"
}
Update an index
PUT
/indexes/:index_uid
Update an index.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Body
Variable | Description |
---|---|
primaryKey | The of the documents |
The uid
of an index cannot be changed.
The primaryKey
can be added if it does not already exist (to know if it has been set, use the get index route).
There are many ways in MeiliSearch to set the primary key.
Example
curl \
-X PUT 'http://localhost:7700/indexes/movie_review' \
--data '{
"primaryKey" : "movie_review_id"
}'
client.updateIndex('movies', { primaryKey: 'movie_review_id' })
client.index('movies').update(primaryKey='movie_review_id')
$client->updateIndex('movies', ['primaryKey' => 'movie_id']);
// OR
$client->index('movies')->update(['primaryKey' => 'movie_id']);
client.index('movies').update(primaryKey: 'movie_id')
response, error := client.Indexes().Get("movies")
client.Indexes().UpdatePrimaryKey(response.UID, "movie_id")
let movie_review: Index = client.get_index("movie_review").await.unwrap();
movie_review.update("movie_review_id").await.unwrap();
Response: 200 Ok
{
"uid": "movie_review",
"primaryKey": "movie_review_id",
"createdAt": "2019-11-20T09:40:33.711324Z",
"updatedAt": "2019-11-20T10:16:42.761858Z"
}
Delete an index
DELETE
/indexes/:index_uid
Delete an index.
Path Variables
Variable | Description |
---|---|
index_uid | The index UID |
Example
curl \
-X DELETE 'http://localhost:7700/indexes/movies'
client.deleteIndex('movies')
client.index('movies').delete()
$client->deleteIndex('movies');
// OR
$client->index('movies')->delete();
client.delete_index('movies')
client.Indexes().Delete("movies")
movies.delete().await.unwrap();
Response: 204 No Content
当前内容版权归 meilisearch 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 meilisearch .