Skip to content

Commit 7fea4c1

Browse files
committed
Update Documents with Functions
1 parent a43baec commit 7fea4c1

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

meilisearch/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,29 @@ def multi_search(
248248
body={"queries": queries, "federation": federation},
249249
)
250250

251+
def update_documents_by_function(self, index_uid: str, queries: Dict[str, List[Dict[str, Any]]]) -> Dict[str, Any]:
252+
"""Update Documents by function
253+
Parameters
254+
----------
255+
index_uid:
256+
The index_uid where you want to update documents of.
257+
queries:
258+
List of dictionaries containing functions with or without filters that you want to use to update documents.
259+
260+
Returns
261+
-------
262+
task_info:
263+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
264+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
265+
266+
Raises
267+
------
268+
MeilisearchApiError
269+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
270+
"""
271+
return self.http.post(path=f"{self.config.paths.index}/{index_uid}/{self.config.paths.document}/{self.config.paths.edit}",
272+
body=dict(queries))
273+
251274
def get_all_stats(self) -> Dict[str, Any]:
252275
"""Get all stats of Meilisearch
253276

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Paths:
4444
search_cutoff_ms = "search-cutoff-ms"
4545
proximity_precision = "proximity-precision"
4646
localized_attributes = "localized-attributes"
47+
edit = "edit"
4748

4849
def __init__(
4950
self,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pytest
2+
3+
from meilisearch.errors import MeilisearchApiError
4+
from tests.common import INDEX_UID
5+
from tests.conftest import index_with_documents
6+
7+
def test_basic_multi_search(client, index_with_documents):
8+
"""Delete the document with id."""
9+
index_with_documents()
10+
response = client.update_documents_by_function(
11+
"indexA", {"function": "if doc.id == \"522681\" {doc = () } else {doc.title = `* ${doc.title} *`}"}
12+
)
13+
14+
assert isinstance(response, dict)
15+
assert response['indexUid'] == INDEX_UID

0 commit comments

Comments
 (0)