Indexes

An index is an entity that gathers a set of documents with its own settings.

Learn more about indexes.

List all indexes

GET

  1. /indexes

List all indexes.

Example

  1. $ curl \
  2. -X GET 'http://localhost:7700/indexes'
  1. client.listIndexes()
  1. client.get_indexes()
  1. $client->getAllIndexes();
  1. client.indexes
  1. client.Indexes().List()
  1. let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();

Response: 200 Ok

  1. [
  2. {
  3. "uid": "movies",
  4. "primaryKey": "movie_id",
  5. "createdAt": "2019-11-20T09:40:33.711324Z",
  6. "updatedAt": "2019-11-20T10:16:42.761858Z"
  7. },
  8. {
  9. "uid": "movie_reviews",
  10. "primaryKey": null,
  11. "createdAt": "2019-11-20T09:40:33.711324Z",
  12. "updatedAt": "2019-11-20T10:16:42.761858Z"
  13. }
  14. ]

Get one index

GET

  1. /indexes/:index_uid

Get information about an index.

Path Variables

VariableDescription
index_uidThe index UID

Example

  1. $ curl \
  2. -X GET 'http://localhost:7700/indexes/movies'
  1. client.index('movies').getRawInfo()
  1. client.get_index('movies')
  1. $client->index('movies')->fetchRawInfo();
  1. client.fetch_index('movies')
  1. client.Indexes().Get("movies")
  1. let movies: Index = client.get_index("movies").await.unwrap();

Response: 200 Ok

  1. {
  2. "uid": "movies",
  3. "primaryKey": "movie_id",
  4. "createdAt": "2019-11-20T09:40:33.711324Z",
  5. "updatedAt": "2019-11-20T10:16:42.761858Z"
  6. }

Create an index

POST

  1. /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

VariableDescription
index_uidThe index unique identifier (mandatory)
primaryKeyThe of the documents
  1. {
  2. "uid": "movies",
  3. "primaryKey": "movie_id"
  4. }

Example

  1. $ curl \
  2. -X POST 'http://localhost:7700/indexes' \
  3. --data '{
  4. "uid": "movies",
  5. "primaryKey": "movie_id"
  6. }'
  1. client.createIndex('movies', { primaryKey: 'movie_id' })
  1. client.create_index('movies', {'primaryKey': 'movie_id'})
  1. $client->createIndex('movies', ['primaryKey' => 'movie_id']);
  1. client.create_index('movies', primaryKey: 'movie_id')
  1. client.Indexes().Create(meilisearch.CreateIndexRequest{
  2. UID: "movies",
  3. PrimaryKey: "movie_id",
  4. })
  1. let movies: Index = client.create_index("movies", Some("movie_id")).await.unwrap();

Response: 201 created

  1. {
  2. "uid": "movies",
  3. "primaryKey": "movie_id",
  4. "createdAt": "2019-11-20T09:40:33.711476Z",
  5. "updatedAt": "2019-11-20T09:40:33.711476Z"
  6. }

Update an index

PUT

  1. /indexes/:index_uid

Update an index.

Path Variables

VariableDescription
index_uidThe index UID

Body

VariableDescription
primaryKeyThe 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

  1. $ curl \
  2. -X PUT 'http://localhost:7700/indexes/movie_review' \
  3. --data '{
  4. "primaryKey" : "movie_review_id"
  5. }'
  1. client.updateIndex('movies', { primaryKey: 'movie_review_id' })
  1. client.index('movies').update(primaryKey='movie_review_id')
  1. $client->updateIndex('movies', ['primaryKey' => 'movie_id']);
  2. // OR
  3. $client->index('movies')->update(['primaryKey' => 'movie_id']);
  1. client.index('movies').update(primaryKey: 'movie_id')
  1. response, error := client.Indexes().Get("movies")
  2. client.Indexes().UpdatePrimaryKey(response.UID, "movie_id")
  1. let movie_review: Index = client.get_index("movie_review").await.unwrap();
  2. movie_review.update("movie_review_id").await.unwrap();

Response: 200 Ok

  1. {
  2. "uid": "movie_review",
  3. "primaryKey": "movie_review_id",
  4. "createdAt": "2019-11-20T09:40:33.711324Z",
  5. "updatedAt": "2019-11-20T10:16:42.761858Z"
  6. }

Delete an index

DELETE

  1. /indexes/:index_uid

Delete an index.

Path Variables

VariableDescription
index_uidThe index UID

Example

  1. $ curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies'
  1. client.deleteIndex('movies')
  1. client.index('movies').delete()
  1. $client->deleteIndex('movies');
  2. // OR
  3. $client->index('movies')->delete();
  1. client.delete_index('movies')
  1. client.Indexes().Delete("movies")
  1. movies.delete().await.unwrap();

Response: 204 No Content