From 5bdf3444f806f1ac89119cf4148d20a12f8b1afd Mon Sep 17 00:00:00 2001 From: Kathleen DeRusso Date: Wed, 13 Mar 2024 15:05:54 -0400 Subject: [PATCH] Update delete object to never fail if alias does not exist --- .../40_search_application_delete.yml | 15 +++++++++++ .../search/SearchApplicationIndexService.java | 25 +++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/40_search_application_delete.yml b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/40_search_application_delete.yml index c196d84755f99..dfc1609a4183d 100644 --- a/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/40_search_application_delete.yml +++ b/x-pack/plugin/ent-search/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/entsearch/40_search_application_delete.yml @@ -77,3 +77,18 @@ teardown: name: test-search-application-to-delete - match: { acknowledged: true } + +--- +"Delete Search Application - Alias does not exist as alias was explicitly removed": + - do: + indices.update_aliases: + body: + actions: + - remove: + index: test-index + alias: test-search-application-to-delete + + search_application.delete: + name: test-search-application-to-delete + + - match: { acknowledged: true } diff --git a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplicationIndexService.java b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplicationIndexService.java index 46e4d45f2c146..61e425d4b05dd 100644 --- a/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplicationIndexService.java +++ b/x-pack/plugin/ent-search/src/main/java/org/elasticsearch/xpack/application/search/SearchApplicationIndexService.java @@ -330,16 +330,21 @@ private void removeAlias(String searchAliasName, ActionListener( - searchAliasName, - listener, - (l, acknowledgedResponse) -> l.onResponse(AcknowledgedResponse.TRUE) - ) - ); + client.admin().indices().aliases(aliasesRequest, new ActionListener<>() { + @Override + public void onResponse(AcknowledgedResponse acknowledgedResponse) { + listener.onResponse(AcknowledgedResponse.TRUE); + } + + @Override + public void onFailure(Exception e) { + if (e instanceof ResourceNotFoundException) { + listener.onResponse(AcknowledgedResponse.TRUE); + } else { + listener.onFailure(e); + } + } + }); } /**