From 42ba6b3a5bf6bebc55797f364be7e750ed1d5206 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 9 Oct 2024 06:14:35 +1100 Subject: [PATCH] [8.15] [Search] Fix issue with crawler not getting deleted (#195440) (#195483) # Backport This will backport the following commits from `main` to `8.15`: - [[Search] Fix issue with crawler not getting deleted (#195440)](https://github.com/elastic/kibana/pull/195440) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Jedr Blaszyk --- .../routes/enterprise_search/indices.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/indices.ts b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/indices.ts index 78d7d2076438e..70b46205c5e88 100644 --- a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/indices.ts +++ b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/indices.ts @@ -14,7 +14,12 @@ import { schema } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; -import { deleteConnectorSecret, updateConnectorIndexName } from '@kbn/search-connectors'; +import { + CRAWLER_SERVICE_TYPE, + deleteConnectorSecret, + deleteConnectorById, + updateConnectorIndexName, +} from '@kbn/search-connectors'; import { fetchConnectorByIndexName, fetchConnectors, @@ -207,13 +212,17 @@ export function registerIndexRoutes({ } if (connector) { - // detach the deleted index without removing the connector - await updateConnectorIndexName(client.asCurrentUser, connector.id, null); - if (connector.api_key_id) { - await client.asCurrentUser.security.invalidateApiKey({ ids: [connector.api_key_id] }); - } - if (connector.api_key_secret_id) { - await deleteConnectorSecret(client.asCurrentUser, connector.api_key_secret_id); + if (connector.service_type === CRAWLER_SERVICE_TYPE) { + await deleteConnectorById(client.asCurrentUser, connector.id); + } else { + // detach the deleted index without removing the connector + await updateConnectorIndexName(client.asCurrentUser, connector.id, null); + if (connector.api_key_id) { + await client.asCurrentUser.security.invalidateApiKey({ ids: [connector.api_key_id] }); + } + if (connector.api_key_secret_id) { + await deleteConnectorSecret(client.asCurrentUser, connector.api_key_secret_id); + } } }