curl \
-X POST 'MEILISEARCH_URL/indexes/movies/documents/edit' \
-H 'Authorization: Bearer API_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"function": "doc.new_field = `a]new[value`",
"filter": "id > 3000",
"context": {
"max_title_length": 10
}
}'import requests
url = "http://localhost:7700/indexes/{index_uid}/documents/edit"
payload = {
"function": "<string>",
"filter": "<unknown>",
"context": "<unknown>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({function: '<string>', filter: '<unknown>', context: '<unknown>'})
};
fetch('http://localhost:7700/indexes/{index_uid}/documents/edit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "7700",
CURLOPT_URL => "http://localhost:7700/indexes/{index_uid}/documents/edit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'function' => '<string>',
'filter' => '<unknown>',
'context' => '<unknown>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:7700/indexes/{index_uid}/documents/edit"
payload := strings.NewReader("{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:7700/indexes/{index_uid}/documents/edit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:7700/indexes/{index_uid}/documents/edit")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}"
response = http.request(request)
puts response.read_body{
"taskUid": 147,
"indexUid": null,
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2024-08-08T17:05:55.791772Z"
}{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
"type": "auth",
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
}{
"message": "Index `movies` not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
}Edit documents by function
Use a RHAI function to edit one or more documents directly in Meilisearch. The function receives each document and returns the modified document.
This feature is experimental and must be enabled through the experimental route.
curl \
-X POST 'MEILISEARCH_URL/indexes/movies/documents/edit' \
-H 'Authorization: Bearer API_KEY' \
-H 'Content-Type: application/json' \
--data-binary '{
"function": "doc.new_field = `a]new[value`",
"filter": "id > 3000",
"context": {
"max_title_length": 10
}
}'import requests
url = "http://localhost:7700/indexes/{index_uid}/documents/edit"
payload = {
"function": "<string>",
"filter": "<unknown>",
"context": "<unknown>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({function: '<string>', filter: '<unknown>', context: '<unknown>'})
};
fetch('http://localhost:7700/indexes/{index_uid}/documents/edit', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_PORT => "7700",
CURLOPT_URL => "http://localhost:7700/indexes/{index_uid}/documents/edit",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'function' => '<string>',
'filter' => '<unknown>',
'context' => '<unknown>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "http://localhost:7700/indexes/{index_uid}/documents/edit"
payload := strings.NewReader("{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("http://localhost:7700/indexes/{index_uid}/documents/edit")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("http://localhost:7700/indexes/{index_uid}/documents/edit")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"function\": \"<string>\",\n \"filter\": \"<unknown>\",\n \"context\": \"<unknown>\"\n}"
response = http.request(request)
puts response.read_body{
"taskUid": 147,
"indexUid": null,
"status": "enqueued",
"type": "documentDeletion",
"enqueuedAt": "2024-08-08T17:05:55.791772Z"
}{
"message": "The Authorization header is missing. It must use the bearer authorization method.",
"code": "missing_authorization_header",
"type": "auth",
"link": "https://docs.meilisearch.com/errors#missing_authorization_header"
}{
"message": "Index `movies` not found.",
"code": "index_not_found",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#index_not_found"
}Authorizations
An API key is a token that you provide when making API calls. Read more about how to secure your project.
Include the API key to the Authorization header, for instance:
-H 'Authorization: Bearer 6436fc5237b0d6e0d64253fbaac21d135012ecf1'
If you use a SDK, ensure you instantiate the client with the API key, for instance with JS SDK:
const client = new MeiliSearch({ host: 'MEILISEARCH_URL', apiKey: '6436fc5237b0d6e0d64253fbaac21d135012ecf1' });
Query Parameters
Body
Request body for editing documents using a RHAI function
A RHAI function string to apply to each document. The function has
access to a doc variable representing the current document. Modify doc fields to
update the document. Return null or () to delete the document.
To enable this feature: PATCH /experimental-features/ {"editDocumentsByFunction": true}.
Response
Task successfully enqueued.
A summarized view of a task, returned when a task is enqueued
Type of operation performed by the task.
documentAdditionOrUpdate, documentEdition, documentDeletion, settingsUpdate, indexCreation, indexDeletion, indexUpdate, indexSwap, taskCancelation, taskDeletion, dumpCreation, snapshotCreation, export, upgradeDatabase, indexCompaction, networkTopologyChange, dsrUpdate, dsrClear "documentAdditionOrUpdate"