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

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X GET 'http://localhost:7700/indexes'
  1. client.getIndexes()
  1. client.get_indexes()
  1. $client->getAllIndexes();
  1. client.getAllIndexes();
  1. client.indexes
  1. client.GetAllIndexes()
  1. let indexes: Vec<Index> = client.list_all_indexes().await.unwrap();
  1. client.getIndexes { (result: Result<[Indexes], Swift.Error>) in
  2. switch result {
  3. case .success(let indexes):
  4. print(indexes)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.getIndexes();

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

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  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.getIndex("movies");
  1. client.fetch_index('movies')
  1. client.GetIndex("movies")
  1. let movies: Index = client.get_index("movies").await.unwrap();
  1. client.getIndex("movies") { (result: Result<Indexes, Swift.Error>) in
  2. switch result {
  3. case .success(let index):
  4. print(index)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.getIndex('movies');

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 primary key of the documents
  1. {
  2. "uid": "movies",
  3. "primaryKey": "movie_id"
  4. }

Example

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  1. curl \
  2. -X POST 'http://localhost:7700/indexes' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "uid": "movies",
  6. "primaryKey": "movie_id"
  7. }'
  1. client.createIndex('movies', { primaryKey: 'movie_id' })
  1. client.create_index('movies', {'primaryKey': 'movie_id'})
  1. $client->createIndex('movies', ['primaryKey' => 'movie_id']);
  1. client.createIndex("movies", "movie_id");
  1. client.create_index('movies', primary_key: 'movie_id')
  1. client.CreateIndex(&meilisearch.IndexConfig{
  2. Uid: "movies",
  3. PrimaryKey: "movie_id",
  4. })
  1. let movies: Index = client.create_index("movies", Some("movie_id")).await.unwrap();
  1. client.createIndex(uid: "movies") { (result: Result<Indexes, Swift.Error>) in
  2. switch result {
  3. case .success(let index):
  4. print(index)
  5. case .failure(let error):
  6. print(error)
  7. }
  8. }
  1. await client.createIndex('movies', primaryKey: 'movie_id');

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

  1. curl \
  2. -X PUT 'http://localhost:7700/indexes/movie_review' \
  3. -H 'Content-Type: application/json' \
  4. --data-binary '{
  5. "primaryKey" : "movie_review_id"
  6. }'
  1. client.updateIndex('movies', { primaryKey: 'movie_review_id' })
  1. client.index('movies').update(primary_key='movie_review_id')
  1. $client->updateIndex('movies', ['primaryKey' => 'movie_review_id']);
  2. // OR
  3. $client->index('movies')->update(['primaryKey' => 'movie_review_id']);
  1. client.updateIndex("movie_review", "movie_review_id");
  1. client.index('movies').update(primary_key: 'movie_id')
  1. client.Index("movie_review").UpdateIndex("movie_review_id")
  1. let movie_review: Index = client.get_index("movie_review").await.unwrap();
  2. movie_review.update("movie_review_id").await.unwrap();
  1. client.index("movies").update(primaryKey: "movie_review_id") { (result: Result<Indexes, Swift.Error>) in
  2. switch result {
  3. case .success(let index):
  4. print(index)
  5. case .failure:
  6. print(error)
  7. }
  8. }
  1. await client.index('movies').update(primaryKey: 'movie_review_id');

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

<>

cURL

JS

Python

PHP

Java

Ruby

Go

Rust

Swift

Dart

  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.deleteIndex("movies");
  1. client.delete_index('movies')
  1. client.DeleteIndex("movies")
  2. // OR
  3. client.Index("movies").Delete()
  1. movies.delete().await.unwrap();
  1. client.index("movies").delete { (result: Result<(), Swift.Error>) in
  2. switch result {
  3. case .success:
  4. print("Index deleted")
  5. case .failure:
  6. print(error)
  7. }
  8. }
  1. await client.index('movies').delete();

Response: 204 No Content