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); + } } }