|
292 | 292 | """
|
293 | 293 | return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.ADDOBJECT, wait_for_tasks=wait_for_tasks, batch_size=batch_size, request_options=request_options)
|
294 | 294 |
|
| 295 | + {{^isSyncClient}}async {{/isSyncClient}}def save_objects_with_transformation( |
| 296 | + self, |
| 297 | + index_name: str, |
| 298 | + objects: List[Dict[str, Any]], |
| 299 | + wait_for_tasks: bool = False, |
| 300 | + batch_size: int = 1000, |
| 301 | + request_options: Optional[Union[dict, RequestOptions]] = None, |
| 302 | + ) -> WatchResponse: |
| 303 | + """ |
| 304 | + Helper: Similar to the `save_objects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must've been passed to the client's config at instantiation. |
| 305 | + """ |
| 306 | + if self._ingestion_transporter is None: |
| 307 | + raise ValueError("`region` must be provided at client instantiation before calling this method.") |
| 308 | +
|
| 309 | + return {{^isSyncClient}}await {{/isSyncClient}}self._ingestion_transporter.push( |
| 310 | + index_name=index_name, |
| 311 | + push_task_payload={ |
| 312 | + "action": Action.ADDOBJECT, |
| 313 | + "records": objects, |
| 314 | + }, |
| 315 | + watch=wait_for_tasks, |
| 316 | + request_options=request_options, |
| 317 | + ) |
| 318 | +
|
| 319 | +
|
295 | 320 | {{^isSyncClient}}async {{/isSyncClient}}def delete_objects(
|
296 | 321 | self,
|
297 | 322 | index_name: str,
|
|
319 | 344 | """
|
320 | 345 | return {{^isSyncClient}}await {{/isSyncClient}}self.chunked_batch(index_name=index_name, objects=objects, action=Action.PARTIALUPDATEOBJECT if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE, wait_for_tasks=wait_for_tasks, batch_size=batch_size, request_options=request_options)
|
321 | 346 |
|
| 347 | + {{^isSyncClient}}async {{/isSyncClient}}def partial_update_objects_with_transformation( |
| 348 | + self, |
| 349 | + index_name: str, |
| 350 | + objects: List[Dict[str, Any]], |
| 351 | + create_if_not_exists: bool = False, |
| 352 | + wait_for_tasks: bool = False, |
| 353 | + batch_size: int = 1000, |
| 354 | + request_options: Optional[Union[dict, RequestOptions]] = None, |
| 355 | + ) -> WatchResponse: |
| 356 | + """ |
| 357 | + Helper: Similar to the `partial_update_objects` method but requires a Push connector (https://www.algolia.com/doc/guides/sending-and-managing-data/send-and-update-your-data/connectors/push/) to be created first, in order to transform records before indexing them to Algolia. The `region` must've been passed to the client instantiation method. |
| 358 | + """ |
| 359 | + if self._ingestion_transporter is None: |
| 360 | + raise ValueError("`region` must be provided at client instantiation before calling this method.") |
| 361 | +
|
| 362 | + return {{^isSyncClient}}await {{/isSyncClient}}self._ingestion_transporter.push( |
| 363 | + index_name=index_name, |
| 364 | + push_task_payload={ |
| 365 | + "action": Action.PARTIALUPDATEOBJECT if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE, |
| 366 | + "records": objects, |
| 367 | + }, |
| 368 | + watch=wait_for_tasks, |
| 369 | + request_options=request_options, |
| 370 | + ) |
| 371 | +
|
| 372 | +
|
322 | 373 | {{^isSyncClient}}async {{/isSyncClient}}def chunked_batch(
|
323 | 374 | self,
|
324 | 375 | index_name: str,
|
|
0 commit comments