diff --git a/lib/algolia/api/search_client.rb b/lib/algolia/api/search_client.rb index 9aed7e7a..f6cbe5ce 100644 --- a/lib/algolia/api/search_client.rb +++ b/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