| title | Documents |
|---|---|
| sidebarTitle | Documents |
| description | The /documents route allows you to create, manage, and delete documents. |
import { RouteHighlighter } from '/snippets/route_highlighter.mdx' import { NoticeTag } from '/snippets/notice_tag.mdx';
import CodeSamplesAddOrReplaceDocuments1 from '/snippets/samples/code_samples_add_or_replace_documents_1.mdx'; import CodeSamplesAddOrUpdateDocuments1 from '/snippets/samples/code_samples_add_or_update_documents_1.mdx'; import CodeSamplesDeleteAllDocuments1 from '/snippets/samples/code_samples_delete_all_documents_1.mdx'; import CodeSamplesDeleteDocumentsByBatch1 from '/snippets/samples/code_samples_delete_documents_by_batch_1.mdx'; import CodeSamplesDeleteDocumentsByFilter1 from '/snippets/samples/code_samples_delete_documents_by_filter_1.mdx'; import CodeSamplesDeleteOneDocument1 from '/snippets/samples/code_samples_delete_one_document_1.mdx'; import CodeSamplesGetDocuments1 from '/snippets/samples/code_samples_get_documents_1.mdx'; import CodeSamplesGetDocumentsPost1 from '/snippets/samples/code_samples_get_documents_post_1.mdx'; import CodeSamplesGetOneDocument1 from '/snippets/samples/code_samples_get_one_document_1.mdx';
The /documents route allows you to create, manage, and delete documents.
Get a set of documents.
Use offset and limit to browse through documents.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Name | Type | Default Value | Description |
|---|---|---|---|
offset |
Integer | 0 |
Number of documents to skip |
limit |
Integer | 20 |
Number of documents to return |
fields |
Array of strings/null |
* |
Document attributes to show (case-sensitive, comma-separated) |
filter |
String/Array of array of strings/null |
N/A | Refine results based on attributes in the filterableAttributes list |
retrieveVectors |
Boolean | false |
Return document vector data with search result |
sort |
null |
A list of attributes written as an array or as a comma-separated string | |
ids |
Array of primary keys | null |
Return documents based on their primary keys |
| Name | Type | Description |
|---|---|---|
results |
Array | An array of documents |
offset |
Integer | Number of documents skipped |
limit |
Integer | Number of documents returned |
total |
Integer | Total number of documents in the index |
/indexes/{index_uid}/documents/fetch and /indexes/{index_uid}/documents responses do not return documents following the order of their primary keys.
{
"results": [
{
"title": "The Travels of Ibn Battuta",
"genres": [
"Travel",
"Adventure"
],
"language": "English",
"rating": 4.5
},
{
"title": "Pride and Prejudice",
"genres": [
"Classics",
"Fiction",
"Romance",
"Literature"
],
"language": "English",
"rating": 4
},
…
],
"offset": 0,
"limit": 3,
"total": 5
}Get a set of documents.
Using the query parameters offset and limit, you can browse through all your documents.filter must be a string. To create filter expressions use AND or OR.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
offset |
0 |
Number of documents to skip |
limit |
20 |
Number of documents to return |
fields |
* |
Document attributes to show (case-sensitive, comma-separated) |
filter |
N/A | Refine results based on attributes in the filterableAttributes list |
retrieveVectors |
false |
Return document vector data with search result |
sort |
null |
A list of comma-separated attributes |
ids |
null |
Return documents based on their primary keys |
| Name | Type | Description |
|---|---|---|
results |
Array | An array of documents |
offset |
Integer | Number of documents skipped |
limit |
Integer | Number of documents returned |
total |
Integer | Total number of documents in the index |
/indexes/{index_uid}/documents/fetch and /indexes/{index_uid}/documents responses do not return documents following the order of their primary keys.
{
"results": [
{
"id": 364,
"title": "Batman Returns",
"overview": "While Batman deals with a deformed man calling himself the Penguin, an employee of a corrupt businessman transforms into the Catwoman.",
"genres": [
"Action",
"Fantasy"
],
"poster": "https://image.tmdb.org/t/p/w500/jKBjeXM7iBBV9UkUcOXx3m7FSHY.jpg",
"release_date": 708912000
},
{
"id": 13851,
"title": " Batman: Gotham Knight",
"overview": "A collection of key events mark Bruce Wayne's life as he journeys from beginner to Dark Knight.",
"genres": [
"Animation",
"Action",
"Adventure"
],
"poster": "https://image.tmdb.org/t/p/w500/f3xUrqo7yEiU0guk2Ua3Znqiw6S.jpg",
"release_date": 1215475200
}
],
"offset": 0,
"limit": 2,
"total": 5403
}Get one document using its unique id.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
document_id * |
String/Integer | Document id of the requested document |
| Query Parameter | Default Value | Description |
|---|---|---|
fields |
* |
Document attributes to show (case-sensitive, comma-separated) |
retrieveVectors |
false |
Return document vector data with search result |
{
"id": 25684,
"title": "American Ninja 5",
"poster": "https://image.tmdb.org/t/p/w1280/iuAQVI4mvjI83wnirpD8GVNRVuY.jpg",
"release_date": "1993-01-01"
}Add an array 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 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 the add or update documents endpoint.
This endpoint accepts the following content types:
application/jsonapplication/x-ndjsontext/csv
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
primaryKey |
null |
Primary key of the index |
csvDelimiter |
"," |
Configure the character separating CSV fields. Must be a string containing one ASCII character. |
customMetadata |
null |
An arbitrary string accessible via the generated task object |
skipCreation |
false |
If true, updates existing documents, but does not add new documents to the index |
If you want to set the primary key of your index on document addition, it can only be done the first time you add documents to the index. After this, the primaryKey parameter will be ignored if given.
An array of documents. Each document is represented as a JSON object.
[
{
"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"
}
]_vectors is a special document attribute containing an object with vector embeddings for AI-powered search.
Each key of the _vectors object must be the name of a configured embedder and correspond to a nested object with two fields, embeddings and regenerate:
[
{
"id": 452,
"title": "Female Trouble",
"overview": "Delinquent high school student Dawn Davenport runs away from home and embarks upon a life of crime.",
"_vectors": {
"default": {
"embeddings": [0.1, 0.2, 0.3],
"regenerate": false
},
"ollama": {
"embeddings": [0.4, 0.12, 0.6],
"regenerate": true
}
}
}
]embeddings is an optional field. It must be an array of numbers representing a single embedding for that document. It may also be an array of arrays of numbers representing multiple embeddings for that document. embeddings defaults to null.
regenerate is a mandatory field. It must be a Boolean value. If regenerate is true, Meilisearch automatically generates embeddings for that document immediately and every time the document is updated. If regenerate is false, Meilisearch keeps the last value of the embeddings on document updates.
You may also use an array shorthand to add embeddings to a document:
"_vectors": {
"default": [0.003, 0.1, 0.75]
}Vector embeddings added with the shorthand are not replaced when Meilisearch generates new embeddings. The above example is equivalent to:
"default": {
"embeddings": [0.003, 0.1, 0.75],
"regenerate": false
}{
"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 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 document id) the old document will be only partially updated according to the fields of the new document. Any fields not present in the new document are kept and remain unchanged.
Partial updates apply only to top-level fields. You cannot perform a partial update of a nested field.Updating an object replaces the entire object and removes any omitted subfields.
Using dot notation in an update request creates a new flat attribute instead of updating the existing nested field.
To completely overwrite a document, check out the add or replace documents route.
If you want to set the primary key of your index through this route, you may only do so the first time you add documents to the index. If you try to set the primary key after having added documents to the index, the task will return an error.
This endpoint accepts the following content types:
application/jsonapplication/x-ndjsontext/csv
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
primaryKey |
null |
Primary key of the documents |
csvDelimiter |
"," |
Configure the character separating CSV fields. Must be a string containing one ASCII character. |
customMetadata |
null |
An arbitrary string accessible via the generated task object |
skipCreation |
false |
If true, updates existing documents, but does not add new documents to the index |
An array of documents. Each document is represented as a JSON object.
[
{
"id": 287947,
"title": "Shazam ⚡️"
}
]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.
{
"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.
Use a RHAI function to edit one or more documents directly in Meilisearch.
This is an experimental feature. Use the experimental features endpoint to activate it:curl \
-X PATCH 'MEILISEARCH_URL/experimental-features/' \
-H 'Content-Type: application/json' \
--data-binary '{
"editDocumentsByFunction": true
}'| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
function |
null |
A string containing a RHAI function |
filter |
null |
A string containing a filter expression |
context |
null |
An object with data Meilisearch should make available for the editing function |
customMetadata |
null |
An arbitrary string accessible via the generated task object |
function must be a string with a RHAI function that Meilisearch will apply to all selected documents. By default this function has access to a single variable, doc, representing the document you are currently editing. This is a required field.
filter must be a string containing a filter expression. Use filter when you want only to apply function to a subset of the documents in your database.
Use context to pass data to the function scope. By default a function only has access to the document it is editing.
curl \
-X POST 'MEILISEARCH_URL/indexes/INDEX_NAME/documents/edit' \
-H 'Content-Type: application/json' \
--data-binary '{
"function": "doc.title = `${doc.title.to_upper()}`"
}'Delete all documents in the specified index.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
customMetadata |
null |
An arbitrary string accessible via the generated task object |
{
"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 based on its unique id.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
document_id * |
String/Integer | Document id of the requested document |
| Query Parameter | Default Value | Description |
|---|---|---|
customMetadata |
null |
An arbitrary string accessible via the generated task object |
{
"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 a set of documents based on a filter.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
customMetadata |
null |
An arbitrary string accessible via the generated task object |
A filter expression written as a string or array of array of strings for the documents to be deleted.
`filter` will not work without first explicitly adding attributes to the [`filterableAttributes` list](/reference/api/settings#update-filterable-attributes). [Learn more about filters in our dedicated guide.](/learn/filtering_and_sorting/filter_search_results) "filter": "rating > 3.5"
{
"taskUid": 1,
"indexUid": "movies",
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2023-05-15T08:38:48.024551Z"
}You can use this taskUid to get more details on the status of the task.
Delete a set of documents based on an array of document ids.
| Name | Type | Description |
|---|---|---|
index_uid * |
String | uid of the requested index |
| Query Parameter | Default Value | Description |
|---|---|---|
customMetadata |
null |
An arbitrary string accessible via the generated task object |
An array of numbers containing the unique ids of the documents to be deleted.
[23488, 153738, 437035, 363869]{
"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.