diff --git a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java index d7531bd3c2..6998bc65e2 100644 --- a/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java +++ b/clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java @@ -6612,7 +6612,31 @@ public List saveObjects(String indexName, Iterable objects * the transporter requestOptions. (optional) */ public List saveObjects(String indexName, Iterable objects, boolean waitForTasks, RequestOptions requestOptions) { - return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, 1000, requestOptions); + return saveObjects(indexName, objects, false, 1000, requestOptions); + } + + /** + * Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used + * under the hood, which creates a `batch` requests with at most 1000 objects in it. + * + * @param indexName The `indexName` to replace `objects` in. + * @param objects The array of `objects` to store in the given Algolia `indexName`. + * @param waitForTasks - Whether or not we should wait until every `batch` tasks has been + * processed, this operation may slow the total execution time of this method but is more + * reliable. + * @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal + * to `length(objects) / batchSize`. + * @param requestOptions The requestOptions to send along with the query, they will be merged with + * the transporter requestOptions. (optional) + */ + public List saveObjects( + String indexName, + Iterable objects, + boolean waitForTasks, + int batchSize, + RequestOptions requestOptions + ) { + return chunkedBatch(indexName, objects, Action.ADD_OBJECT, waitForTasks, batchSize, requestOptions); } /** @@ -6652,6 +6676,30 @@ public List deleteObjects(String indexName, List objectID * the transporter requestOptions. (optional) */ public List deleteObjects(String indexName, List objectIDs, boolean waitForTasks, RequestOptions requestOptions) { + return deleteObjects(indexName, objectIDs, false, 1000, null); + } + + /** + * Helper: Deletes every records for the given objectIDs. The `chunkedBatch` helper is used under + * the hood, which creates a `batch` requests with at most 1000 objectIDs in it. + * + * @param indexName The `indexName` to delete `objectIDs` from. + * @param objectIDs The array of `objectIDs` to delete from the `indexName`. + * @param waitForTasks - Whether or not we should wait until every `batch` tasks has been + * processed, this operation may slow the total execution time of this method but is more + * reliable. + * @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal + * to `length(objects) / batchSize`. + * @param requestOptions The requestOptions to send along with the query, they will be merged with + * the transporter requestOptions. (optional) + */ + public List deleteObjects( + String indexName, + List objectIDs, + boolean waitForTasks, + int batchSize, + RequestOptions requestOptions + ) { List> objects = new ArrayList<>(); for (String id : objectIDs) { @@ -6660,7 +6708,7 @@ public List deleteObjects(String indexName, List objectID objects.add(obj); } - return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, 1000, requestOptions); + return chunkedBatch(indexName, objects, Action.DELETE_OBJECT, waitForTasks, batchSize, requestOptions); } /** @@ -6720,13 +6768,41 @@ public List partialUpdateObjects( boolean createIfNotExists, boolean waitForTasks, RequestOptions requestOptions + ) { + return partialUpdateObjects(indexName, objects, createIfNotExists, waitForTasks, 1000, null); + } + + /** + * Helper: Replaces object content of all the given objects according to their respective + * `objectID` field. The `chunkedBatch` helper is used under the hood, which creates a `batch` + * requests with at most 1000 objects in it. + * + * @param indexName The `indexName` to update `objects` in. + * @param objects The array of `objects` to update in the given Algolia `indexName`. + * @param createIfNotExists To be provided if non-existing objects are passed, otherwise, the call + * will fail. + * @param waitForTasks - Whether or not we should wait until every `batch` tasks has been + * processed, this operation may slow the total execution time of this method but is more + * reliable. + * @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal + * to `length(objects) / batchSize`. + * @param requestOptions The requestOptions to send along with the query, they will be merged with + * the transporter requestOptions. (optional) + */ + public List partialUpdateObjects( + String indexName, + Iterable objects, + boolean createIfNotExists, + boolean waitForTasks, + int batchSize, + RequestOptions requestOptions ) { return chunkedBatch( indexName, objects, createIfNotExists ? Action.PARTIAL_UPDATE_OBJECT : Action.PARTIAL_UPDATE_OBJECT_NO_CREATE, waitForTasks, - 1000, + batchSize, requestOptions ); } diff --git a/clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts b/clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts index 210a716014..85ca19271b 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/model/clientMethodProps.ts @@ -824,21 +824,24 @@ export type SearchClientNodeHelpers = { getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number; }; -export type DeleteObjectsOptions = Pick & { +export type DeleteObjectsOptions = Pick & { /** * The objectIDs to delete. */ objectIDs: string[]; }; -export type PartialUpdateObjectsOptions = Pick & { +export type PartialUpdateObjectsOptions = Pick< + ChunkedBatchOptions, + 'indexName' | 'objects' | 'waitForTasks' | 'batchSize' +> & { /** *To be provided if non-existing objects are passed, otherwise, the call will fail. */ createIfNotExists?: boolean; }; -export type SaveObjectsOptions = Pick; +export type SaveObjectsOptions = Pick; export type ChunkedBatchOptions = ReplaceAllObjectsOptions & { /** diff --git a/clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts b/clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts index 42661bd109..1b29366cec 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/src/searchClient.ts @@ -550,14 +550,18 @@ export function createSearchClient({ * @param saveObjects - The `saveObjects` object. * @param saveObjects.indexName - The `indexName` to save `objects` in. * @param saveObjects.objects - The array of `objects` to store in the given Algolia `indexName`. + * @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param saveObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions. */ async saveObjects( - { indexName, objects, waitForTasks }: SaveObjectsOptions, + { indexName, objects, waitForTasks, batchSize }: SaveObjectsOptions, requestOptions?: RequestOptions, ): Promise { - return await this.chunkedBatch({ indexName, objects, action: 'addObject', waitForTasks }, requestOptions); + return await this.chunkedBatch( + { indexName, objects, action: 'addObject', waitForTasks, batchSize }, + requestOptions, + ); }, /** @@ -567,11 +571,12 @@ export function createSearchClient({ * @param deleteObjects - The `deleteObjects` object. * @param deleteObjects.indexName - The `indexName` to delete `objectIDs` from. * @param deleteObjects.objectIDs - The objectIDs to delete. + * @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param deleteObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `batch` method and merged with the transporter requestOptions. */ async deleteObjects( - { indexName, objectIDs, waitForTasks }: DeleteObjectsOptions, + { indexName, objectIDs, waitForTasks, batchSize }: DeleteObjectsOptions, requestOptions?: RequestOptions, ): Promise { return await this.chunkedBatch( @@ -580,6 +585,7 @@ export function createSearchClient({ objects: objectIDs.map((objectID) => ({ objectID })), action: 'deleteObject', waitForTasks, + batchSize, }, requestOptions, ); @@ -593,11 +599,12 @@ export function createSearchClient({ * @param partialUpdateObjects.indexName - The `indexName` to update `objects` in. * @param partialUpdateObjects.objects - The array of `objects` to update in the given Algolia `indexName`. * @param partialUpdateObjects.createIfNotExists - To be provided if non-existing objects are passed, otherwise, the call will fail.. + * @param chunkedBatch.batchSize - The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param partialUpdateObjects.waitForTasks - Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. * @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions. */ async partialUpdateObjects( - { indexName, objects, createIfNotExists, waitForTasks }: PartialUpdateObjectsOptions, + { indexName, objects, createIfNotExists, waitForTasks, batchSize }: PartialUpdateObjectsOptions, requestOptions?: RequestOptions, ): Promise { return await this.chunkedBatch( @@ -605,6 +612,7 @@ export function createSearchClient({ indexName, objects, action: createIfNotExists ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', + batchSize, waitForTasks, }, requestOptions, diff --git a/clients/algoliasearch-client-php/lib/Api/SearchClient.php b/clients/algoliasearch-client-php/lib/Api/SearchClient.php index f5774edb38..2d44dbd496 100644 --- a/clients/algoliasearch-client-php/lib/Api/SearchClient.php +++ b/clients/algoliasearch-client-php/lib/Api/SearchClient.php @@ -2945,12 +2945,13 @@ public function replaceAllObjects($indexName, $objects, $batchSize = 1000, $requ * * @param string $indexName the `indexName` to replace `objects` in * @param array $objects the array of `objects` to store in the given Algolia `indexName` + * @param array $batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param array $requestOptions Request options * @param bool $waitForTasks Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable */ - public function saveObjects($indexName, $objects, $requestOptions = [], $waitForTasks = false) + public function saveObjects($indexName, $objects, $batchSize = 1000, $requestOptions = [], $waitForTasks = false) { - return $this->chunkedBatch($indexName, $objects, 'addObject', $waitForTasks, 1000, $requestOptions); + return $this->chunkedBatch($indexName, $objects, 'addObject', $waitForTasks, $batchSize, $requestOptions); } /** @@ -2958,10 +2959,11 @@ public function saveObjects($indexName, $objects, $requestOptions = [], $waitFor * * @param string $indexName the `indexName` to delete `objectIDs` from * @param array $objectIDs the `objectIDs` to delete + * @param array $batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param array $requestOptions Request options * @param bool $waitForTasks Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable */ - public function deleteObjects($indexName, $objectIDs, $requestOptions = [], $waitForTasks = false) + public function deleteObjects($indexName, $objectIDs, $batchSize = 1000, $requestOptions = [], $waitForTasks = false) { $objects = []; @@ -2969,7 +2971,7 @@ public function deleteObjects($indexName, $objectIDs, $requestOptions = [], $wai $objects[] = ['objectID' => $id]; } - return $this->chunkedBatch($indexName, $objects, 'deleteObject', $waitForTasks, 1000, $requestOptions); + return $this->chunkedBatch($indexName, $objects, 'deleteObject', $waitForTasks, $batchSize, $requestOptions); } /** @@ -2978,12 +2980,13 @@ public function deleteObjects($indexName, $objectIDs, $requestOptions = [], $wai * @param string $indexName the `indexName` to replace `objects` in * @param array $objects the array of `objects` to store in the given Algolia `indexName` * @param bool $createIfNotExists To be provided if non-existing objects are passed, otherwise, the call will fail.. + * @param array $batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. * @param array $requestOptions Request options * @param bool $waitForTasks Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable */ - public function partialUpdateObjects($indexName, $objects, $createIfNotExists, $requestOptions = [], $waitForTasks = false) + public function partialUpdateObjects($indexName, $objects, $createIfNotExists, $batchSize = 1000, $requestOptions = [], $waitForTasks = false) { - return $this->chunkedBatch($indexName, $objects, (true == $createIfNotExists) ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', $waitForTasks, 1000, $requestOptions); + return $this->chunkedBatch($indexName, $objects, (true == $createIfNotExists) ? 'partialUpdateObject' : 'partialUpdateObjectNoCreate', $waitForTasks, $batchSize, $requestOptions); } /** diff --git a/clients/algoliasearch-client-python/algoliasearch/search/client.py b/clients/algoliasearch-client-python/algoliasearch/search/client.py index 9a3f8a94f5..d80e0ddff0 100644 --- a/clients/algoliasearch-client-python/algoliasearch/search/client.py +++ b/clients/algoliasearch-client-python/algoliasearch/search/client.py @@ -504,6 +504,7 @@ async def save_objects( index_name: str, objects: List[Dict[str, Any]], wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -514,6 +515,7 @@ async def save_objects( objects=objects, action=Action.ADDOBJECT, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) @@ -522,6 +524,7 @@ async def delete_objects( index_name: str, object_ids: List[str], wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -532,6 +535,7 @@ async def delete_objects( objects=[{"objectID": id} for id in object_ids], action=Action.DELETEOBJECT, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) @@ -541,6 +545,7 @@ async def partial_update_objects( objects: List[Dict[str, Any]], create_if_not_exists: bool = False, wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -553,6 +558,7 @@ async def partial_update_objects( if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) @@ -5526,6 +5532,7 @@ def save_objects( index_name: str, objects: List[Dict[str, Any]], wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -5536,6 +5543,7 @@ def save_objects( objects=objects, action=Action.ADDOBJECT, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) @@ -5544,6 +5552,7 @@ def delete_objects( index_name: str, object_ids: List[str], wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -5554,6 +5563,7 @@ def delete_objects( objects=[{"objectID": id} for id in object_ids], action=Action.DELETEOBJECT, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) @@ -5563,6 +5573,7 @@ def partial_update_objects( objects: List[Dict[str, Any]], create_if_not_exists: bool = False, wait_for_tasks: bool = False, + batch_size: int = 1000, request_options: Optional[Union[dict, RequestOptions]] = None, ) -> List[BatchResponse]: """ @@ -5575,6 +5586,7 @@ def partial_update_objects( if create_if_not_exists else Action.PARTIALUPDATEOBJECTNOCREATE, wait_for_tasks=wait_for_tasks, + batch_size=batch_size, request_options=request_options, ) diff --git a/clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb b/clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb index 9aed7e7ab4..f6cbe5ce6f 100644 --- a/clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb +++ b/clients/algoliasearch-client-ruby/lib/algolia/api/search_client.rb @@ -3336,17 +3336,18 @@ def get_secured_api_key_remaining_validity(secured_api_key) # @param index_name [String]: The `index_name` to save `objects` in. # @param objects [Array]: The array of `objects` to store in the given Algolia `indexName`. # @param wait_for_tasks [Boolean]: Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. + # @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) # # @return [BatchResponse] # - def save_objects(index_name, objects, wait_for_tasks = false, request_options = {}) + def save_objects(index_name, objects, wait_for_tasks = false, batch_size = 1000, request_options = {}) chunked_batch( index_name, objects, Search::Action::ADD_OBJECT, wait_for_tasks, - 1000, + batch_size, request_options ) end @@ -3356,17 +3357,18 @@ def save_objects(index_name, objects, wait_for_tasks = false, request_options = # @param index_name [String]: The `index_name` to delete `object_ids` from. # @param object_ids [Array]: The object_ids to delete. # @param wait_for_tasks [Boolean]: Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. + # @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) # # @return [BatchResponse] # - def delete_objects(index_name, object_ids, wait_for_tasks = false, request_options = {}) + def delete_objects(index_name, object_ids, wait_for_tasks = false, batch_size = 1000, request_options = {}) chunked_batch( index_name, object_ids.map { |id| {"objectID" => id} }, Search::Action::DELETE_OBJECT, wait_for_tasks, - 1000, + batch_size, request_options ) end @@ -3377,17 +3379,25 @@ def delete_objects(index_name, object_ids, wait_for_tasks = false, request_optio # @param objects [Array]: The objects to partially update. # @param create_if_not_exists [Boolean]: To be provided if non-existing objects are passed, otherwise, the call will fail. # @param wait_for_tasks [Boolean] Whether or not we should wait until every `batch` tasks has been processed, this operation may slow the total execution time of this method but is more reliable. + # @param batch_size [int] The size of the chunk of `objects`. The number of `batch` calls will be equal to `length(objects) / batchSize`. Defaults to 1000. # @param request_options: The request options to send along with the query, they will be merged with the transporter base parameters (headers, query params, timeouts, etc.). (optional) # # @return [BatchResponse] # - def partial_update_objects(index_name, objects, create_if_not_exists, wait_for_tasks = false, request_options = {}) + def partial_update_objects( + index_name, + objects, + create_if_not_exists, + wait_for_tasks = false, + batch_size = 1000, + request_options = {} + ) chunked_batch( index_name, objects, create_if_not_exists ? Search::Action::PARTIAL_UPDATE_OBJECT : Search::Action::PARTIAL_UPDATE_OBJECT_NO_CREATE, wait_for_tasks, - 1000, + batch_size, request_options ) end diff --git a/specs/bundled/search.yml b/specs/bundled/search.yml index 5a45ab72cb..f666cfcc11 100644 --- a/specs/bundled/search.yml +++ b/specs/bundled/search.yml @@ -3569,6 +3569,14 @@ paths: required: false schema: type: boolean + - in: query + name: batchSize + description: >- + The size of the chunk of `objects`. The number of `batch` calls will + be equal to `length(objects) / batchSize`. Defaults to 1000. + required: false + schema: + type: integer - in: query name: requestOptions description: The request options to pass to the `batch` method. @@ -3621,6 +3629,14 @@ paths: required: false schema: type: boolean + - in: query + name: batchSize + description: >- + The size of the chunk of `objects`. The number of `batch` calls will + be equal to `length(objects) / batchSize`. Defaults to 1000. + required: false + schema: + type: integer - in: query name: requestOptions description: The request options to pass to the `batch` method. @@ -3684,6 +3700,14 @@ paths: required: false schema: type: boolean + - in: query + name: batchSize + description: >- + The size of the chunk of `objects`. The number of `batch` calls will + be equal to `length(objects) / batchSize`. Defaults to 1000. + required: false + schema: + type: integer - in: query name: requestOptions description: The request options to pass to the `batch` method. diff --git a/tests/output/javascript/src/e2e/insights.test.ts b/tests/output/javascript/src/e2e/insights.test.ts index b79e1f774a..9964d27018 100644 --- a/tests/output/javascript/src/e2e/insights.test.ts +++ b/tests/output/javascript/src/e2e/insights.test.ts @@ -30,7 +30,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -40,7 +40,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], }, ], diff --git a/tests/output/javascript/src/requests/insights.test.ts b/tests/output/javascript/src/requests/insights.test.ts index 43ed5db8a5..81dfc30e65 100644 --- a/tests/output/javascript/src/requests/insights.test.ts +++ b/tests/output/javascript/src/requests/insights.test.ts @@ -311,7 +311,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -321,7 +321,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], }, ], @@ -337,7 +337,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], queryID: '43b15df305339e827f0ac0bdc5ebcaa7', }, @@ -347,7 +347,7 @@ describe('pushEvents', () => { index: 'products', userToken: 'user-123456', authenticatedUserToken: 'user-123456', - timestamp: 1732492800000, + timestamp: 1732752000000, objectIDs: ['9780545139700', '9780439784542'], }, ],