diff --git a/meilisearch/index.py b/meilisearch/index.py index f61578fd..5c4021e9 100644 --- a/meilisearch/index.py +++ b/meilisearch/index.py @@ -482,6 +482,7 @@ def add_documents( primary_key: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Add documents to the index. @@ -494,6 +495,8 @@ def add_documents( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -506,7 +509,7 @@ def add_documents( MeilisearchApiError 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 """ - url = self._build_url(primary_key) + url = self._build_url(primary_key, metadata=metadata) add_document_task = self.http.post(url, documents, serializer=serializer) return TaskInfo(**add_document_task) @@ -517,6 +520,7 @@ def add_documents_in_batches( primary_key: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> List[TaskInfo]: """Add documents to the index in batches. @@ -531,6 +535,8 @@ def add_documents_in_batches( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -548,7 +554,9 @@ def add_documents_in_batches( tasks: List[TaskInfo] = [] for document_batch in self._batch(documents, batch_size): - task = self.add_documents(document_batch, primary_key, serializer=serializer) + task = self.add_documents( + document_batch, primary_key, serializer=serializer, metadata=metadata + ) tasks.append(task) return tasks @@ -559,6 +567,7 @@ def add_documents_json( primary_key: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Add documents to the index from a byte-encoded JSON string. @@ -571,6 +580,8 @@ def add_documents_json( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -584,7 +595,7 @@ def add_documents_json( 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 """ return self.add_documents_raw( - str_documents, primary_key, "application/json", serializer=serializer + str_documents, primary_key, "application/json", serializer=serializer, metadata=metadata ) def add_documents_csv( @@ -592,6 +603,7 @@ def add_documents_csv( str_documents: bytes, primary_key: Optional[str] = None, csv_delimiter: Optional[str] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Add documents to the index from a byte-encoded CSV string. @@ -603,6 +615,8 @@ def add_documents_csv( The primary-key used in index. Ignored if already set up. csv_delimiter: One ASCII character used to customize the delimiter for CSV. Comma used by default. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -615,12 +629,15 @@ def add_documents_csv( MeilisearchApiError 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 """ - return self.add_documents_raw(str_documents, primary_key, "text/csv", csv_delimiter) + return self.add_documents_raw( + str_documents, primary_key, "text/csv", csv_delimiter=csv_delimiter, metadata=metadata + ) def add_documents_ndjson( self, str_documents: bytes, primary_key: Optional[str] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Add documents to the index from a byte-encoded NDJSON string. @@ -630,6 +647,8 @@ def add_documents_ndjson( Byte-encoded NDJSON string. primary_key (optional): The primary-key used in index. Ignored if already set up. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -642,7 +661,9 @@ def add_documents_ndjson( MeilisearchApiError 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 """ - return self.add_documents_raw(str_documents, primary_key, "application/x-ndjson") + return self.add_documents_raw( + str_documents, primary_key, "application/x-ndjson", metadata=metadata + ) def add_documents_raw( self, @@ -652,6 +673,7 @@ def add_documents_raw( csv_delimiter: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Add documents to the index from a byte-encoded string. @@ -669,6 +691,8 @@ def add_documents_raw( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -681,7 +705,9 @@ def add_documents_raw( MeilisearchApiError 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 """ - url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter) + url = self._build_url( + primary_key=primary_key, csv_delimiter=csv_delimiter, metadata=metadata + ) response = self.http.post(url, str_documents, content_type, serializer=serializer) return TaskInfo(**response) @@ -691,6 +717,7 @@ def update_documents( primary_key: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Update documents in the index. @@ -703,6 +730,8 @@ def update_documents( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -715,7 +744,7 @@ def update_documents( MeilisearchApiError 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 """ - url = self._build_url(primary_key) + url = self._build_url(primary_key, metadata=metadata) response = self.http.put(url, documents, serializer=serializer) return TaskInfo(**response) @@ -723,6 +752,7 @@ def update_documents_ndjson( self, str_documents: str, primary_key: Optional[str] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Update documents as a ndjson string in the index. @@ -732,6 +762,8 @@ def update_documents_ndjson( String of document from a NDJSON file. primary_key (optional): The primary-key used in index. Ignored if already set up + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -744,7 +776,9 @@ def update_documents_ndjson( MeilisearchApiError 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 """ - return self.update_documents_raw(str_documents, primary_key, "application/x-ndjson") + return self.update_documents_raw( + str_documents, primary_key, "application/x-ndjson", metadata=metadata + ) def update_documents_json( self, @@ -752,6 +786,7 @@ def update_documents_json( primary_key: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Update documents as a json string in the index. @@ -764,6 +799,8 @@ def update_documents_json( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -777,7 +814,7 @@ def update_documents_json( 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 """ return self.update_documents_raw( - str_documents, primary_key, "application/json", serializer=serializer + str_documents, primary_key, "application/json", serializer=serializer, metadata=metadata ) def update_documents_csv( @@ -785,6 +822,7 @@ def update_documents_csv( str_documents: str, primary_key: Optional[str] = None, csv_delimiter: Optional[str] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Update documents as a csv string in the index. @@ -796,6 +834,8 @@ def update_documents_csv( The primary-key used in index. Ignored if already set up. csv_delimiter: One ASCII character used to customize the delimiter for CSV. Comma used by default. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -808,7 +848,9 @@ def update_documents_csv( MeilisearchApiError 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 """ - return self.update_documents_raw(str_documents, primary_key, "text/csv", csv_delimiter) + return self.update_documents_raw( + str_documents, primary_key, "text/csv", csv_delimiter=csv_delimiter, metadata=metadata + ) def update_documents_raw( self, @@ -818,6 +860,7 @@ def update_documents_raw( csv_delimiter: Optional[str] = None, *, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Update documents as a string in the index. @@ -835,6 +878,8 @@ def update_documents_raw( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -847,7 +892,9 @@ def update_documents_raw( MeilisearchApiError 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 """ - url = self._build_url(primary_key=primary_key, csv_delimiter=csv_delimiter) + url = self._build_url( + primary_key=primary_key, csv_delimiter=csv_delimiter, metadata=metadata + ) response = self.http.put(url, str_documents, content_type, serializer=serializer) return TaskInfo(**response) @@ -857,6 +904,7 @@ def update_documents_in_batches( batch_size: int = 1000, primary_key: Optional[str] = None, serializer: Optional[Type[JSONEncoder]] = None, + metadata: Optional[str] = None, ) -> List[TaskInfo]: """Update documents to the index in batches. @@ -871,6 +919,8 @@ def update_documents_in_batches( serializer (optional): A custom JSONEncode to handle serializing fields that the build in json.dumps cannot handle, for example UUID and datetime. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -888,18 +938,24 @@ def update_documents_in_batches( tasks = [] for document_batch in self._batch(documents, batch_size): - update_task = self.update_documents(document_batch, primary_key, serializer=serializer) + update_task = self.update_documents( + document_batch, primary_key, serializer=serializer, metadata=metadata + ) tasks.append(update_task) return tasks - def delete_document(self, document_id: Union[str, int]) -> TaskInfo: + def delete_document( + self, document_id: Union[str, int], metadata: Optional[str] = None + ) -> TaskInfo: """Delete one document from the index. Parameters ---------- document_id: Unique identifier of the document. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -912,9 +968,10 @@ def delete_document(self, document_id: Union[str, int]) -> TaskInfo: MeilisearchApiError 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 """ - response = self.http.delete( - f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/{document_id}" - ) + url = f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/{document_id}" + if metadata: + url += f"?{parse.urlencode({'customMetadata': metadata})}" + response = self.http.delete(url) return TaskInfo(**response) @version_error_hint_message @@ -925,6 +982,7 @@ def delete_documents( filter: Optional[ # pylint: disable=redefined-builtin Union[str, List[Union[str, List[str]]]] ] = None, + metadata: Optional[str] = None, ) -> TaskInfo: """Delete multiple documents from the index by id or filter. @@ -935,6 +993,8 @@ def delete_documents( removed in a future version. filter: The filter value information. + metadata (optional): + Custom metadata string to attach to the task. Returns ------- @@ -952,20 +1012,31 @@ def delete_documents( "The use of ids is depreciated and will be removed in the future", DeprecationWarning, ) + url = f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete-batch" + if metadata: + url += f"?{parse.urlencode({'customMetadata': metadata})}" response = self.http.post( - f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete-batch", + url, [str(i) for i in ids], ) else: + url = f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete" + if metadata: + url += f"?{parse.urlencode({'customMetadata': metadata})}" response = self.http.post( - f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}/delete", + url, body={"filter": filter}, ) return TaskInfo(**response) - def delete_all_documents(self) -> TaskInfo: + def delete_all_documents(self, metadata: Optional[str] = None) -> TaskInfo: """Delete all documents from the index. + Parameters + ---------- + metadata (optional): + Custom metadata string to attach to the task. + Returns ------- task_info: @@ -977,9 +1048,10 @@ def delete_all_documents(self) -> TaskInfo: MeilisearchApiError 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 """ - response = self.http.delete( - f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}" - ) + url = f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}" + if metadata: + url += f"?{parse.urlencode({'customMetadata': metadata})}" + response = self.http.delete(url) return TaskInfo(**response) # GENERAL SETTINGS ROUTES @@ -2359,13 +2431,16 @@ def _build_url( self, primary_key: Optional[str] = None, csv_delimiter: Optional[str] = None, + metadata: Optional[str] = None, ) -> str: parameters = {} if primary_key: parameters["primaryKey"] = primary_key if csv_delimiter: parameters["csvDelimiter"] = csv_delimiter - if primary_key is None and csv_delimiter is None: + if metadata: + parameters["customMetadata"] = metadata + if not parameters: return f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}" return f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}" diff --git a/meilisearch/models/task.py b/meilisearch/models/task.py index 83735c73..f20458ad 100644 --- a/meilisearch/models/task.py +++ b/meilisearch/models/task.py @@ -22,6 +22,7 @@ class Task(CamelBase): started_at: Optional[datetime] = None finished_at: Optional[datetime] = None network: Optional[Dict[str, Any]] = None + customMetadata: Optional[str] = None if is_pydantic_2(): diff --git a/tests/index/test_index_document_meilisearch.py b/tests/index/test_index_document_meilisearch.py index 35bc5f33..b81abd1e 100644 --- a/tests/index/test_index_document_meilisearch.py +++ b/tests/index/test_index_document_meilisearch.py @@ -31,12 +31,13 @@ def test_get_documents_default(empty_index): def test_add_documents(empty_index, small_movies): """Tests adding new documents to a clean index.""" index = empty_index() - response = index.add_documents(small_movies) + response = index.add_documents(small_movies, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_add_documents_empty(empty_index): @@ -61,13 +62,16 @@ def test_add_documents_in_batches( small_movies, ): index = empty_index() - response = index.add_documents_in_batches(small_movies, batch_size, primary_key) + response = index.add_documents_in_batches( + small_movies, batch_size, primary_key, metadata="Test metadata" + ) assert ceil(len(small_movies) / batch_size) == len(response) for r in response: assert r.task_uid is not None update = index.wait_for_task(r.task_uid) assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" assert index.get_primary_key() == expected_primary_key @@ -105,12 +109,15 @@ def test_add_documents_json_custom_serializer(empty_index): {"id": uuid4(), "title": "Test 2", "when": datetime.now()}, ] index = empty_index() - response = index.add_documents_json(documents, serializer=CustomEncoder) + response = index.add_documents_json( + documents, serializer=CustomEncoder, metadata="Test metadata" + ) assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_add_documents_raw_custom_serializer(empty_index): @@ -120,13 +127,17 @@ def test_add_documents_raw_custom_serializer(empty_index): ] index = empty_index() response = index.add_documents_raw( - documents, content_type="application/json", serializer=CustomEncoder + documents, + content_type="application/json", + serializer=CustomEncoder, + metadata="Test metadata", ) assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_update_documents_custom_serializer(empty_index): @@ -135,12 +146,13 @@ def test_update_documents_custom_serializer(empty_index): {"id": uuid4(), "title": "Test 2", "when": datetime.now()}, ] index = empty_index() - response = index.update_documents(documents, serializer=CustomEncoder) + response = index.update_documents(documents, serializer=CustomEncoder, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_update_documents_in_batches_custom_serializer(empty_index): @@ -162,12 +174,15 @@ def test_update_documents_json_custom_serializer(empty_index): {"id": uuid4(), "title": "Test 2", "when": datetime.now()}, ] index = empty_index() - response = index.update_documents_json(documents, serializer=CustomEncoder) + response = index.update_documents_json( + documents, serializer=CustomEncoder, metadata="Test metadata" + ) assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_update_documents_raw_custom_serializer(empty_index): @@ -177,13 +192,17 @@ def test_update_documents_raw_custom_serializer(empty_index): ] index = empty_index() response = index.update_documents_raw( - documents, content_type="application/json", serializer=CustomEncoder + documents, + content_type="application/json", + serializer=CustomEncoder, + metadata="Test metadata", ) assert isinstance(response, TaskInfo) assert response.task_uid is not None update = index.wait_for_task(response.task_uid) assert index.get_primary_key() == "id" assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" def test_get_document(index_with_documents): @@ -371,11 +390,12 @@ def test_update_documents(index_with_documents, small_movies): doc = response.results[0] doc.title = "Some title" - update = index.update_documents([dict(doc)]) + update = index.update_documents([dict(doc)], metadata="Test metadata") assert isinstance(update, TaskInfo) assert update.task_uid is not None - index.wait_for_task(update.task_uid) + task = index.wait_for_task(update.task_uid) + assert task.customMetadata == "Test metadata" response = index.get_document(doc.id) assert response.title == "Some title" @@ -400,13 +420,16 @@ def test_update_documents_in_batches( small_movies, ): index = empty_index() - response = index.update_documents_in_batches(small_movies, batch_size, primary_key) + response = index.update_documents_in_batches( + small_movies, batch_size, primary_key, metadata="Test metadata" + ) assert ceil(len(small_movies) / batch_size) == len(response) for r in response: assert r.task_uid is not None update = index.wait_for_task(r.task_uid) assert update.status == "succeeded" + assert update.customMetadata == "Test metadata" assert index.get_primary_key() == expected_primary_key @@ -414,10 +437,12 @@ def test_update_documents_in_batches( def test_delete_document(index_with_documents): """Tests deleting a single document.""" index = index_with_documents() - response = index.delete_document("500682") + response = index.delete_document("500682", metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None - index.wait_for_task(response.task_uid) + task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" + with pytest.raises(Exception): index.get_document("500682") @@ -427,10 +452,12 @@ def test_delete_documents_by_id(index_with_documents): with catch_warnings(record=True) as w: to_delete = [522681, "450465", 329996] index = index_with_documents() - response = index.delete_documents(to_delete) + response = index.delete_documents(to_delete, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None - index.wait_for_task(response.task_uid) + task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" + for document in to_delete: with pytest.raises(Exception): index.get_document(document) @@ -443,8 +470,10 @@ def test_delete_documents(index_with_documents): index.wait_for_task(response.task_uid) response = index.get_documents() assert "action" in ([x.__dict__.get("genre") for x in response.results]) - response = index.delete_documents(filter="genre=action") - index.wait_for_task(response.task_uid) + response = index.delete_documents(filter="genre=action", metadata="Test metadata") + task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" + response = index.get_documents() genres = [x.__dict__.get("genre") for x in response.results] assert "action" not in genres @@ -454,10 +483,11 @@ def test_delete_documents(index_with_documents): def test_delete_all_documents(index_with_documents): """Tests deleting all the documents in the index.""" index = index_with_documents() - response = index.delete_all_documents() + response = index.delete_all_documents(metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None - index.wait_for_task(response.task_uid) + task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" response = index.get_documents() assert isinstance(response.results, list) assert response.results == [] @@ -466,10 +496,11 @@ def test_delete_all_documents(index_with_documents): def test_add_documents_csv(empty_index, songs_csv): """Tests adding new documents to a clean index.""" index = empty_index() - response = index.add_documents_csv(songs_csv) + response = index.add_documents_csv(songs_csv, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" assert task.status == "succeeded" assert index.get_primary_key() == "id" @@ -491,11 +522,12 @@ def test_add_documents_csv_with_delimiter(empty_index, songs_csv_custom_separato def test_update_documents_csv(index_with_documents, songs_csv): """Tests updating a single document with csv string.""" index = index_with_documents() - response = index.update_documents_csv(songs_csv) + response = index.update_documents_csv(songs_csv, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) assert task.status == "succeeded" + assert task.customMetadata == "Test metadata" assert index.get_primary_key() == "id" @@ -516,21 +548,23 @@ def test_update_documents_csv_with_delimiter(index_with_documents, songs_csv_cus def test_add_documents_json(empty_index, small_movies_json_file): """Tests adding new documents to a clean index.""" index = empty_index() - response = index.add_documents_json(small_movies_json_file) + response = index.add_documents_json(small_movies_json_file, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) assert task.status == "succeeded" + assert task.customMetadata == "Test metadata" assert index.get_primary_key() == "id" def test_update_documents_json(index_with_documents, small_movies_json_file): """Tests updating a single document with json string.""" index = index_with_documents() - response = index.update_documents_json(small_movies_json_file) + response = index.update_documents_json(small_movies_json_file, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" assert task.status == "succeeded" assert index.get_primary_key() == "id" @@ -538,10 +572,11 @@ def test_update_documents_json(index_with_documents, small_movies_json_file): def test_add_documents_ndjson(empty_index, songs_ndjson): """Tests adding new documents to a clean index.""" index = empty_index() - response = index.add_documents_ndjson(songs_ndjson) + response = index.add_documents_ndjson(songs_ndjson, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) + assert task.customMetadata == "Test metadata" assert task.status == "succeeded" assert index.get_primary_key() == "id" @@ -549,9 +584,10 @@ def test_add_documents_ndjson(empty_index, songs_ndjson): def test_update_documents_ndjson(index_with_documents, songs_ndjson): """Tests updating a single document with ndjson string.""" index = index_with_documents() - response = index.update_documents_ndjson(songs_ndjson) + response = index.update_documents_ndjson(songs_ndjson, metadata="Test metadata") assert isinstance(response, TaskInfo) assert response.task_uid is not None task = index.wait_for_task(response.task_uid) assert task.status == "succeeded" + assert task.customMetadata == "Test metadata" assert index.get_primary_key() == "id"