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

JavaScript

Python

PHP

Ruby

Go

Rust

  1. curl \
  2. -X GET 'http://localhost:7700/indexes'
  1. client.listIndexes()
  1. client.get_indexes()
  1. $client->getAllIndexes();
  1. client.indexes
  1. client.GetAllIndexes()
  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

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

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

Example

cURL

JavaScript

Python

PHP

Ruby

Go

Rust

  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.CreateIndex(&meilisearch.IndexConfig{
  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 primary key
An 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

  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_review_id']);
  2. // OR
  3. $client->index('movies')->update(['primaryKey' => 'movie_review_id']);
  1. client.index('movies').update(primaryKey: 'movie_id')
  1. client.Index("movies").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();

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

JavaScript

Python

PHP

Ruby

Go

Rust

  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.DeleteIndex("movies")
  2. // OR
  3. client.Index("movies").Delete()
  1. movies.delete().await.unwrap();

Response: 204 No Content