# Documents
The /documents route allows you to create, manage, and delete documents.
# Get one document
/indexes/{index_uid}/documents/{document_id}Get one document using its unique id. Both the index uid and document id are required.
You can use the optional fields query parameter to specify which document fields Meilisearch should include in the response body. fields accepts a case-sensitive list of document fields separated by a comma.
# Query parameters
| Query Parameter | Description | Default Value |
|---|---|---|
| fields | Document attributes to show | * |
# Example
curl \
-X GET 'http://localhost:7700/indexes/movies/documents/25684?fields=id,title,poster,release_date'
# Response: 200 Ok
{
"id": 25684,
"title": "American Ninja 5",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"release_date": "1993-01-01"
}
# Get documents
/indexes/{index_uid}/documentsGet documents by batch. The index uid is required.
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.
# Query parameters
| Query Parameter | Description | Default Value |
|---|---|---|
| offset | Number of documents to skip | 0 |
| limit | Number of documents to return | 20 |
| fields | Document attributes to show | * |
# Example
curl \
-X GET 'http://localhost:7700/indexes/movies/documents?limit=2'
# Response: 200 Ok
{
"results": [
{
"id": 25684,
"release_date": "1993-01-01",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"title": "American Ninja 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."
},
{
"id": 468219,
"title": "Dead in a Week (Or Your Money Back)",
"release_date": "2018-09-12",
"poster": "https://image.tmdb.org/t/p/w1280/f4ANVEuEaGy2oP5M0Y2P1dwxUNn.jpg",
"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."
}
],
"offset": 0,
"limit": 2,
"total": 500134
}
NOTE
The response's total value response indicates the total number of documents in the queried index.
# Add or replace documents
/indexes/{index_uid}/documentsAdd a list of documents or replace them if they already exist. If the provided index does not exist, it will be created. The index uid is required.
If you send an already existing document (same document id) the whole existing document will be overwritten by the new document. Fields that are no longer present in the new document are removed.
For a partial update of the document see add or update documents.
# Query parameters
| Query Parameter | Description | Default Value |
|---|---|---|
| primaryKey | The primary key of the index (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.
[
{
"id": 287947,
"title": "Shazam",
"poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
"overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
"release_date": "2019-03-23"
}
]
# Example
curl \
-X POST 'http://localhost:7700/indexes/movies/documents' \
-H 'Content-Type: application/json' \
--data-binary '[
{
"id": 287947,
"title": "Shazam",
"poster": "https://image.tmdb.org/t/p/w1280/xnopI5Xtky18MPhK40cZAGAOVeV.jpg",
"overview": "A boy is given the ability to become an adult superhero in times of need with a single magic word.",
"release_date": "2019-03-23"
}
]'
# Response: 202 Accepted
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentAdditionOrUpdate",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
You can use this taskUid to get more details on the status of the task.
# Add or update documents
/indexes/{index_uid}/documentsAdd a list of documents or update them if they already exist. If the provided index does not exist, it will be created. The index uid is required.
If you send an already existing document (same document 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.
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 Parameter | Description | Default Value |
|---|---|---|
| primaryKey | The primary key of the documents (optional) | none |
# Body
The body is composed of a JSON array of documents.
[
{
"id": 287947,
"title": "Shazam ⚡️"
}
]
# Example
curl \
-X PUT 'http://localhost:7700/indexes/movies/documents' \
-H 'Content-Type: application/json' \
--data-binary '[
{
"id": 287947,
"title": "Shazam ⚡️",
"genres": "comedy"
}
]'
This document is an update of the document found in add or replace document.
The documents are matched because they have the same primary key 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
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentAdditionOrUpdate",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
You can use this taskUid to get more details on the status of the task.
# Delete all documents
/indexes/{index_uid}/documentsDelete all documents in the specified index. The index uid is required.
# Example
curl \
-X DELETE 'http://localhost:7700/indexes/movies/documents'
# Response: 202 Accepted
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
You can use this taskUid to get more details on the status of the task.
# Delete one document
/indexes/{index_uid}/documents/{document_id}Delete one document based on its unique id. Both the index uid and document id are required.
# Example
curl \
-X DELETE 'http://localhost:7700/indexes/movies/documents/25684'
# Response: 202 Accepted
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
You can use this taskUid to get more details on the status of the task.
# Delete documents by batch
/indexes/{index_uid}/documents/delete-batchDelete a selection of documents based on array of document id's. The index uid is required.
# Body
The body must be a JSON Array with the unique id's of the documents to delete.
[23488, 153738, 437035, 363869]
# Example
curl \
-X POST 'http://localhost:7700/indexes/movies/documents/delete-batch' \
-H 'Content-Type: application/json' \
--data-binary '[
23488,
153738,
437035,
363869
]'
# Response: 202 Accepted
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2021-08-11T09:25:53.000000Z"
}
You can use this taskUid to get more details on the status of the task.