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
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X GET 'http://localhost:7700/indexes'
client.getIndexes()
client.get_indexes()
$client->getAllIndexes();
client.getAllIndexes();
client.indexes
client.GetAllIndexes()
let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();
client.getIndexes { (result: Result<[Indexes], Swift.Error>) in
switch result {
case .success(let indexes):
print(indexes)
case .failure(let error):
print(error)
}
}
await client.getIndexes();
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
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X GET 'http://localhost:7700/indexes/movies'
client.index('movies').getRawInfo()
client.get_index('movies')
$client->index('movies')->fetchRawInfo();
client.getIndex("movies");
client.fetch_index('movies')
client.GetIndex("movies")
let movies: Index = client.get_index("movies").await.unwrap();
client.getIndex("movies") { (result: Result<Indexes, Swift.Error>) in
switch result {
case .success(let index):
print(index)
case .failure(let error):
print(error)
}
}
await client.getIndex('movies');
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 primary key of the documents |
{
"uid": "movies",
"primaryKey": "movie_id"
}
Example
<>
cURL
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X POST 'http://localhost:7700/indexes' \
-H 'Content-Type: application/json' \
--data-binary '{
"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.createIndex("movies", "movie_id");
client.create_index('movies', primary_key: 'movie_id')
client.CreateIndex(&meilisearch.IndexConfig{
Uid: "movies",
PrimaryKey: "movie_id",
})
let movies: Index = client.create_index("movies", Some("movie_id")).await.unwrap();
client.createIndex(uid: "movies") { (result: Result<Indexes, Swift.Error>) in
switch result {
case .success(let index):
print(index)
case .failure(let error):
print(error)
}
}
await client.createIndex('movies', primaryKey: 'movie_id');
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 primary key 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
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X PUT 'http://localhost:7700/indexes/movie_review' \
-H 'Content-Type: application/json' \
--data-binary '{
"primaryKey" : "movie_review_id"
}'
client.updateIndex('movies', { primaryKey: 'movie_review_id' })
client.index('movies').update(primary_key='movie_review_id')
$client->updateIndex('movies', ['primaryKey' => 'movie_review_id']);
// OR
$client->index('movies')->update(['primaryKey' => 'movie_review_id']);
client.updateIndex("movie_review", "movie_review_id");
client.index('movies').update(primary_key: 'movie_id')
client.Index("movie_review").UpdateIndex("movie_review_id")
let movie_review: Index = client.get_index("movie_review").await.unwrap();
movie_review.update("movie_review_id").await.unwrap();
client.index("movies").update(primaryKey: "movie_review_id") { (result: Result<Indexes, Swift.Error>) in
switch result {
case .success(let index):
print(index)
case .failure:
print(error)
}
}
await client.index('movies').update(primaryKey: 'movie_review_id');
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
JS
Python
PHP
Java
Ruby
Go
Rust
Swift
Dart
curl \
-X DELETE 'http://localhost:7700/indexes/movies'
client.deleteIndex('movies')
client.index('movies').delete()
$client->deleteIndex('movies');
// OR
$client->index('movies')->delete();
client.deleteIndex("movies");
client.delete_index('movies')
client.DeleteIndex("movies")
// OR
client.Index("movies").Delete()
movies.delete().await.unwrap();
client.index("movies").delete { (result: Result<(), Swift.Error>) in
switch result {
case .success:
print("Index deleted")
case .failure:
print(error)
}
}
await client.index('movies').delete();