Skip to main content
The /documents route allows you to create, manage, and delete documents. Learn more about documents.

Get documents with POST

Get a set of documents. Use offset and limit to browse through documents.
filter will not work without first explicitly adding attributes to the filterableAttributes list. Learn more about filters in our dedicated guide.

Path parameters

Body

Sending an empty payload (--data-binary '{}') will return all documents in the index.

Response

Returned document order

/indexes/{index_uid}/documents/fetch and /indexes/{index_uid}/documents responses do not return documents following the order of their primary keys.

Example

Response: 200 Ok

Get documents with GET

This endpoint will be deprecated in the near future. Consider using POST /indexes/{index_uid}/documents/fetch instead.
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.
filter will not work without first explicitly adding attributes to the filterableAttributes list. Learn more about filters in our dedicated guide.

Path parameters

Query parameters

Response

Returned document order

/indexes/{index_uid}/documents/fetch and /indexes/{index_uid}/documents responses do not return documents following the order of their primary keys.

Example

Response: 200 Ok

Get one document

Get one document using its unique id.

Path parameters

Query parameters

Example

Response: 200 Ok

Add or replace documents

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/json
  • application/x-ndjson
  • text/csv

Path parameters

Query parameters

Configuring csvDelimiter and sending data with a content type other than CSV will cause Meilisearch to throw an error.
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.

Body

An array of documents. Each document is represented as a JSON object.

_vectors

_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:
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:
Vector embeddings added with the shorthand are not replaced when Meilisearch generates new embeddings. The above example is equivalent to:
If the key for an embedder inside _vectors is empty or null, Meilisearch treats the document as not having any embeddings for that embedder. This document is then returned last during AI-powered searches.

Example

Response: 202 Accepted

You can use this taskUid to get more details on the status of the task.

Add or update 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 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 remain unchanged. 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/json
  • application/x-ndjson
  • text/csv

Path parameters

Query parameters

Configuring csvDelimiter and sending data with a content type other than CSV will cause Meilisearch to throw an error.

Body

An array of documents. Each document is represented as a JSON object.

Example

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

You can use this taskUid to get more details on the status of the task.

Update documents with function

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:

Path parameters

Query parameters

function

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

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.

context

Use context to pass data to the function scope. By default a function only has access to the document it is editing.

Example

Delete all documents

Delete all documents in the specified index.

Path parameters

Query parameters

Example

Response: 202 Accepted

You can use this taskUid to get more details on the status of the task.

Delete one document

Delete one document based on its unique id.

Path parameters

Query parameters

Example

Response: 202 Accepted

You can use this taskUid to get more details on the status of the task.

Delete documents by filter

Delete a set of documents based on a filter.

Path parameters

Query parameters

Body

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. Learn more about filters in our dedicated guide.
Sending an empty payload (--data-binary '{}') will return a bad_request error.

Example

Response: 202 Accepted

You can use this taskUid to get more details on the status of the task.

Delete documents by batch

Delete a set of documents based on an array of document ids.

Path parameters

Query parameters

Body

An array of numbers containing the unique ids of the documents to be deleted.

Example

Response: 202 Accepted

You can use this taskUid to get more details on the status of the task.