Indexes
An index is an entity that gathers a set of documents with its own settings.
Learn more about indexes.
List all indexes
GET
/indexes
List all indexes.
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
curl \ -X GET 'http://localhost:7700/indexes'
client.listIndexes()
client.get_indexes()
$client->getAllIndexes();
client.indexes
client.GetAllIndexes()
let indexes: Vec = 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
JavaScript
Python
PHP
Ruby
Go
Rust
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.GetIndex("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 primary keyAn attribute that must be present in every document of a given index, used to identify and distinguish documents.Example: In a document with the primary field “id”: “Abc_012”, “id” is the index’s primary key and “Abc_012” is the document’s unique identifier.of the documents |
{ "uid": "movies", "primaryKey": "movie_id"}
Example
cURL
JavaScript
Python
PHP
Ruby
Go
Rust
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.CreateIndex(&meilisearch.IndexConfig{ 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 primary keyAn attribute that must be present in every document of a given index, used to identify and distinguish documents.Example: In a document with the primary field “id”: “Abc_012”, “id” is the index’s primary key and “Abc_012” is the document’s unique identifier.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
JavaScript
Python
PHP
Ruby
Go
Rust
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_review_id']);// OR$client->index('movies')->update(['primaryKey' => 'movie_review_id']);
client.index('movies').update(primaryKey: 'movie_id')
client.Index("movies").UpdateIndex("movie_review_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
JavaScript
Python
PHP
Ruby
Go
Rust
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.DeleteIndex("movies")// ORclient.Index("movies").Delete()
movies.delete().await.unwrap();
