Documents

Documents are objects composed of fields that can store any type of data.
Each field contains an attribute and its associated value.

Documents are stored inside indexes.
Learn more about documents.

Get one document

GET

  1. /indexes/:index_uid/documents/:document_id

Get one document using its unique id.

Path Variables

VariableDescription
index_uidThe index UID
document_idThe document id

Example

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/movies/documents/25684'
  1. client.getDocument(25684)
  1. client.index('movies').get_document(25684)
  1. $client->index('movies')->getDocument(25684);
  1. index.document(25684)
  1. var a interface{}
  2. client.Documents("movies").Get("25684", &a)
  1. let movie: Movie = movies.get_document(String::from("25684")).await.unwrap();

Response: 200 Ok

  1. {
  2. "id": 25684,
  3. "title": "American Ninja 5",
  4. "poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
  5. "overview": "When a scientists daughter is kidnapped, American Ninja, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the ninja.",
  6. "release_date": "1993-01-01"
  7. }

Get documents

GET

  1. /indexes/:index_uid/documents

Get documents by batch.

Using the query parameters offset and limit, you can browse through all your documents.

NOTE

Documents are ordered by MeiliSearch depending on the hash of their id.

Path Variables

VariableDescription
index_uidThe index UID

Query Parameters

Query ParameterDescriptionDefault Value
offsetnumber of documents to skip0
limitnumber of documents to take20
attributesToRetrievedocument attributes to show*

Example

  1. curl \
  2. -X GET 'http://localhost:7700/indexes/movies/documents?limit=2'
  1. client.index('movies').getDocuments({ limit: 2 })
  1. client.index('movies').get_documents({'limit':2})
  1. $client->index('movies')->getDocuments(['limit' => 2]);
  1. index.documents(limit: 2)
  1. var a []interface{}
  2. client.Documents("movies").List(meilisearch.ListDocumentsRequest{
  3. Limit: 2,
  4. }, &a)
  1. let documents: Vec<Movie> = movies.get_documents(None, Some(2), None).await.unwrap();

Response: 200 Ok

  1. [
  2. {
  3. "id": 25684,
  4. "release_date": "1993-01-01",
  5. "poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
  6. "title": "American Ninja 5",
  7. "overview": "When a scientists daughter is kidnapped, American Ninja, attempts to find her, but this time he teams up with a youngster he has trained in the ways of the ninja."
  8. },
  9. {
  10. "id": 468219,
  11. "title": "Dead in a Week (Or Your Money Back)",
  12. "release_date": "2018-09-12",
  13. "poster": "https://image.tmdb.org/t/p/w1280/f4ANVEuEaGy2oP5M0Y2P1dwxUNn.jpg",
  14. "overview": "William has failed to kill himself so many times that he outsources his suicide to aging assassin Leslie. But with the contract signed and death assured within a week (or his money back), William suddenly discovers reasons to live... However Leslie is under pressure from his boss to make sure the contract is completed."
  15. }
  16. ]

Add or replace documents

POST

  1. /indexes/:index_uid/documents

Add a list of documents or replace them if they already exist. If the provided index does not exist, it will be created.

If you send an already existing document (same id) the whole existing document will be overwritten by the new document. Fields previously in the document not present in the new document are removed.

For a partial update of the document see add or update documents.

If the provided index does not exist, it will be created.

Path Variables

VariableDescription
index_uidThe index UID

Query Parameters

Query ParameterDescriptionDefault Value
primaryKeyThe primary key of the documents (optional)none

If you want to set the primary key of your index through this route, it only has to be done the first time you add documents to the index. After which it will be ignored if given.

Body

The body is composed of a JSON array of documents.

  1. [
  2. {
  3. "id": 287947,
  4. "title": "Shazam",
  5. "poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
  6. "overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
  7. "release_date": "2019-03-23"
  8. }
  9. ]

Example

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/documents' \
  3. --data '[{
  4. "id": 287947,
  5. "title": "Shazam",
  6. "poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
  7. "overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
  8. "release_date": "2019-03-23"
  9. }]'
  1. client.index('movies').addDocuments([{
  2. id: 287947,
  3. title: 'Shazam',
  4. poster: 'https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg',
  5. overview: 'A boy is given the ability to become an adult superhero in times of need with a single magic word.',
  6. release_date: '2019-03-23'
  7. }])
  1. client.index('movies').add_documents([{
  2. 'id': 287947,
  3. 'title': 'Shazam',
  4. 'poster': 'https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg',
  5. 'overview': 'A boy is given the ability to become an adult superhero in times of need with a single magic word.',
  6. 'release_date': '2019-03-23'
  7. }])
  1. $client->index('movies')->addDocuments([
  2. [
  3. 'id' => 287947
  4. 'title' => 'Shazam',
  5. 'poster' => 'https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg',
  6. 'overview' => 'A boy is given the ability to become an adult superhero in times of need with a single magic word.',
  7. 'release_date' => '2019-03-23'
  8. ]
  9. ]);
  1. index.add_documents([
  2. {
  3. id: 287947,
  4. title: 'Shazam',
  5. poster: 'https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg',
  6. overview: 'A boy is given the ability to become an adult superhero in times of need with a single magic word.',
  7. release_date: '2019-03-23'
  8. }
  9. ])
  1. documents := []map[string]interface{}{
  2. {
  3. "id": 287947,
  4. "title": "Shazam",
  5. "poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
  6. "overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
  7. "release_date": "2019-03-23",
  8. },
  9. }
  10. client.Documents("movies").AddOrReplace(documents)
  1. let progress: Progress = movies.add_or_replace(&[
  2. Movie {
  3. id: 287947,
  4. title: "Shazam".to_string(),
  5. poster: "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg".to_string(),
  6. overview: "A boy is given the ability to become an adult superhero in times of need with a single magic word.".to_string(),
  7. release_date: "2019-03-23".to_string(),
  8. }
  9. ], None).await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

Add or update documents

PUT

  1. /indexes/:index_uid/documents

Add a list of documents or update them if they already exist. If the provided index does not exist, it will be created.

If you send an already existing document (same id) the old document will be only partially updated according to the fields of the new document. Thus, any fields not present in the new document are kept and remained unchanged.

To completely overwrite a document, check out the add or replace documents route.

If the provided index does not exist, it will be created.

Path Variables

VariableDescription
index_uidThe index UID

If you want to set the primary key of your index through this route, it only has to be done the first time you add documents to the index. After which it will be ignored if given.

Query Parameters

Query ParameterDescriptionDefault Value
primaryKeyThe primary key of the documents (optional)none

Body

The body is composed of a JSON array of documents.

  1. [
  2. {
  3. "id": 287947,
  4. "title": "Shazam ⚡️"
  5. }
  6. ]

Example

  1. curl \
  2. -X PUT 'http://localhost:7700/indexes/movies/documents' \
  3. --data '[{
  4. "id": 287947,
  5. "title": "Shazam ⚡️",
  6. "genres": "comedy"
  7. }]'
  1. client.index('movies').updateDocuments([{
  2. id: 287947,
  3. title: 'Shazam ⚡️',
  4. genres: 'comedy'
  5. }])
  1. client.index('movies').update_documents([{
  2. 'id': 287947,
  3. 'title': 'Shazam ⚡️',
  4. 'genres': 'comedy'
  5. }])
  1. $client->index('movies')->updateDocuments([
  2. [
  3. 'id' => 287947
  4. 'title' => 'Shazam ⚡️',
  5. 'genres' => 'comedy'
  6. ]
  7. ]);
  1. index.update_documents([
  2. {
  3. id: 287947,
  4. title: 'Shazam ⚡️',
  5. genres: 'comedy'
  6. }
  7. ])
  1. documents := []map[string]interface{}{
  2. {
  3. "id": 287947,
  4. "title": "Shazam",
  5. "genres": "comedy",
  6. },
  7. }
  8. client.Documents("movies").AddOrUpdate(documents)
  1. // Define the type of our documents
  2. #[derive(Serialize, Deserialize, Debug)]
  3. struct IncompleteMovie {
  4. id: usize,
  5. title: String
  6. }
  7. impl Document for IncompleteMovie {
  8. type UIDType = usize;
  9. fn get_uid(&self) -> &Self::UIDType { &self.id }
  10. }
  11. let progress: Progress = movies.add_or_update(&[
  12. IncompleteMovie {
  13. id: 287947,
  14. title: "Shazam ⚡️".to_string()
  15. }
  16. ], None).await.unwrap();

This document is an update of the document found in add or replace document.
The documents are matched because they have the same primaryKey value id: 287947. This route will update the title field as it changed from Shazam to Shazam ⚡️ and add the new genres field to that document. The rest of the document will remain unchanged.

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

Delete all documents

DELETE

  1. /indexes/:index_uid/documents

Delete all documents in the specified index.

Path Variables

VariableDescription
index_uidThe index UID

Example

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies/documents'
  1. client.index('movies').deleteAllDocuments()
  1. client.index('movies').delete_all_documents()
  1. $client->index('movies')->deleteAllDocuments();
  1. index.delete_all_documents
  1. client.Documents("movies").DeleteAllDocuments()
  1. let progress: Progress = movies.delete_all_documents().await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

Delete one document

DELETE

  1. /indexes/:index_uid/documents/:document_id

Delete one document based on its unique id.

Path Variables

VariableDescription
index_uidThe index UID
document_idThe document id

Example

  1. curl \
  2. -X DELETE 'http://localhost:7700/indexes/movies/documents/25684'
  1. client.index('movies').deleteDocument(25684)
  1. client.index('movies').delete_document(25684)
  1. $client->index('movies')->deleteDocument(25684);
  1. index.delete_document(25684)
  1. client.Documents("movies").Delete("25684")
  1. let progress: Progress = movies.delete_document(25684).await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.

Delete documents

POST

  1. /indexes/:index_uid/documents/delete-batch

Delete a selection of documents based on array of document id’s.

Path Variables

VariableDescription
index_uidThe index UID

Body

The body must be a JSON Array with the unique id’s of the documents to delete.

  1. [23488, 153738, 437035, 363869]

Example

  1. curl \
  2. -X POST 'http://localhost:7700/indexes/movies/documents/delete-batch' \
  3. --data '[
  4. 23488,
  5. 153738,
  6. 437035,
  7. 363869
  8. ]'
  1. client.index('movies').deleteDocuments([23488, 153738, 437035, 363869])
  1. client.index('movies').delete_documents([23488, 153738, 437035, 363869])
  1. $client->index('movies')->deleteDocuments([23488, 153738, 437035, 363869]);
  1. index.delete_documents([23488, 153738, 437035, 363869])
  1. client.Documents("movies").Deletes([]string{
  2. "23488",
  3. "153738",
  4. "437035",
  5. "363869",
  6. })
  1. let progress: Progress = movies.delete_documents(&[23488, 153738, 437035, 363869]).await.unwrap();

Response: 202 Accepted

  1. {
  2. "updateId": 1
  3. }

This updateId allows you to track the current update.