@@ -465,46 +465,50 @@ public suspend fun SearchClient.replaceAllObjects(
465
465
): ReplaceAllObjectsResponse {
466
466
val tmpIndexName = " ${indexName} _tmp_${Random .nextInt(from = 0 , until = 100 )} "
467
467
468
- var copy = operationIndex(
469
- indexName = indexName,
470
- operationIndexParams = OperationIndexParams (
471
- operation = OperationType .Copy ,
472
- destination = tmpIndexName,
473
- scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
474
- ),
475
- requestOptions = requestOptions,
476
- )
468
+ try {
469
+ var copy = operationIndex(
470
+ indexName = indexName,
471
+ operationIndexParams = OperationIndexParams (
472
+ operation = OperationType .Copy ,
473
+ destination = tmpIndexName,
474
+ scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
475
+ ),
476
+ requestOptions = requestOptions,
477
+ )
477
478
478
- val batchResponses = this .chunkedBatch(
479
- indexName = tmpIndexName,
480
- objects = objects,
481
- action = Action .AddObject ,
482
- waitForTask = true ,
483
- batchSize = batchSize,
484
- requestOptions = requestOptions,
485
- )
479
+ val batchResponses = this .chunkedBatch(
480
+ indexName = tmpIndexName,
481
+ objects = objects,
482
+ action = Action .AddObject ,
483
+ waitForTask = true ,
484
+ batchSize = batchSize,
485
+ requestOptions = requestOptions,
486
+ )
486
487
487
- waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
488
+ waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
488
489
489
- copy = operationIndex(
490
- indexName = indexName,
491
- operationIndexParams = OperationIndexParams (
492
- operation = OperationType .Copy ,
493
- destination = tmpIndexName,
494
- scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
495
- ),
496
- requestOptions = requestOptions,
497
- )
498
- waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
490
+ copy = operationIndex(
491
+ indexName = indexName,
492
+ operationIndexParams = OperationIndexParams (
493
+ operation = OperationType .Copy ,
494
+ destination = tmpIndexName,
495
+ scope = listOf (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ),
496
+ ),
497
+ requestOptions = requestOptions,
498
+ )
499
+ waitForTask(indexName = tmpIndexName, taskID = copy.taskID)
499
500
500
- val move = operationIndex(
501
- indexName = tmpIndexName,
502
- operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
503
- requestOptions = requestOptions,
504
- )
505
- waitForTask(indexName = tmpIndexName, taskID = move.taskID)
501
+ val move = operationIndex(
502
+ indexName = tmpIndexName,
503
+ operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
504
+ requestOptions = requestOptions,
505
+ )
506
+ waitForTask(indexName = tmpIndexName, taskID = move.taskID)
506
507
507
- return ReplaceAllObjectsResponse (copy, batchResponses, move)
508
+ return ReplaceAllObjectsResponse (copy, batchResponses, move)
509
+ } finally {
510
+ deleteIndex(tmpIndexName)
511
+ }
508
512
}
509
513
510
514
/* *
@@ -535,6 +539,13 @@ public fun securedApiKeyRemainingValidity(apiKey: String): Duration {
535
539
return validUntil - Clock .System .now()
536
540
}
537
541
542
+ /* *
543
+ * Checks that an index exists.
544
+ *
545
+ * @param indexName The name of the index to check.
546
+ * @return true if the index exists, false otherwise.
547
+ * @throws AlgoliaApiException if an error occurs during the request.
548
+ */
538
549
public suspend fun SearchClient.indexExists (indexName : String ): Boolean {
539
550
try {
540
551
getSettings(indexName)
0 commit comments