@@ -359,50 +359,54 @@ package object extension {
359359 }
360360 val tmpIndexName = s " ${indexName}_tmp_ ${scala.util.Random .nextInt(100 )}"
361361
362- for {
363- copy <- client.operationIndex(
364- indexName = indexName,
365- operationIndexParams = OperationIndexParams (
366- operation = OperationType .Copy ,
367- destination = tmpIndexName,
368- scope = Some (Seq (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ))
369- ),
370- requestOptions = requestOptions
371- )
362+ try {
363+ for {
364+ copy <- client.operationIndex(
365+ indexName = indexName,
366+ operationIndexParams = OperationIndexParams (
367+ operation = OperationType .Copy ,
368+ destination = tmpIndexName,
369+ scope = Some (Seq (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ))
370+ ),
371+ requestOptions = requestOptions
372+ )
372373
373- batchResponses <- chunkedBatch(
374- indexName = tmpIndexName,
375- objects = objects,
376- action = Action .AddObject ,
377- waitForTasks = true ,
378- batchSize = batchSize,
379- requestOptions = requestOptions
380- )
374+ batchResponses <- chunkedBatch(
375+ indexName = tmpIndexName,
376+ objects = objects,
377+ action = Action .AddObject ,
378+ waitForTasks = true ,
379+ batchSize = batchSize,
380+ requestOptions = requestOptions
381+ )
381382
382- _ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
383+ _ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
383384
384- copy <- client.operationIndex(
385- indexName = indexName,
386- operationIndexParams = OperationIndexParams (
387- operation = OperationType .Copy ,
388- destination = tmpIndexName,
389- scope = Some (Seq (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ))
390- ),
391- requestOptions = requestOptions
392- )
393- _ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
385+ copy <- client.operationIndex(
386+ indexName = indexName,
387+ operationIndexParams = OperationIndexParams (
388+ operation = OperationType .Copy ,
389+ destination = tmpIndexName,
390+ scope = Some (Seq (ScopeType .Settings , ScopeType .Rules , ScopeType .Synonyms ))
391+ ),
392+ requestOptions = requestOptions
393+ )
394+ _ <- client.waitTask(indexName = tmpIndexName, taskID = copy.taskID, requestOptions = requestOptions)
394395
395- move <- client.operationIndex(
396- indexName = tmpIndexName,
397- operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
398- requestOptions = requestOptions
396+ move <- client.operationIndex(
397+ indexName = tmpIndexName,
398+ operationIndexParams = OperationIndexParams (operation = OperationType .Move , destination = indexName),
399+ requestOptions = requestOptions
400+ )
401+ _ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
402+ } yield ReplaceAllObjectsResponse (
403+ copyOperationResponse = copy,
404+ batchResponses = batchResponses,
405+ moveOperationResponse = move
399406 )
400- _ <- client.waitTask(indexName = tmpIndexName, taskID = move.taskID, requestOptions = requestOptions)
401- } yield ReplaceAllObjectsResponse (
402- copyOperationResponse = copy,
403- batchResponses = batchResponses,
404- moveOperationResponse = move
405- )
407+ } finally {
408+ client.deleteIndex(tmpIndexName)
409+ }
406410 }
407411
408412 def indexExists (indexName : String )(implicit ec : ExecutionContext ): Future [Boolean ] = {
0 commit comments