@@ -3478,63 +3478,69 @@ def chunked_batch(
3478
3478
def replace_all_objects ( index_name , objects , batch_size = 1000 , request_options = { } )
3479
3479
tmp_index_name = index_name + "_tmp_" + rand ( 10_000_000 ) . to_s
3480
3480
3481
- copy_operation_response = operation_index (
3482
- index_name ,
3483
- Search ::OperationIndexParams . new (
3484
- operation : Search ::OperationType ::COPY ,
3485
- destination : tmp_index_name ,
3486
- scope : [
3487
- Search ::ScopeType ::SETTINGS ,
3488
- Search ::ScopeType ::RULES ,
3489
- Search ::ScopeType ::SYNONYMS
3490
- ]
3491
- ) ,
3492
- request_options
3493
- )
3481
+ begin
3482
+ copy_operation_response = operation_index (
3483
+ index_name ,
3484
+ Search ::OperationIndexParams . new (
3485
+ operation : Search ::OperationType ::COPY ,
3486
+ destination : tmp_index_name ,
3487
+ scope : [
3488
+ Search ::ScopeType ::SETTINGS ,
3489
+ Search ::ScopeType ::RULES ,
3490
+ Search ::ScopeType ::SYNONYMS
3491
+ ]
3492
+ ) ,
3493
+ request_options
3494
+ )
3494
3495
3495
- batch_responses = chunked_batch (
3496
- tmp_index_name ,
3497
- objects ,
3498
- Search ::Action ::ADD_OBJECT ,
3499
- true ,
3500
- batch_size ,
3501
- request_options
3502
- )
3496
+ batch_responses = chunked_batch (
3497
+ tmp_index_name ,
3498
+ objects ,
3499
+ Search ::Action ::ADD_OBJECT ,
3500
+ true ,
3501
+ batch_size ,
3502
+ request_options
3503
+ )
3503
3504
3504
- wait_for_task ( tmp_index_name , copy_operation_response . task_id )
3505
+ wait_for_task ( tmp_index_name , copy_operation_response . task_id )
3506
+
3507
+ copy_operation_response = operation_index (
3508
+ index_name ,
3509
+ Search ::OperationIndexParams . new (
3510
+ operation : Search ::OperationType ::COPY ,
3511
+ destination : tmp_index_name ,
3512
+ scope : [
3513
+ Search ::ScopeType ::SETTINGS ,
3514
+ Search ::ScopeType ::RULES ,
3515
+ Search ::ScopeType ::SYNONYMS
3516
+ ]
3517
+ ) ,
3518
+ request_options
3519
+ )
3505
3520
3506
- copy_operation_response = operation_index (
3507
- index_name ,
3508
- Search ::OperationIndexParams . new (
3509
- operation : Search ::OperationType ::COPY ,
3510
- destination : tmp_index_name ,
3511
- scope : [
3512
- Search ::ScopeType ::SETTINGS ,
3513
- Search ::ScopeType ::RULES ,
3514
- Search ::ScopeType ::SYNONYMS
3515
- ]
3516
- ) ,
3517
- request_options
3518
- )
3521
+ wait_for_task ( tmp_index_name , copy_operation_response . task_id )
3519
3522
3520
- wait_for_task ( tmp_index_name , copy_operation_response . task_id )
3523
+ move_operation_response = operation_index (
3524
+ tmp_index_name ,
3525
+ Search ::OperationIndexParams . new (
3526
+ operation : Search ::OperationType ::MOVE ,
3527
+ destination : index_name
3528
+ ) ,
3529
+ request_options
3530
+ )
3521
3531
3522
- move_operation_response = operation_index (
3523
- tmp_index_name ,
3524
- Search ::OperationIndexParams . new (
3525
- operation : Search ::OperationType ::MOVE ,
3526
- destination : index_name
3527
- ) ,
3528
- request_options
3529
- )
3532
+ wait_for_task ( tmp_index_name , move_operation_response . task_id )
3530
3533
3531
- wait_for_task ( tmp_index_name , move_operation_response . task_id )
3534
+ Search ::ReplaceAllObjectsResponse . new (
3535
+ copy_operation_response : copy_operation_response ,
3536
+ batch_responses : batch_responses ,
3537
+ move_operation_response : move_operation_response
3538
+ )
3539
+ rescue Exception => e
3540
+ delete_index ( tmp_index_name )
3532
3541
3533
- Search ::ReplaceAllObjectsResponse . new (
3534
- copy_operation_response : copy_operation_response ,
3535
- batch_responses : batch_responses ,
3536
- move_operation_response : move_operation_response
3537
- )
3542
+ raise e
3543
+ end
3538
3544
end
3539
3545
3540
3546
def index_exists? ( index_name )
0 commit comments