diff --git a/package.json b/package.json
index 554aeb48e9c8ac..f23ef1aa97723c 100644
--- a/package.json
+++ b/package.json
@@ -169,6 +169,12 @@
"@kbn/core-doc-links-server": "link:bazel-bin/packages/core/doc-links/core-doc-links-server",
"@kbn/core-doc-links-server-internal": "link:bazel-bin/packages/core/doc-links/core-doc-links-server-internal",
"@kbn/core-doc-links-server-mocks": "link:bazel-bin/packages/core/doc-links/core-doc-links-server-mocks",
+ "@kbn/core-elasticsearch-client-server": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server",
+ "@kbn/core-elasticsearch-client-server-internal": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-internal",
+ "@kbn/core-elasticsearch-client-server-mocks": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-mocks",
+ "@kbn/core-elasticsearch-server": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server",
+ "@kbn/core-elasticsearch-server-internal": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-internal",
+ "@kbn/core-elasticsearch-server-mocks": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-mocks",
"@kbn/core-environment-server-internal": "link:bazel-bin/packages/core/environment/core-environment-server-internal",
"@kbn/core-environment-server-mocks": "link:bazel-bin/packages/core/environment/core-environment-server-mocks",
"@kbn/core-execution-context-browser": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser",
@@ -757,6 +763,12 @@
"@types/kbn__core-doc-links-server": "link:bazel-bin/packages/core/doc-links/core-doc-links-server/npm_module_types",
"@types/kbn__core-doc-links-server-internal": "link:bazel-bin/packages/core/doc-links/core-doc-links-server-internal/npm_module_types",
"@types/kbn__core-doc-links-server-mocks": "link:bazel-bin/packages/core/doc-links/core-doc-links-server-mocks/npm_module_types",
+ "@types/kbn__core-elasticsearch-client-server": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server/npm_module_types",
+ "@types/kbn__core-elasticsearch-client-server-internal": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-internal/npm_module_types",
+ "@types/kbn__core-elasticsearch-client-server-mocks": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/npm_module_types",
+ "@types/kbn__core-elasticsearch-server": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server/npm_module_types",
+ "@types/kbn__core-elasticsearch-server-internal": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-internal/npm_module_types",
+ "@types/kbn__core-elasticsearch-server-mocks": "link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-mocks/npm_module_types",
"@types/kbn__core-environment-server-internal": "link:bazel-bin/packages/core/environment/core-environment-server-internal/npm_module_types",
"@types/kbn__core-environment-server-mocks": "link:bazel-bin/packages/core/environment/core-environment-server-mocks/npm_module_types",
"@types/kbn__core-execution-context-browser": "link:bazel-bin/packages/core/execution-context/core-execution-context-browser/npm_module_types",
diff --git a/packages/BUILD.bazel b/packages/BUILD.bazel
index efa4b2b7adcb97..d4bf2ee0807e54 100644
--- a/packages/BUILD.bazel
+++ b/packages/BUILD.bazel
@@ -37,6 +37,11 @@ filegroup(
"//packages/core/doc-links/core-doc-links-server-internal:build",
"//packages/core/doc-links/core-doc-links-server-mocks:build",
"//packages/core/doc-links/core-doc-links-server:build",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal:build",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-mocks:build",
+ "//packages/core/elasticsearch/core-elasticsearch-server-internal:build",
+ "//packages/core/elasticsearch/core-elasticsearch-server-mocks:build",
+ "//packages/core/elasticsearch/core-elasticsearch-server:build",
"//packages/core/environment/core-environment-server-internal:build",
"//packages/core/environment/core-environment-server-mocks:build",
"//packages/core/execution-context/core-execution-context-browser-internal:build",
@@ -248,6 +253,11 @@ filegroup(
"//packages/core/doc-links/core-doc-links-server-internal:build_types",
"//packages/core/doc-links/core-doc-links-server-mocks:build_types",
"//packages/core/doc-links/core-doc-links-server:build_types",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal:build_types",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-mocks:build_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server-internal:build_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server-mocks:build_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server:build_types",
"//packages/core/environment/core-environment-server-internal:build_types",
"//packages/core/environment/core-environment-server-mocks:build_types",
"//packages/core/execution-context/core-execution-context-browser-internal:build_types",
diff --git a/packages/core/base/core-base-common/BUILD.bazel b/packages/core/base/core-base-common/BUILD.bazel
index 7282d7ad4af186..0dd9cf7a57d94c 100644
--- a/packages/core/base/core-base-common/BUILD.bazel
+++ b/packages/core/base/core-base-common/BUILD.bazel
@@ -26,11 +26,13 @@ NPM_MODULE_EXTRA_FILES = [
]
RUNTIME_DEPS = [
+ "//packages/kbn-std",
]
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
+ "//packages/kbn-std:npm_module_types",
"//packages/kbn-config:npm_module_types",
]
diff --git a/packages/core/base/core-base-common/src/index.ts b/packages/core/base/core-base-common/src/index.ts
index ae2ac637e3e084..7785bd332aecda 100644
--- a/packages/core/base/core-base-common/src/index.ts
+++ b/packages/core/base/core-base-common/src/index.ts
@@ -9,3 +9,5 @@
export type { PluginOpaqueId, PluginName, DiscoveredPlugin } from './plugins';
export { PluginType } from './plugins';
export { EUI_STYLES_GLOBAL } from './eui';
+export { ServiceStatusLevels } from './service_status';
+export type { ServiceStatus, ServiceStatusLevel } from './service_status';
diff --git a/packages/core/base/core-base-common/src/service_status.ts b/packages/core/base/core-base-common/src/service_status.ts
new file mode 100644
index 00000000000000..4c9539f015d86a
--- /dev/null
+++ b/packages/core/base/core-base-common/src/service_status.ts
@@ -0,0 +1,101 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import { deepFreeze } from '@kbn/std';
+
+/**
+ * The current status of a service at a point in time.
+ *
+ * @typeParam Meta - JSON-serializable object. Plugins should export this type to allow other plugins to read the `meta`
+ * field in a type-safe way.
+ * @public
+ */
+export interface ServiceStatus | unknown = unknown> {
+ /**
+ * The current availability level of the service.
+ */
+ level: ServiceStatusLevel;
+ /**
+ * A high-level summary of the service status.
+ */
+ summary: string;
+ /**
+ * A more detailed description of the service status.
+ */
+ detail?: string;
+ /**
+ * A URL to open in a new tab about how to resolve or troubleshoot the problem.
+ */
+ documentationUrl?: string;
+ /**
+ * Any JSON-serializable data to be included in the HTTP API response. Useful for providing more fine-grained,
+ * machine-readable information about the service status. May include status information for underlying features.
+ */
+ meta?: Meta;
+}
+
+/**
+ * The current "level" of availability of a service.
+ *
+ * @remarks
+ * The values implement `valueOf` to allow for easy comparisons between status levels with <, >, etc. Higher values
+ * represent higher severities. Note that the default `Array.prototype.sort` implementation does not correctly sort
+ * these values.
+ *
+ * A snapshot serializer is available in `src/core/server/test_utils` to ease testing of these values with Jest.
+ *
+ * @public
+ */
+export const ServiceStatusLevels = deepFreeze({
+ /**
+ * Everything is working!
+ */
+ available: {
+ toString: () => 'available',
+ valueOf: () => 0,
+ toJSON() {
+ return this.toString();
+ },
+ },
+ /**
+ * Some features may not be working.
+ */
+ degraded: {
+ toString: () => 'degraded',
+ valueOf: () => 1,
+ toJSON() {
+ return this.toString();
+ },
+ },
+ /**
+ * The service is unavailable, but other functions that do not depend on this service should work.
+ */
+ unavailable: {
+ toString: () => 'unavailable',
+ valueOf: () => 2,
+ toJSON() {
+ return this.toString();
+ },
+ },
+ /**
+ * Block all user functions and display the status page, reserved for Core services only.
+ */
+ critical: {
+ toString: () => 'critical',
+ valueOf: () => 3,
+ toJSON() {
+ return this.toString();
+ },
+ },
+});
+
+/**
+ * A convenience type that represents the union of each value in {@link ServiceStatusLevels}.
+ * @public
+ */
+export type ServiceStatusLevel = typeof ServiceStatusLevels[keyof typeof ServiceStatusLevels];
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/BUILD.bazel b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/BUILD.bazel
new file mode 100644
index 00000000000000..c297697811253a
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/BUILD.bazel
@@ -0,0 +1,116 @@
+load("@npm//@bazel/typescript:index.bzl", "ts_config")
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
+
+PKG_DIRNAME = "core-elasticsearch-client-server-internal"
+PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-client-server-internal"
+
+SOURCE_FILES = glob(
+ [
+ "src/**/*.ts",
+ ],
+ exclude = [
+ "**/*.test.*",
+ "**/*.stories.*",
+ ],
+)
+
+SRCS = SOURCE_FILES
+
+filegroup(
+ name = "srcs",
+ srcs = SRCS,
+)
+
+NPM_MODULE_EXTRA_FILES = [
+ "package.json",
+]
+
+RUNTIME_DEPS = [
+ "@npm//moment",
+ "@npm//@elastic/elasticsearch",
+ "@npm//@elastic/numeral",
+ "//packages/kbn-std",
+ "//packages/kbn-es-errors",
+ "//packages/core/http/core-http-router-server-internal",
+ ### test dependencies
+ "//packages/core/logging/core-logging-server-mocks",
+ "//packages/core/http/core-http-server-mocks",
+]
+
+TYPES_DEPS = [
+ "@npm//@types/node",
+ "@npm//@types/jest",
+ "@npm//moment",
+ "@npm//@elastic/elasticsearch",
+ "@npm//@elastic/numeral",
+ "//packages/kbn-utility-types:npm_module_types",
+ "//packages/kbn-std:npm_module_types",
+ "//packages/kbn-es-errors:npm_module_types",
+ "//packages/kbn-logging:npm_module_types",
+ "//packages/core/http/core-http-server:npm_module_types",
+ "//packages/core/http/core-http-router-server-internal:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
+]
+
+jsts_transpiler(
+ name = "target_node",
+ srcs = SRCS,
+ build_pkg_name = package_name(),
+)
+
+ts_config(
+ name = "tsconfig",
+ src = "tsconfig.json",
+ deps = [
+ "//:tsconfig.base.json",
+ "//:tsconfig.bazel.json",
+ ],
+)
+
+ts_project(
+ name = "tsc_types",
+ args = ['--pretty'],
+ srcs = SRCS,
+ deps = TYPES_DEPS,
+ declaration = True,
+ declaration_map = True,
+ emit_declaration_only = True,
+ out_dir = "target_types",
+ root_dir = "src",
+ tsconfig = ":tsconfig",
+)
+
+js_library(
+ name = PKG_DIRNAME,
+ srcs = NPM_MODULE_EXTRA_FILES,
+ deps = RUNTIME_DEPS + [":target_node"],
+ package_name = PKG_REQUIRE_NAME,
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm(
+ name = "npm_module",
+ deps = [":" + PKG_DIRNAME],
+)
+
+filegroup(
+ name = "build",
+ srcs = [":npm_module"],
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm_types(
+ name = "npm_module_types",
+ srcs = SRCS,
+ deps = [":tsc_types"],
+ package_name = PKG_REQUIRE_NAME,
+ tsconfig = ":tsconfig",
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "build_types",
+ srcs = [":npm_module_types"],
+ visibility = ["//visibility:public"],
+)
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/README.md b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/README.md
new file mode 100644
index 00000000000000..019af4b68bc669
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/README.md
@@ -0,0 +1,3 @@
+# @kbn/core-elasticsearch-client-server-internal
+
+This package contains the internal implementation for Core's server-side elasticsearch client.
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/jest.config.js b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/jest.config.js
new file mode 100644
index 00000000000000..49e02733250cf1
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/jest.config.js
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+module.exports = {
+ preset: '@kbn/test/jest_node',
+ rootDir: '../../../..',
+ roots: ['/packages/core/elasticsearch/core-elasticsearch-client-server-internal'],
+};
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/package.json b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/package.json
new file mode 100644
index 00000000000000..8029d8dfcf9f55
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@kbn/core-elasticsearch-client-server-internal",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./target_node/index.js",
+ "license": "SSPL-1.0 OR Elastic License 2.0"
+}
diff --git a/src/core/server/elasticsearch/client/client_config.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.test.ts
similarity index 98%
rename from src/core/server/elasticsearch/client/client_config.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.test.ts
index dcc6d25c565bf9..f7988a19009bb9 100644
--- a/src/core/server/elasticsearch/client/client_config.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.test.ts
@@ -7,8 +7,9 @@
*/
import { duration } from 'moment';
-import { ElasticsearchClientConfig, parseClientOptions } from './client_config';
-import { DEFAULT_HEADERS } from '../default_headers';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
+import { parseClientOptions } from './client_config';
+import { DEFAULT_HEADERS } from './headers';
const createConfig = (
parts: Partial = {}
diff --git a/src/core/server/elasticsearch/client/client_config.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.ts
similarity index 81%
rename from src/core/server/elasticsearch/client/client_config.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.ts
index 63b9555a420abc..9d380fcbaa4557 100644
--- a/src/core/server/elasticsearch/client/client_config.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/client_config.ts
@@ -10,35 +10,8 @@ import { ConnectionOptions as TlsConnectionOptions } from 'tls';
import { URL } from 'url';
import { Duration } from 'moment';
import type { ClientOptions } from '@elastic/elasticsearch/lib/client';
-import { ElasticsearchConfig } from '../elasticsearch_config';
-import { DEFAULT_HEADERS } from '../default_headers';
-
-/**
- * Configuration options to be used to create a {@link IClusterClient | cluster client} using the
- * {@link ElasticsearchServiceStart.createClient | createClient API}
- *
- * @public
- */
-export type ElasticsearchClientConfig = Pick<
- ElasticsearchConfig,
- | 'customHeaders'
- | 'maxSockets'
- | 'compression'
- | 'sniffOnStart'
- | 'sniffOnConnectionFault'
- | 'requestHeadersWhitelist'
- | 'sniffInterval'
- | 'hosts'
- | 'username'
- | 'password'
- | 'serviceAccountToken'
-> & {
- pingTimeout?: ElasticsearchConfig['pingTimeout'] | ClientOptions['pingTimeout'];
- requestTimeout?: ElasticsearchConfig['requestTimeout'] | ClientOptions['requestTimeout'];
- ssl?: Partial;
- keepAlive?: boolean;
- caFingerprint?: ClientOptions['caFingerprint'];
-};
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
+import { DEFAULT_HEADERS } from './headers';
/**
* Parse the client options from given client config and `scoped` flag.
diff --git a/src/core/server/elasticsearch/client/cluster_client.test.mocks.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.test.mocks.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/cluster_client.test.mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.test.mocks.ts
diff --git a/src/core/server/elasticsearch/client/cluster_client.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.test.ts
similarity index 97%
rename from src/core/server/elasticsearch/client/cluster_client.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.test.ts
index 78fc0494951a78..3b2e6f82fe40dd 100644
--- a/src/core/server/elasticsearch/client/cluster_client.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.test.ts
@@ -11,12 +11,12 @@ import {
createTransportMock,
createInternalErrorHandlerMock,
} from './cluster_client.test.mocks';
+import type { Client } from '@elastic/elasticsearch';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { httpServerMock, httpServiceMock } from '@kbn/core-http-server-mocks';
-import { elasticsearchClientMock } from './mocks';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
import { ClusterClient } from './cluster_client';
-import { ElasticsearchClientConfig } from './client_config';
-import { DEFAULT_HEADERS } from '../default_headers';
+import { DEFAULT_HEADERS } from './headers';
const createConfig = (
parts: Partial = {}
@@ -34,18 +34,21 @@ const createConfig = (
};
};
+const createClient = () =>
+ ({ close: jest.fn(), child: jest.fn() } as unknown as jest.Mocked);
+
describe('ClusterClient', () => {
let logger: ReturnType;
let authHeaders: ReturnType;
- let internalClient: ReturnType;
- let scopedClient: ReturnType;
+ let internalClient: jest.Mocked;
+ let scopedClient: jest.Mocked;
const mockTransport = { mockTransport: true };
beforeEach(() => {
logger = loggingSystemMock.createLogger();
- internalClient = elasticsearchClientMock.createInternalClient();
- scopedClient = elasticsearchClientMock.createInternalClient();
+ internalClient = createClient();
+ scopedClient = createClient();
authHeaders = httpServiceMock.createAuthHeaderStorage();
authHeaders.get.mockImplementation(() => ({
diff --git a/src/core/server/elasticsearch/client/cluster_client.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.ts
similarity index 74%
rename from src/core/server/elasticsearch/client/cluster_client.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.ts
index 2eaaa0d6efca4e..088a99c7642f0a 100644
--- a/src/core/server/elasticsearch/client/cluster_client.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/cluster_client.ts
@@ -15,52 +15,20 @@ import {
isKibanaRequest,
isRealRequest,
} from '@kbn/core-http-router-server-internal';
-import { ScopeableRequest } from '../types';
-import { ElasticsearchClient } from './types';
-import { configureClient } from './configure_client';
-import { ElasticsearchClientConfig } from './client_config';
-import { ScopedClusterClient, IScopedClusterClient } from './scoped_cluster_client';
-import { DEFAULT_HEADERS } from '../default_headers';
-import {
+import type {
+ ScopeableRequest,
UnauthorizedErrorHandler,
- createInternalErrorHandler,
- InternalUnauthorizedErrorHandler,
-} from './retry_unauthorized';
+ ICustomClusterClient,
+} from '@kbn/core-elasticsearch-server';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
+import { configureClient } from './configure_client';
+import { ScopedClusterClient } from './scoped_cluster_client';
+import { DEFAULT_HEADERS } from './headers';
+import { createInternalErrorHandler, InternalUnauthorizedErrorHandler } from './retry_unauthorized';
import { createTransport } from './create_transport';
const noop = () => undefined;
-/**
- * Represents an Elasticsearch cluster API client created by the platform.
- * It allows to call API on behalf of the internal Kibana user and
- * the actual user that is derived from the request headers (via `asScoped(...)`).
- *
- * @public
- **/
-export interface IClusterClient {
- /**
- * A {@link ElasticsearchClient | client} to be used to query the ES cluster on behalf of the Kibana internal user
- */
- readonly asInternalUser: ElasticsearchClient;
- /**
- * Creates a {@link IScopedClusterClient | scoped cluster client} bound to given {@link ScopeableRequest | request}
- */
- asScoped: (request: ScopeableRequest) => IScopedClusterClient;
-}
-
-/**
- * See {@link IClusterClient}
- *
- * @public
- */
-export interface ICustomClusterClient extends IClusterClient {
- /**
- * Closes the cluster client. After that client cannot be used and one should
- * create a new client instance to be able to interact with Elasticsearch API.
- */
- close: () => Promise;
-}
-
/** @internal **/
export class ClusterClient implements ICustomClusterClient {
private readonly config: ElasticsearchClientConfig;
diff --git a/src/core/server/elasticsearch/client/configure_client.test.mocks.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.test.mocks.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/configure_client.test.mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.test.mocks.ts
diff --git a/src/core/server/elasticsearch/client/configure_client.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.test.ts
similarity index 98%
rename from src/core/server/elasticsearch/client/configure_client.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.test.ts
index b25568bbd906ea..e4fb582972b1b1 100644
--- a/src/core/server/elasticsearch/client/configure_client.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.test.ts
@@ -18,7 +18,7 @@ import {
} from './configure_client.test.mocks';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { ClusterConnectionPool } from '@elastic/elasticsearch';
-import type { ElasticsearchClientConfig } from './client_config';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
import { configureClient } from './configure_client';
import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation';
diff --git a/src/core/server/elasticsearch/client/configure_client.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.ts
similarity index 91%
rename from src/core/server/elasticsearch/client/configure_client.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.ts
index 248820ceb1f56f..4901349e6b487b 100644
--- a/src/core/server/elasticsearch/client/configure_client.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/configure_client.ts
@@ -8,7 +8,8 @@
import { Client, HttpConnection, ClusterConnectionPool } from '@elastic/elasticsearch';
import type { Logger } from '@kbn/logging';
-import { parseClientOptions, ElasticsearchClientConfig } from './client_config';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
+import { parseClientOptions } from './client_config';
import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation';
import { createTransport } from './create_transport';
diff --git a/src/core/server/elasticsearch/client/create_transport.test.mocks.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.test.mocks.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/create_transport.test.mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.test.mocks.ts
diff --git a/src/core/server/elasticsearch/client/create_transport.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/create_transport.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.test.ts
diff --git a/src/core/server/elasticsearch/client/create_transport.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.ts
similarity index 91%
rename from src/core/server/elasticsearch/client/create_transport.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.ts
index 363dbb416979d1..07ed3833a7af21 100644
--- a/src/core/server/elasticsearch/client/create_transport.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/create_transport.ts
@@ -7,13 +7,13 @@
*/
import type { IncomingHttpHeaders } from 'http';
-import type {
- TransportRequestParams,
- TransportRequestOptions,
- TransportResult,
-} from '@elastic/transport';
-import type { TransportOptions } from '@elastic/transport/lib/Transport';
-import { Transport } from '@elastic/elasticsearch';
+import {
+ Transport,
+ type TransportOptions,
+ type TransportRequestParams,
+ type TransportRequestOptions,
+ type TransportResult,
+} from '@elastic/elasticsearch';
import { isUnauthorizedError } from '@kbn/es-errors';
import { InternalUnauthorizedErrorHandler, isRetryResult } from './retry_unauthorized';
diff --git a/src/core/server/elasticsearch/client/get_ecs_response_log.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.test.ts
similarity index 99%
rename from src/core/server/elasticsearch/client/get_ecs_response_log.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.test.ts
index ec00badbcdf287..03c8c118edcf2c 100644
--- a/src/core/server/elasticsearch/client/get_ecs_response_log.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.test.ts
@@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
+
import { type DiagnosticResult, type ConnectionRequestParams } from '@elastic/elasticsearch';
import { getEcsResponseLog } from './get_ecs_response_log';
diff --git a/src/core/server/elasticsearch/client/get_ecs_response_log.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.ts
similarity index 99%
rename from src/core/server/elasticsearch/client/get_ecs_response_log.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.ts
index b977f03a9a062c..fa122166ada08c 100644
--- a/src/core/server/elasticsearch/client/get_ecs_response_log.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/get_ecs_response_log.ts
@@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
+
import { type IncomingHttpHeaders } from 'http';
import { type DiagnosticResult } from '@elastic/elasticsearch';
import { type LogMeta } from '@kbn/logging';
diff --git a/src/core/server/elasticsearch/default_headers.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/headers.ts
similarity index 72%
rename from src/core/server/elasticsearch/default_headers.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/headers.ts
index eef04754cd958c..755947490f05c7 100644
--- a/src/core/server/elasticsearch/default_headers.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/headers.ts
@@ -8,22 +8,26 @@
import { deepFreeze } from '@kbn/std';
+/**
+ * @internal
+ */
+export const PRODUCT_RESPONSE_HEADER = 'x-elastic-product';
+
+/**
+ * @internal
+ */
export const PRODUCT_ORIGIN_HEADER = 'x-elastic-product-origin';
+/**
+ * @internal
+ */
export const RESERVED_HEADERS = deepFreeze([PRODUCT_ORIGIN_HEADER]);
+/**
+ * @internal
+ */
export const DEFAULT_HEADERS = deepFreeze({
// Elasticsearch uses this to identify when a request is coming from Kibana, to allow Kibana to
// access system indices using the standard ES APIs.
[PRODUCT_ORIGIN_HEADER]: 'kibana',
});
-
-export const getReservedHeaders = (headerNames: string[]): string[] => {
- const reservedHeaders = [];
- for (const headerName of headerNames) {
- if (RESERVED_HEADERS.includes(headerName.toLowerCase())) {
- reservedHeaders.push(headerName);
- }
- }
- return reservedHeaders;
-};
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/index.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/index.ts
new file mode 100644
index 00000000000000..a4ca96fdd70361
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/index.ts
@@ -0,0 +1,18 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+export { ScopedClusterClient } from './scoped_cluster_client';
+export { ClusterClient } from './cluster_client';
+export { configureClient } from './configure_client';
+export { getRequestDebugMeta, getErrorMessage } from './log_query_and_deprecation';
+export {
+ PRODUCT_RESPONSE_HEADER,
+ DEFAULT_HEADERS,
+ PRODUCT_ORIGIN_HEADER,
+ RESERVED_HEADERS,
+} from './headers';
diff --git a/src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/log_query_and_deprecation.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/log_query_and_deprecation.test.ts
diff --git a/src/core/server/elasticsearch/client/log_query_and_deprecation.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/log_query_and_deprecation.ts
similarity index 99%
rename from src/core/server/elasticsearch/client/log_query_and_deprecation.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/log_query_and_deprecation.ts
index 7d48b924cdf36a..460ca0446f0fc0 100644
--- a/src/core/server/elasticsearch/client/log_query_and_deprecation.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/log_query_and_deprecation.ts
@@ -5,6 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
+
import type { IncomingHttpHeaders } from 'http';
import { Buffer } from 'buffer';
import { stringify } from 'querystring';
diff --git a/src/core/server/elasticsearch/client/retry_unauthorized.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/retry_unauthorized.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/retry_unauthorized.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/retry_unauthorized.test.ts
diff --git a/src/core/server/elasticsearch/client/retry_unauthorized.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/retry_unauthorized.ts
similarity index 58%
rename from src/core/server/elasticsearch/client/retry_unauthorized.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/retry_unauthorized.ts
index 568bc530e2fe8a..e8337898eb6c3f 100644
--- a/src/core/server/elasticsearch/client/retry_unauthorized.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/retry_unauthorized.ts
@@ -8,71 +8,16 @@
import { MaybePromise } from '@kbn/utility-types';
import { UnauthorizedError } from '@kbn/es-errors';
-import type { AuthHeaders, KibanaRequest, SetAuthHeaders } from '@kbn/core-http-server';
+import type { SetAuthHeaders } from '@kbn/core-http-server';
import { isRealRequest } from '@kbn/core-http-router-server-internal';
-import { ScopeableRequest } from '../types';
-
-/**
- * @public
- */
-export interface UnauthorizedErrorHandlerOptions {
- error: UnauthorizedError;
- request: KibanaRequest;
-}
-
-/**
- * @public
- */
-export interface UnauthorizedErrorHandlerResultRetryParams {
- authHeaders: AuthHeaders;
-}
-
-/**
- * @public
- */
-export interface UnauthorizedErrorHandlerRetryResult
- extends UnauthorizedErrorHandlerResultRetryParams {
- type: 'retry';
-}
-
-/**
- * @public
- */
-export interface UnauthorizedErrorHandlerNotHandledResult {
- type: 'notHandled';
-}
-
-/**
- * @public
- */
-export type UnauthorizedErrorHandlerResult =
- | UnauthorizedErrorHandlerRetryResult
- | UnauthorizedErrorHandlerNotHandledResult;
-
-/**
- * Toolkit passed to a {@link UnauthorizedErrorHandler} used to generate responses from the handler
- * @public
- */
-export interface UnauthorizedErrorHandlerToolkit {
- /**
- * The handler cannot handle the error, or was not able to authenticate.
- */
- notHandled: () => UnauthorizedErrorHandlerNotHandledResult;
- /**
- * The handler was able to authenticate. Will retry the failed request with new auth headers
- */
- retry: (params: UnauthorizedErrorHandlerResultRetryParams) => UnauthorizedErrorHandlerRetryResult;
-}
-
-/**
- * A handler used to handle unauthorized error returned by elasticsearch
- *
- * @public
- */
-export type UnauthorizedErrorHandler = (
- options: UnauthorizedErrorHandlerOptions,
- toolkit: UnauthorizedErrorHandlerToolkit
-) => MaybePromise;
+import type {
+ ScopeableRequest,
+ UnauthorizedErrorHandler,
+ UnauthorizedErrorHandlerResult,
+ UnauthorizedErrorHandlerToolkit,
+ UnauthorizedErrorHandlerRetryResult,
+ UnauthorizedErrorHandlerNotHandledResult,
+} from '@kbn/core-elasticsearch-server';
/** @internal */
export type InternalUnauthorizedErrorHandler = (
diff --git a/src/core/server/elasticsearch/client/scoped_cluster_client.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.test.ts
similarity index 71%
rename from src/core/server/elasticsearch/client/scoped_cluster_client.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.test.ts
index 6635f32b8863fe..75d2e9d9e63611 100644
--- a/src/core/server/elasticsearch/client/scoped_cluster_client.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.test.ts
@@ -6,13 +6,15 @@
* Side Public License, v 1.
*/
-import { elasticsearchClientMock } from './mocks';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { ScopedClusterClient } from './scoped_cluster_client';
+const createEsClient = () => ({} as unknown as ElasticsearchClient);
+
describe('ScopedClusterClient', () => {
it('uses the internal client passed in the constructor', () => {
- const internalClient = elasticsearchClientMock.createElasticsearchClient();
- const scopedClient = elasticsearchClientMock.createElasticsearchClient();
+ const internalClient = createEsClient();
+ const scopedClient = createEsClient();
const scopedClusterClient = new ScopedClusterClient(internalClient, scopedClient);
@@ -20,8 +22,8 @@ describe('ScopedClusterClient', () => {
});
it('uses the scoped client passed in the constructor', () => {
- const internalClient = elasticsearchClientMock.createElasticsearchClient();
- const scopedClient = elasticsearchClientMock.createElasticsearchClient();
+ const internalClient = createEsClient();
+ const scopedClient = createEsClient();
const scopedClusterClient = new ScopedClusterClient(internalClient, scopedClient);
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.ts
new file mode 100644
index 00000000000000..dedccacf43202c
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/src/scoped_cluster_client.ts
@@ -0,0 +1,17 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { ElasticsearchClient, IScopedClusterClient } from '@kbn/core-elasticsearch-server';
+
+/** @internal **/
+export class ScopedClusterClient implements IScopedClusterClient {
+ constructor(
+ public readonly asInternalUser: ElasticsearchClient,
+ public readonly asCurrentUser: ElasticsearchClient
+ ) {}
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-internal/tsconfig.json b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/tsconfig.json
new file mode 100644
index 00000000000000..39d3c7097814ac
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-internal/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../../../../tsconfig.bazel.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "target_types",
+ "rootDir": "src",
+ "stripInternal": false,
+ "types": [
+ "jest",
+ "node"
+ ]
+ },
+ "include": [
+ "src/**/*"
+ ]
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/BUILD.bazel b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/BUILD.bazel
new file mode 100644
index 00000000000000..a8534e09fd9295
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/BUILD.bazel
@@ -0,0 +1,102 @@
+load("@npm//@bazel/typescript:index.bzl", "ts_config")
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
+
+PKG_DIRNAME = "core-elasticsearch-client-server-mocks"
+PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-client-server-mocks"
+
+SOURCE_FILES = glob(
+ [
+ "src/**/*.ts",
+ ],
+ exclude = [
+ "**/*.test.*",
+ "**/*.stories.*",
+ ],
+)
+
+SRCS = SOURCE_FILES
+
+filegroup(
+ name = "srcs",
+ srcs = SRCS,
+)
+
+NPM_MODULE_EXTRA_FILES = [
+ "package.json",
+]
+
+RUNTIME_DEPS = [
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal",
+]
+
+TYPES_DEPS = [
+ "@npm//@types/node",
+ "@npm//@types/jest",
+ "@npm//@elastic/elasticsearch",
+ "//packages/kbn-utility-types:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal:npm_module_types",
+]
+
+jsts_transpiler(
+ name = "target_node",
+ srcs = SRCS,
+ build_pkg_name = package_name(),
+)
+
+ts_config(
+ name = "tsconfig",
+ src = "tsconfig.json",
+ deps = [
+ "//:tsconfig.base.json",
+ "//:tsconfig.bazel.json",
+ ],
+)
+
+ts_project(
+ name = "tsc_types",
+ args = ['--pretty'],
+ srcs = SRCS,
+ deps = TYPES_DEPS,
+ declaration = True,
+ declaration_map = True,
+ emit_declaration_only = True,
+ out_dir = "target_types",
+ root_dir = "src",
+ tsconfig = ":tsconfig",
+)
+
+js_library(
+ name = PKG_DIRNAME,
+ srcs = NPM_MODULE_EXTRA_FILES,
+ deps = RUNTIME_DEPS + [":target_node"],
+ package_name = PKG_REQUIRE_NAME,
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm(
+ name = "npm_module",
+ deps = [":" + PKG_DIRNAME],
+)
+
+filegroup(
+ name = "build",
+ srcs = [":npm_module"],
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm_types(
+ name = "npm_module_types",
+ srcs = SRCS,
+ deps = [":tsc_types"],
+ package_name = PKG_REQUIRE_NAME,
+ tsconfig = ":tsconfig",
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "build_types",
+ srcs = [":npm_module_types"],
+ visibility = ["//visibility:public"],
+)
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/README.md b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/README.md
new file mode 100644
index 00000000000000..3f2b0129bd3742
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/README.md
@@ -0,0 +1,3 @@
+# @kbn/core-elasticsearch-client-server-mocks
+
+This package contains the mocks for the server-side elasticsearch client.
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/jest.config.js b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/jest.config.js
new file mode 100644
index 00000000000000..a88ecf94eb7349
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/jest.config.js
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+module.exports = {
+ preset: '@kbn/test/jest_node',
+ rootDir: '../../../..',
+ roots: ['/packages/core/elasticsearch/core-elasticsearch-client-server-mocks'],
+};
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/package.json b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/package.json
new file mode 100644
index 00000000000000..5668979087411d
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@kbn/core-elasticsearch-client-server-mocks",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./target_node/index.js",
+ "license": "SSPL-1.0 OR Elastic License 2.0"
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/index.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/index.ts
new file mode 100644
index 00000000000000..41192f12c2f651
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/index.ts
@@ -0,0 +1,17 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+export { elasticsearchClientMock } from './mocks';
+export type {
+ ClientApiMockInstance,
+ ClusterClientMock,
+ ScopedClusterClientMock,
+ CustomClusterClientMock,
+ DeeplyMockedApi,
+ ElasticsearchClientMock,
+} from './mocks';
diff --git a/src/core/server/elasticsearch/client/mocks.test.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/mocks.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/mocks.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/mocks.test.ts
diff --git a/src/core/server/elasticsearch/client/mocks.ts b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/mocks.ts
similarity index 96%
rename from src/core/server/elasticsearch/client/mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/mocks.ts
index 2c34629f2fd575..be3fe6f839dcee 100644
--- a/src/core/server/elasticsearch/client/mocks.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/src/mocks.ts
@@ -6,12 +6,10 @@
* Side Public License, v 1.
*/
-import type { Client } from '@elastic/elasticsearch';
-import type { TransportResult, TransportRequestOptions } from '@elastic/elasticsearch';
+import type { Client, TransportResult, TransportRequestOptions } from '@elastic/elasticsearch';
import type { PublicKeys } from '@kbn/utility-types';
-import { ElasticsearchClient } from './types';
-import { ICustomClusterClient } from './cluster_client';
-import { PRODUCT_RESPONSE_HEADER } from '../supported_server_response_check';
+import type { ElasticsearchClient, ICustomClusterClient } from '@kbn/core-elasticsearch-server';
+import { PRODUCT_RESPONSE_HEADER } from '@kbn/core-elasticsearch-client-server-internal';
const omittedProps = [
'diagnostic',
diff --git a/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/tsconfig.json b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/tsconfig.json
new file mode 100644
index 00000000000000..39d3c7097814ac
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../../../../tsconfig.bazel.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "target_types",
+ "rootDir": "src",
+ "stripInternal": false,
+ "types": [
+ "jest",
+ "node"
+ ]
+ },
+ "include": [
+ "src/**/*"
+ ]
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/BUILD.bazel b/packages/core/elasticsearch/core-elasticsearch-server-internal/BUILD.bazel
new file mode 100644
index 00000000000000..1593da93f02341
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/BUILD.bazel
@@ -0,0 +1,132 @@
+load("@npm//@bazel/typescript:index.bzl", "ts_config")
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
+
+PKG_DIRNAME = "core-elasticsearch-server-internal"
+PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-server-internal"
+
+SOURCE_FILES = glob(
+ [
+ "src/**/*.ts",
+ ],
+ exclude = [
+ "**/*.test.*",
+ "**/*.stories.*",
+ ],
+)
+
+SRCS = SOURCE_FILES
+
+filegroup(
+ name = "srcs",
+ srcs = SRCS,
+)
+
+NPM_MODULE_EXTRA_FILES = [
+ "package.json",
+]
+
+RUNTIME_DEPS = [
+ "@npm//rxjs",
+ "@npm//semver",
+ "@npm//moment",
+ "@npm//@elastic/elasticsearch",
+ "//packages/kbn-std",
+ "//packages/kbn-i18n",
+ "//packages/kbn-crypto",
+ "//packages/kbn-config-schema",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal",
+ ### test dependencies
+ "//packages/kbn-config-mocks",
+ "//packages/core/logging/core-logging-server-mocks",
+ "//packages/core/analytics/core-analytics-server-mocks",
+ "//packages/core/execution-context/core-execution-context-server-mocks",
+ "//packages/core/http/core-http-server-mocks",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-mocks",
+ "//packages/core/config/core-config-server-internal",
+]
+
+TYPES_DEPS = [
+ "@npm//@types/node",
+ "@npm//@types/jest",
+ "@npm//rxjs",
+ "@npm//@types/semver",
+ "@npm//moment",
+ "@npm//@elastic/elasticsearch",
+ "//packages/kbn-utility-types:npm_module_types",
+ "//packages/kbn-std:npm_module_types",
+ "//packages/kbn-logging:npm_module_types",
+ "//packages/kbn-i18n:npm_module_types",
+ "//packages/kbn-crypto:npm_module_types",
+ "//packages/kbn-config-schema:npm_module_types",
+ "//packages/core/base/core-base-common:npm_module_types",
+ "//packages/core/base/core-base-server-internal:npm_module_types",
+ "//packages/core/analytics/core-analytics-server:npm_module_types",
+ "//packages/core/http/core-http-server:npm_module_types",
+ "//packages/core/http/core-http-server-internal:npm_module_types",
+ "//packages/core/execution-context/core-execution-context-server-internal:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-internal:npm_module_types",
+]
+
+jsts_transpiler(
+ name = "target_node",
+ srcs = SRCS,
+ build_pkg_name = package_name(),
+)
+
+ts_config(
+ name = "tsconfig",
+ src = "tsconfig.json",
+ deps = [
+ "//:tsconfig.base.json",
+ "//:tsconfig.bazel.json",
+ ],
+)
+
+ts_project(
+ name = "tsc_types",
+ args = ['--pretty'],
+ srcs = SRCS,
+ deps = TYPES_DEPS,
+ declaration = True,
+ declaration_map = True,
+ emit_declaration_only = True,
+ out_dir = "target_types",
+ root_dir = "src",
+ tsconfig = ":tsconfig",
+)
+
+js_library(
+ name = PKG_DIRNAME,
+ srcs = NPM_MODULE_EXTRA_FILES,
+ deps = RUNTIME_DEPS + [":target_node"],
+ package_name = PKG_REQUIRE_NAME,
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm(
+ name = "npm_module",
+ deps = [":" + PKG_DIRNAME],
+)
+
+filegroup(
+ name = "build",
+ srcs = [":npm_module"],
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm_types(
+ name = "npm_module_types",
+ srcs = SRCS,
+ deps = [":tsc_types"],
+ package_name = PKG_REQUIRE_NAME,
+ tsconfig = ":tsconfig",
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "build_types",
+ srcs = [":npm_module_types"],
+ visibility = ["//visibility:public"],
+)
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/README.md b/packages/core/elasticsearch/core-elasticsearch-server-internal/README.md
new file mode 100644
index 00000000000000..38df445ccf465f
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/README.md
@@ -0,0 +1,3 @@
+# @kbn/core-elasticsearch-server-internal
+
+This package contains the internal types and implementation for Core's server-side elasticsearch service.
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/jest.config.js b/packages/core/elasticsearch/core-elasticsearch-server-internal/jest.config.js
new file mode 100644
index 00000000000000..bf51a18cb31b72
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/jest.config.js
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+module.exports = {
+ preset: '@kbn/test/jest_node',
+ rootDir: '../../../..',
+ roots: ['/packages/core/elasticsearch/core-elasticsearch-server-internal'],
+};
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/package.json b/packages/core/elasticsearch/core-elasticsearch-server-internal/package.json
new file mode 100644
index 00000000000000..c4d93c383d4212
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@kbn/core-elasticsearch-server-internal",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./target_node/index.js",
+ "license": "SSPL-1.0 OR Elastic License 2.0"
+}
diff --git a/src/core/server/elasticsearch/default_headers.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.test.ts
similarity index 84%
rename from src/core/server/elasticsearch/default_headers.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.test.ts
index 58e6e222a3f2ba..862020ba77feac 100644
--- a/src/core/server/elasticsearch/default_headers.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.test.ts
@@ -6,7 +6,8 @@
* Side Public License, v 1.
*/
-import { getReservedHeaders, PRODUCT_ORIGIN_HEADER } from './default_headers';
+import { PRODUCT_ORIGIN_HEADER } from '@kbn/core-elasticsearch-client-server-internal';
+import { getReservedHeaders } from './default_headers';
describe('getReservedHeaders', () => {
it('returns the list of reserved headers contained in a list', () => {
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.ts
new file mode 100644
index 00000000000000..4c447d66fd57a6
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/default_headers.ts
@@ -0,0 +1,19 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import { RESERVED_HEADERS } from '@kbn/core-elasticsearch-client-server-internal';
+
+export const getReservedHeaders = (headerNames: string[]): string[] => {
+ const reservedHeaders = [];
+ for (const headerName of headerNames) {
+ if (RESERVED_HEADERS.includes(headerName.toLowerCase())) {
+ reservedHeaders.push(headerName);
+ }
+ }
+ return reservedHeaders;
+};
diff --git a/src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.test.mocks.ts
similarity index 100%
rename from src/core/server/elasticsearch/elasticsearch_config.test.mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.test.mocks.ts
diff --git a/src/core/server/elasticsearch/elasticsearch_config.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/elasticsearch_config.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.test.ts
diff --git a/src/core/server/elasticsearch/elasticsearch_config.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.ts
similarity index 98%
rename from src/core/server/elasticsearch/elasticsearch_config.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.ts
index 201f285d728741..8420d8d72346f2 100644
--- a/src/core/server/elasticsearch/elasticsearch_config.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_config.ts
@@ -12,7 +12,8 @@ import { i18n } from '@kbn/i18n';
import { Duration } from 'moment';
import { readFileSync } from 'fs';
import type { ServiceConfigDescriptor } from '@kbn/core-base-server-internal';
-import { ConfigDeprecationProvider } from '..';
+import type { ConfigDeprecationProvider } from '@kbn/config';
+import type { IElasticsearchConfig, ElasticsearchSslConfig } from '@kbn/core-elasticsearch-server';
import { getReservedHeaders } from './default_headers';
const hostURISchema = schema.uri({ scheme: ['http', 'https'] });
@@ -20,7 +21,6 @@ const hostURISchema = schema.uri({ scheme: ['http', 'https'] });
export const DEFAULT_API_VERSION = 'master';
export type ElasticsearchConfigType = TypeOf;
-type SslConfigSchema = ElasticsearchConfigType['ssl'];
/**
* Validation schema for elasticsearch service config. It can be reused when plugins allow users
@@ -270,9 +270,9 @@ export const config: ServiceConfigDescriptor = {
/**
* Wrapper of config schema.
- * @public
+ * @internal
*/
-export class ElasticsearchConfig {
+export class ElasticsearchConfig implements IElasticsearchConfig {
/**
* @internal
* Only valid in dev mode. Skip the valid connection check during startup. The connection check allows
@@ -381,10 +381,7 @@ export class ElasticsearchConfig {
* are required when `xpack.ssl.verification_mode` in Elasticsearch is set to
* either `certificate` or `full`.
*/
- public readonly ssl: Pick<
- SslConfigSchema,
- Exclude
- > & { certificateAuthorities?: string[] };
+ public readonly ssl: ElasticsearchSslConfig;
/**
* Header names and values to send to Elasticsearch with every request. These
diff --git a/src/core/server/elasticsearch/elasticsearch_route_handler_context.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_route_handler_context.ts
similarity index 82%
rename from src/core/server/elasticsearch/elasticsearch_route_handler_context.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_route_handler_context.ts
index e33cd854546fc8..0b4a1474a88e80 100644
--- a/src/core/server/elasticsearch/elasticsearch_route_handler_context.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_route_handler_context.ts
@@ -7,17 +7,12 @@
*/
import type { KibanaRequest } from '@kbn/core-http-server';
-import type { IScopedClusterClient } from './client';
+import type {
+ IScopedClusterClient,
+ ElasticsearchRequestHandlerContext,
+} from '@kbn/core-elasticsearch-server';
import type { InternalElasticsearchServiceStart } from './types';
-/**
- * Core's `elasticsearch` request handler context.
- * @public
- */
-export interface ElasticsearchRequestHandlerContext {
- client: IScopedClusterClient;
-}
-
/**
* The {@link UiSettingsRequestHandlerContext} implementation.
* @internal
diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.mocks.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.mocks.ts
similarity index 83%
rename from src/core/server/elasticsearch/elasticsearch_service.test.mocks.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.mocks.ts
index 0ac23c1b37cf6b..29b9a2cda3dfd5 100644
--- a/src/core/server/elasticsearch/elasticsearch_service.test.mocks.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.mocks.ts
@@ -7,7 +7,9 @@
*/
export const MockClusterClient = jest.fn();
-jest.mock('./client/cluster_client', () => ({ ClusterClient: MockClusterClient }));
+jest.mock('@kbn/core-elasticsearch-client-server-internal', () => ({
+ ClusterClient: MockClusterClient,
+}));
export const isScriptingEnabledMock = jest.fn();
jest.doMock('./is_scripting_enabled', () => ({
diff --git a/src/core/server/elasticsearch/elasticsearch_service.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.ts
similarity index 99%
rename from src/core/server/elasticsearch/elasticsearch_service.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.ts
index b40a157a4ca2fc..aaf7344fdc3b6d 100644
--- a/src/core/server/elasticsearch/elasticsearch_service.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.test.ts
@@ -16,9 +16,6 @@ jest.mock('./version_check/ensure_es_version', () => ({
pollEsNodesVersion: jest.fn(),
}));
-// Mocking the module to disable caching for tests
-jest.mock('../ui_settings/cache');
-
import { MockClusterClient, isScriptingEnabledMock } from './elasticsearch_service.test.mocks';
import type { NodesVersionCompatibility } from './version_check/ensure_es_version';
@@ -32,9 +29,9 @@ import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { analyticsServiceMock } from '@kbn/core-analytics-server-mocks';
import { executionContextServiceMock } from '@kbn/core-execution-context-server-mocks';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { configSchema, ElasticsearchConfig } from './elasticsearch_config';
import { ElasticsearchService, SetupDeps } from './elasticsearch_service';
-import { elasticsearchClientMock } from './client/mocks';
import { duration } from 'moment';
import { isValidConnection as isValidConnectionMock } from './is_valid_connection';
import { pollEsNodesVersion as pollEsNodesVersionMocked } from './version_check/ensure_es_version';
diff --git a/src/core/server/elasticsearch/elasticsearch_service.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.ts
similarity index 97%
rename from src/core/server/elasticsearch/elasticsearch_service.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.ts
index a60069d644ca28..8e7ab46b0edd45 100644
--- a/src/core/server/elasticsearch/elasticsearch_service.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/elasticsearch_service.ts
@@ -18,9 +18,13 @@ import type {
} from '@kbn/core-execution-context-server-internal';
import type { IAuthHeadersStorage } from '@kbn/core-http-server';
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
+import type {
+ UnauthorizedErrorHandler,
+ ElasticsearchClientConfig,
+} from '@kbn/core-elasticsearch-server';
+import { ClusterClient } from '@kbn/core-elasticsearch-client-server-internal';
import { registerAnalyticsContextProvider } from './register_analytics_context_provider';
-import { ClusterClient, ElasticsearchClientConfig } from './client';
import { ElasticsearchConfig, ElasticsearchConfigType } from './elasticsearch_config';
import {
InternalElasticsearchServicePreboot,
@@ -32,7 +36,6 @@ import { pollEsNodesVersion } from './version_check/ensure_es_version';
import { calculateStatus$ } from './status';
import { isValidConnection } from './is_valid_connection';
import { isInlineScriptingEnabled } from './is_scripting_enabled';
-import type { UnauthorizedErrorHandler } from './client/retry_unauthorized';
import { mergeConfig } from './merge_config';
import { getClusterInfo$ } from './get_cluster_info';
diff --git a/src/core/server/elasticsearch/get_cluster_info.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.test.ts
similarity index 96%
rename from src/core/server/elasticsearch/get_cluster_info.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.test.ts
index fd3b3b71844acf..100fac8e1197b2 100644
--- a/src/core/server/elasticsearch/get_cluster_info.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.test.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import { elasticsearchClientMock } from './client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { firstValueFrom } from 'rxjs';
import { getClusterInfo$ } from './get_cluster_info';
diff --git a/src/core/server/elasticsearch/get_cluster_info.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.ts
similarity index 93%
rename from src/core/server/elasticsearch/get_cluster_info.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.ts
index c807965d3bbf8a..96ef87430048c0 100644
--- a/src/core/server/elasticsearch/get_cluster_info.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/get_cluster_info.ts
@@ -8,7 +8,7 @@
import type { Observable } from 'rxjs';
import { defer, map, retry, shareReplay } from 'rxjs';
-import type { ElasticsearchClient } from './client';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
/** @private */
export interface ClusterInfo {
diff --git a/src/core/server/elasticsearch/index.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/index.ts
similarity index 51%
rename from src/core/server/elasticsearch/index.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/index.ts
index b23b12ffe392c2..2554f225a58abe 100644
--- a/src/core/server/elasticsearch/index.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/index.ts
@@ -7,45 +7,25 @@
*/
export { ElasticsearchService } from './elasticsearch_service';
-export { config, configSchema } from './elasticsearch_config';
-export { ElasticsearchConfig } from './elasticsearch_config';
+export { config, configSchema, ElasticsearchConfig } from './elasticsearch_config';
+export type { ElasticsearchConfigType } from './elasticsearch_config';
export type {
NodesVersionCompatibility,
PollEsNodesVersionOptions,
+ NodesInfo,
+ NodeInfo,
} from './version_check/ensure_es_version';
export type {
- ElasticsearchServicePreboot,
- ElasticsearchServiceSetup,
- ElasticsearchServiceStart,
ElasticsearchStatusMeta,
InternalElasticsearchServicePreboot,
InternalElasticsearchServiceSetup,
InternalElasticsearchServiceStart,
- FakeRequest,
- ScopeableRequest,
- ElasticsearchConfigPreboot,
} from './types';
-export type {
- IClusterClient,
- ICustomClusterClient,
- ElasticsearchClientConfig,
- ElasticsearchClient,
- IScopedClusterClient,
- // unauthorized error handler
- UnauthorizedErrorHandlerOptions,
- UnauthorizedErrorHandlerResultRetryParams,
- UnauthorizedErrorHandlerRetryResult,
- UnauthorizedErrorHandlerNotHandledResult,
- UnauthorizedErrorHandlerResult,
- UnauthorizedErrorHandlerToolkit,
- UnauthorizedErrorHandler,
-} from './client';
-export { getRequestDebugMeta, getErrorMessage } from './client';
export { pollEsNodesVersion } from './version_check/ensure_es_version';
export {
isSupportedEsServer,
isNotFoundFromUnsupportedServer,
- PRODUCT_RESPONSE_HEADER,
} from './supported_server_response_check';
export { CoreElasticsearchRouteHandlerContext } from './elasticsearch_route_handler_context';
-export type { ElasticsearchRequestHandlerContext } from './elasticsearch_route_handler_context';
+export { retryCallCluster, migrationRetryCallCluster } from './retry_call_cluster';
+export { isInlineScriptingEnabled } from './is_scripting_enabled';
diff --git a/src/core/server/elasticsearch/is_scripting_enabled.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts
similarity index 91%
rename from src/core/server/elasticsearch/is_scripting_enabled.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts
index 797ff8972b7bee..d2922c0161c6f7 100644
--- a/src/core/server/elasticsearch/is_scripting_enabled.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts
@@ -7,14 +7,14 @@
*/
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-import { elasticsearchServiceMock } from './elasticsearch_service.mock';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { isInlineScriptingEnabled } from './is_scripting_enabled';
describe('isInlineScriptingEnabled', () => {
- let client: ReturnType;
+ let client: ReturnType;
beforeEach(() => {
- client = elasticsearchServiceMock.createElasticsearchClient();
+ client = elasticsearchClientMock.createElasticsearchClient();
});
const mockSettingsValue = (settings: estypes.ClusterGetSettingsResponse) => {
diff --git a/src/core/server/elasticsearch/is_scripting_enabled.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.ts
similarity index 93%
rename from src/core/server/elasticsearch/is_scripting_enabled.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.ts
index 13685362c11caf..6a3900229c0d46 100644
--- a/src/core/server/elasticsearch/is_scripting_enabled.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import { ElasticsearchClient } from './client';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
const scriptAllowedTypesKey = 'script.allowed_types';
diff --git a/src/core/server/elasticsearch/is_valid_connection.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_valid_connection.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/is_valid_connection.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_valid_connection.test.ts
diff --git a/src/core/server/elasticsearch/is_valid_connection.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_valid_connection.ts
similarity index 100%
rename from src/core/server/elasticsearch/is_valid_connection.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_valid_connection.ts
diff --git a/src/core/server/elasticsearch/merge_config.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.test.ts
similarity index 97%
rename from src/core/server/elasticsearch/merge_config.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.test.ts
index c89a7594352847..02317546a9dbcd 100644
--- a/src/core/server/elasticsearch/merge_config.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.test.ts
@@ -6,8 +6,8 @@
* Side Public License, v 1.
*/
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
import { mergeConfig } from './merge_config';
-import type { ElasticsearchClientConfig } from './client';
import { configSchema, ElasticsearchConfig } from './elasticsearch_config';
const partialToConfig = (parts: Partial): ElasticsearchClientConfig => {
diff --git a/src/core/server/elasticsearch/merge_config.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.ts
similarity index 93%
rename from src/core/server/elasticsearch/merge_config.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.ts
index 373bf6fc6cbe0a..9bb06670a09a9b 100644
--- a/src/core/server/elasticsearch/merge_config.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/merge_config.ts
@@ -8,7 +8,7 @@
import { merge } from '@kbn/std';
import { Writable } from '@kbn/utility-types';
-import type { ElasticsearchClientConfig } from './client';
+import type { ElasticsearchClientConfig } from '@kbn/core-elasticsearch-server';
type WritableConfig = Writable;
diff --git a/src/core/server/elasticsearch/register_analytics_context_provider.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/register_analytics_context_provider.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/register_analytics_context_provider.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/register_analytics_context_provider.test.ts
diff --git a/src/core/server/elasticsearch/register_analytics_context_provider.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/register_analytics_context_provider.ts
similarity index 100%
rename from src/core/server/elasticsearch/register_analytics_context_provider.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/register_analytics_context_provider.ts
diff --git a/src/core/server/elasticsearch/client/retry_call_cluster.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/retry_call_cluster.test.ts
similarity index 99%
rename from src/core/server/elasticsearch/client/retry_call_cluster.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/retry_call_cluster.test.ts
index aacb683197882d..78bb907c5cc483 100644
--- a/src/core/server/elasticsearch/client/retry_call_cluster.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/retry_call_cluster.test.ts
@@ -8,7 +8,7 @@
import { errors } from '@elastic/elasticsearch';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
-import { elasticsearchClientMock } from './mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { retryCallCluster, migrationRetryCallCluster } from './retry_call_cluster';
const dummyBody: any = { foo: 'bar' };
diff --git a/src/core/server/elasticsearch/client/retry_call_cluster.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/retry_call_cluster.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/retry_call_cluster.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/retry_call_cluster.ts
diff --git a/src/core/server/elasticsearch/status.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.test.ts
similarity index 96%
rename from src/core/server/elasticsearch/status.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.test.ts
index c1f7cf0e358928..f6aec43e680c40 100644
--- a/src/core/server/elasticsearch/status.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.test.ts
@@ -9,11 +9,15 @@
import { take } from 'rxjs/operators';
import { Subject, of } from 'rxjs';
+import { ServiceStatusLevels, ServiceStatusLevel, ServiceStatus } from '@kbn/core-base-common';
import { calculateStatus$ } from './status';
-import { ServiceStatusLevels, ServiceStatus } from '../status';
-import { ServiceStatusLevelSnapshotSerializer } from '../status/test_utils';
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
+const ServiceStatusLevelSnapshotSerializer: jest.SnapshotSerializerPlugin = {
+ test: (val: any) => Object.values(ServiceStatusLevels).includes(val),
+ serialize: (val: ServiceStatusLevel) => val.toString(),
+};
+
expect.addSnapshotSerializer(ServiceStatusLevelSnapshotSerializer);
const nodeInfo = {
diff --git a/src/core/server/elasticsearch/status.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.ts
similarity index 96%
rename from src/core/server/elasticsearch/status.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.ts
index 23e44b71863f18..5a38f11432b7bf 100644
--- a/src/core/server/elasticsearch/status.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/status.ts
@@ -8,8 +8,7 @@
import { Observable, merge, of } from 'rxjs';
import { map } from 'rxjs/operators';
-
-import { ServiceStatus, ServiceStatusLevels } from '../status';
+import { ServiceStatus, ServiceStatusLevels } from '@kbn/core-base-common';
import { ElasticsearchStatusMeta } from './types';
import { NodesVersionCompatibility } from './version_check/ensure_es_version';
diff --git a/src/core/server/elasticsearch/supported_server_response_check.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/supported_server_response_check.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/supported_server_response_check.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/supported_server_response_check.test.ts
diff --git a/src/core/server/elasticsearch/supported_server_response_check.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/supported_server_response_check.ts
similarity index 94%
rename from src/core/server/elasticsearch/supported_server_response_check.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/supported_server_response_check.ts
index 91aa06e132de8b..43f3f4ca92ce86 100644
--- a/src/core/server/elasticsearch/supported_server_response_check.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/supported_server_response_check.ts
@@ -5,7 +5,9 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
-export const PRODUCT_RESPONSE_HEADER = 'x-elastic-product';
+
+import { PRODUCT_RESPONSE_HEADER } from '@kbn/core-elasticsearch-client-server-internal';
+
/**
* Response headers check to determine if the response is from Elasticsearch
* @param headers Response headers
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/src/types.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/types.ts
new file mode 100644
index 00000000000000..57f3620a7911d0
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/types.ts
@@ -0,0 +1,39 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { Observable } from 'rxjs';
+import type {
+ ElasticsearchServicePreboot,
+ ElasticsearchServiceStart,
+ ElasticsearchServiceSetup,
+} from '@kbn/core-elasticsearch-server';
+import type { ServiceStatus } from '@kbn/core-base-common';
+import type { NodesVersionCompatibility, NodeInfo } from './version_check/ensure_es_version';
+import type { ClusterInfo } from './get_cluster_info';
+
+/** @internal */
+export type InternalElasticsearchServicePreboot = ElasticsearchServicePreboot;
+
+/** @internal */
+export interface InternalElasticsearchServiceSetup extends ElasticsearchServiceSetup {
+ clusterInfo$: Observable;
+ esNodesCompatibility$: Observable;
+ status$: Observable>;
+}
+
+/**
+ * @internal
+ */
+export type InternalElasticsearchServiceStart = ElasticsearchServiceStart;
+
+/** @internal */
+export interface ElasticsearchStatusMeta {
+ warningNodes: NodeInfo[];
+ incompatibleNodes: NodeInfo[];
+ nodesInfoRequestError?: Error;
+}
diff --git a/src/core/server/elasticsearch/version_check/ensure_es_version.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.test.ts
similarity index 99%
rename from src/core/server/elasticsearch/version_check/ensure_es_version.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.test.ts
index 49b8517f8c23e1..dccb2722309c43 100644
--- a/src/core/server/elasticsearch/version_check/ensure_es_version.test.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.test.ts
@@ -8,7 +8,7 @@
import { mapNodesVersionCompatibility, pollEsNodesVersion, NodesInfo } from './ensure_es_version';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
-import { elasticsearchClientMock } from '../client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { take, delay } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { of } from 'rxjs';
diff --git a/src/core/server/elasticsearch/version_check/ensure_es_version.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.ts
similarity index 98%
rename from src/core/server/elasticsearch/version_check/ensure_es_version.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.ts
index 7ef52dec337327..caa2dd372b8f35 100644
--- a/src/core/server/elasticsearch/version_check/ensure_es_version.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/ensure_es_version.ts
@@ -14,11 +14,11 @@
import { timer, of, from, Observable } from 'rxjs';
import { map, distinctUntilChanged, catchError, exhaustMap } from 'rxjs/operators';
import type { Logger } from '@kbn/logging';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
esVersionCompatibleWithKibana,
esVersionEqualsKibana,
} from './es_kibana_version_compatability';
-import type { ElasticsearchClient } from '../client';
/** @public */
export interface PollEsNodesVersionOptions {
@@ -29,7 +29,8 @@ export interface PollEsNodesVersionOptions {
esVersionCheckInterval: number;
}
-interface NodeInfo {
+/** @public */
+export interface NodeInfo {
version: string;
ip: string;
http?: {
diff --git a/src/core/server/elasticsearch/version_check/es_kibana_version_compatability.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/es_kibana_version_compatability.test.ts
similarity index 100%
rename from src/core/server/elasticsearch/version_check/es_kibana_version_compatability.test.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/es_kibana_version_compatability.test.ts
diff --git a/src/core/server/elasticsearch/version_check/es_kibana_version_compatability.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/es_kibana_version_compatability.ts
similarity index 100%
rename from src/core/server/elasticsearch/version_check/es_kibana_version_compatability.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-internal/src/version_check/es_kibana_version_compatability.ts
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/tsconfig.json b/packages/core/elasticsearch/core-elasticsearch-server-internal/tsconfig.json
new file mode 100644
index 00000000000000..39d3c7097814ac
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../../../../tsconfig.bazel.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "target_types",
+ "rootDir": "src",
+ "stripInternal": false,
+ "types": [
+ "jest",
+ "node"
+ ]
+ },
+ "include": [
+ "src/**/*"
+ ]
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/BUILD.bazel b/packages/core/elasticsearch/core-elasticsearch-server-mocks/BUILD.bazel
new file mode 100644
index 00000000000000..5b5f11738a10a8
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/BUILD.bazel
@@ -0,0 +1,105 @@
+load("@npm//@bazel/typescript:index.bzl", "ts_config")
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
+
+PKG_DIRNAME = "core-elasticsearch-server-mocks"
+PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-server-mocks"
+
+SOURCE_FILES = glob(
+ [
+ "src/**/*.ts",
+ ],
+ exclude = [
+ "**/*.test.*",
+ "**/*.stories.*",
+ ],
+)
+
+SRCS = SOURCE_FILES
+
+filegroup(
+ name = "srcs",
+ srcs = SRCS,
+)
+
+NPM_MODULE_EXTRA_FILES = [
+ "package.json",
+]
+
+RUNTIME_DEPS = [
+ "@npm//rxjs",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-mocks",
+]
+
+TYPES_DEPS = [
+ "@npm//@types/node",
+ "@npm//@types/jest",
+ "@npm//rxjs",
+ "//packages/kbn-utility-types:npm_module_types",
+ "//packages/core/base/core-base-common:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-client-server-mocks:npm_module_types",
+ "//packages/core/elasticsearch/core-elasticsearch-server-internal:npm_module_types",
+]
+
+jsts_transpiler(
+ name = "target_node",
+ srcs = SRCS,
+ build_pkg_name = package_name(),
+)
+
+ts_config(
+ name = "tsconfig",
+ src = "tsconfig.json",
+ deps = [
+ "//:tsconfig.base.json",
+ "//:tsconfig.bazel.json",
+ ],
+)
+
+ts_project(
+ name = "tsc_types",
+ args = ['--pretty'],
+ srcs = SRCS,
+ deps = TYPES_DEPS,
+ declaration = True,
+ declaration_map = True,
+ emit_declaration_only = True,
+ out_dir = "target_types",
+ root_dir = "src",
+ tsconfig = ":tsconfig",
+)
+
+js_library(
+ name = PKG_DIRNAME,
+ srcs = NPM_MODULE_EXTRA_FILES,
+ deps = RUNTIME_DEPS + [":target_node"],
+ package_name = PKG_REQUIRE_NAME,
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm(
+ name = "npm_module",
+ deps = [":" + PKG_DIRNAME],
+)
+
+filegroup(
+ name = "build",
+ srcs = [":npm_module"],
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm_types(
+ name = "npm_module_types",
+ srcs = SRCS,
+ deps = [":tsc_types"],
+ package_name = PKG_REQUIRE_NAME,
+ tsconfig = ":tsconfig",
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "build_types",
+ srcs = [":npm_module_types"],
+ visibility = ["//visibility:public"],
+)
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/README.md b/packages/core/elasticsearch/core-elasticsearch-server-mocks/README.md
new file mode 100644
index 00000000000000..afc49df686dce3
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/README.md
@@ -0,0 +1,3 @@
+# @kbn/core-elasticsearch-server-mocks
+
+This package contains the mocks for Core's server-side elasticsearch service.
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/jest.config.js b/packages/core/elasticsearch/core-elasticsearch-server-mocks/jest.config.js
new file mode 100644
index 00000000000000..297bfd70ae34ad
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/jest.config.js
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+module.exports = {
+ preset: '@kbn/test/jest_node',
+ rootDir: '../../../..',
+ roots: ['/packages/core/elasticsearch/core-elasticsearch-server-mocks'],
+};
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/package.json b/packages/core/elasticsearch/core-elasticsearch-server-mocks/package.json
new file mode 100644
index 00000000000000..4455a10b79d205
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@kbn/core-elasticsearch-server-mocks",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./target_node/index.js",
+ "license": "SSPL-1.0 OR Elastic License 2.0"
+}
diff --git a/src/core/server/elasticsearch/elasticsearch_service.mock.ts b/packages/core/elasticsearch/core-elasticsearch-server-mocks/src/elasticsearch_service.mock.ts
similarity index 89%
rename from src/core/server/elasticsearch/elasticsearch_service.mock.ts
rename to packages/core/elasticsearch/core-elasticsearch-server-mocks/src/elasticsearch_service.mock.ts
index 02a846a5b8011c..aebf2c290ea576 100644
--- a/src/core/server/elasticsearch/elasticsearch_service.mock.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/src/elasticsearch_service.mock.ts
@@ -11,21 +11,23 @@ import type { PublicMethodsOf } from '@kbn/utility-types';
import {
elasticsearchClientMock,
- ClusterClientMock,
- CustomClusterClientMock,
-} from './client/mocks';
-import { ElasticsearchClientConfig } from './client';
-import { ElasticsearchConfig } from './elasticsearch_config';
-import { ElasticsearchService } from './elasticsearch_service';
-import {
- InternalElasticsearchServiceSetup,
+ type ClusterClientMock,
+ type CustomClusterClientMock,
+} from '@kbn/core-elasticsearch-client-server-mocks';
+import type {
+ ElasticsearchClientConfig,
ElasticsearchServiceSetup,
- ElasticsearchStatusMeta,
ElasticsearchServicePreboot,
-} from './types';
-import { NodesVersionCompatibility } from './version_check/ensure_es_version';
-import { ServiceStatus, ServiceStatusLevels } from '../status';
-import type { ClusterInfo } from './get_cluster_info';
+} from '@kbn/core-elasticsearch-server';
+import type {
+ ElasticsearchConfig,
+ ElasticsearchService,
+ InternalElasticsearchServiceSetup,
+ ElasticsearchStatusMeta,
+ NodesVersionCompatibility,
+ ClusterInfo,
+} from '@kbn/core-elasticsearch-server-internal';
+import { type ServiceStatus, ServiceStatusLevels } from '@kbn/core-base-common';
type MockedElasticSearchServicePreboot = jest.Mocked;
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/src/index.ts b/packages/core/elasticsearch/core-elasticsearch-server-mocks/src/index.ts
new file mode 100644
index 00000000000000..0c58017fdc4291
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/src/index.ts
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+export { elasticsearchServiceMock } from './elasticsearch_service.mock';
+export type {
+ MockedElasticSearchServiceSetup,
+ MockedElasticSearchServiceStart,
+} from './elasticsearch_service.mock';
diff --git a/packages/core/elasticsearch/core-elasticsearch-server-mocks/tsconfig.json b/packages/core/elasticsearch/core-elasticsearch-server-mocks/tsconfig.json
new file mode 100644
index 00000000000000..39d3c7097814ac
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server-mocks/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../../../../tsconfig.bazel.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "target_types",
+ "rootDir": "src",
+ "stripInternal": false,
+ "types": [
+ "jest",
+ "node"
+ ]
+ },
+ "include": [
+ "src/**/*"
+ ]
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/BUILD.bazel b/packages/core/elasticsearch/core-elasticsearch-server/BUILD.bazel
new file mode 100644
index 00000000000000..c097ff5b33fd26
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/BUILD.bazel
@@ -0,0 +1,102 @@
+load("@npm//@bazel/typescript:index.bzl", "ts_config")
+load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
+load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
+
+PKG_DIRNAME = "core-elasticsearch-server"
+PKG_REQUIRE_NAME = "@kbn/core-elasticsearch-server"
+
+SOURCE_FILES = glob(
+ [
+ "src/**/*.ts",
+ ],
+ exclude = [
+ "**/*.test.*",
+ "**/*.stories.*",
+ ],
+)
+
+SRCS = SOURCE_FILES
+
+filegroup(
+ name = "srcs",
+ srcs = SRCS,
+)
+
+NPM_MODULE_EXTRA_FILES = [
+ "package.json",
+]
+
+RUNTIME_DEPS = [
+]
+
+TYPES_DEPS = [
+ "@npm//@types/node",
+ "@npm//@types/jest",
+ "@npm//moment",
+ "@npm//@elastic/elasticsearch",
+ "//packages/kbn-utility-types:npm_module_types",
+ "//packages/kbn-es-errors:npm_module_types",
+ "//packages/core/http/core-http-server:npm_module_types",
+]
+
+jsts_transpiler(
+ name = "target_node",
+ srcs = SRCS,
+ build_pkg_name = package_name(),
+)
+
+ts_config(
+ name = "tsconfig",
+ src = "tsconfig.json",
+ deps = [
+ "//:tsconfig.base.json",
+ "//:tsconfig.bazel.json",
+ ],
+)
+
+ts_project(
+ name = "tsc_types",
+ args = ['--pretty'],
+ srcs = SRCS,
+ deps = TYPES_DEPS,
+ declaration = True,
+ declaration_map = True,
+ emit_declaration_only = True,
+ out_dir = "target_types",
+ root_dir = "src",
+ tsconfig = ":tsconfig",
+)
+
+js_library(
+ name = PKG_DIRNAME,
+ srcs = NPM_MODULE_EXTRA_FILES,
+ deps = RUNTIME_DEPS + [":target_node"],
+ package_name = PKG_REQUIRE_NAME,
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm(
+ name = "npm_module",
+ deps = [":" + PKG_DIRNAME],
+)
+
+filegroup(
+ name = "build",
+ srcs = [":npm_module"],
+ visibility = ["//visibility:public"],
+)
+
+pkg_npm_types(
+ name = "npm_module_types",
+ srcs = SRCS,
+ deps = [":tsc_types"],
+ package_name = PKG_REQUIRE_NAME,
+ tsconfig = ":tsconfig",
+ visibility = ["//visibility:public"],
+)
+
+filegroup(
+ name = "build_types",
+ srcs = [":npm_module_types"],
+ visibility = ["//visibility:public"],
+)
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/README.md b/packages/core/elasticsearch/core-elasticsearch-server/README.md
new file mode 100644
index 00000000000000..3bcfd22475d342
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/README.md
@@ -0,0 +1,3 @@
+# @kbn/core-elasticsearch-server
+
+This package contains the public type for Core's server-side `elasticsearch` domain.
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/jest.config.js b/packages/core/elasticsearch/core-elasticsearch-server/jest.config.js
new file mode 100644
index 00000000000000..e3bdaf67022ce3
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/jest.config.js
@@ -0,0 +1,13 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+module.exports = {
+ preset: '@kbn/test/jest_node',
+ rootDir: '../../../..',
+ roots: ['/packages/core/elasticsearch/core-elasticsearch-server'],
+};
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/package.json b/packages/core/elasticsearch/core-elasticsearch-server/package.json
new file mode 100644
index 00000000000000..87a6b652dbd445
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@kbn/core-elasticsearch-server",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./target_node/index.js",
+ "license": "SSPL-1.0 OR Elastic License 2.0"
+}
diff --git a/src/core/server/elasticsearch/client/types.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/client.ts
similarity index 100%
rename from src/core/server/elasticsearch/client/types.ts
rename to packages/core/elasticsearch/core-elasticsearch-server/src/client/client.ts
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/client/client_config.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/client_config.ts
new file mode 100644
index 00000000000000..8c8fa6343e5465
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/client_config.ts
@@ -0,0 +1,45 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { Duration } from 'moment';
+
+/**
+ * Configuration options to be used to create a {@link IClusterClient | cluster client}
+ *
+ * @public
+ */
+export interface ElasticsearchClientConfig {
+ customHeaders: Record;
+ requestHeadersWhitelist: string[];
+ maxSockets: number;
+ compression: boolean;
+ sniffOnStart: boolean;
+ sniffOnConnectionFault: boolean;
+ sniffInterval: false | Duration;
+ username?: string;
+ password?: string;
+ serviceAccountToken?: string;
+ hosts: string[];
+ keepAlive?: boolean;
+ pingTimeout?: Duration | number;
+ requestTimeout?: Duration | number;
+ caFingerprint?: string;
+ ssl?: ElasticsearchClientSslConfig;
+}
+
+/**
+ * @public
+ */
+export interface ElasticsearchClientSslConfig {
+ verificationMode?: 'none' | 'certificate' | 'full';
+ certificate?: string;
+ certificateAuthorities?: string[];
+ key?: string;
+ keyPassphrase?: string;
+ alwaysPresentCertificate?: boolean;
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/client/cluster_client.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/cluster_client.ts
new file mode 100644
index 00000000000000..57eadf70ef68a6
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/cluster_client.ts
@@ -0,0 +1,42 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { ElasticsearchClient } from './client';
+import { ScopeableRequest } from './scopeable_request';
+import { IScopedClusterClient } from './scoped_cluster_client';
+
+/**
+ * Represents an Elasticsearch cluster API client created by the platform.
+ * It allows to call API on behalf of the internal Kibana user and
+ * the actual user that is derived from the request headers (via `asScoped(...)`).
+ *
+ * @public
+ **/
+export interface IClusterClient {
+ /**
+ * A {@link ElasticsearchClient | client} to be used to query the ES cluster on behalf of the Kibana internal user
+ */
+ readonly asInternalUser: ElasticsearchClient;
+ /**
+ * Creates a {@link IScopedClusterClient | scoped cluster client} bound to given {@link ScopeableRequest | request}
+ */
+ asScoped: (request: ScopeableRequest) => IScopedClusterClient;
+}
+
+/**
+ * See {@link IClusterClient}
+ *
+ * @public
+ */
+export interface ICustomClusterClient extends IClusterClient {
+ /**
+ * Closes the cluster client. After that client cannot be used and one should
+ * create a new client instance to be able to interact with Elasticsearch API.
+ */
+ close: () => Promise;
+}
diff --git a/src/core/server/elasticsearch/client/index.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/index.ts
similarity index 61%
rename from src/core/server/elasticsearch/client/index.ts
rename to packages/core/elasticsearch/core-elasticsearch-server/src/client/index.ts
index b1630ec25c9ff3..377d8365089891 100644
--- a/src/core/server/elasticsearch/client/index.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/index.ts
@@ -6,21 +6,17 @@
* Side Public License, v 1.
*/
-export type { ElasticsearchClient } from './types';
-export { ScopedClusterClient } from './scoped_cluster_client';
-export type { IScopedClusterClient } from './scoped_cluster_client';
-export type { ElasticsearchClientConfig } from './client_config';
-export { ClusterClient } from './cluster_client';
+export type { ElasticsearchClient } from './client';
export type { IClusterClient, ICustomClusterClient } from './cluster_client';
-export { configureClient } from './configure_client';
-export { getRequestDebugMeta, getErrorMessage } from './log_query_and_deprecation';
-export { retryCallCluster, migrationRetryCallCluster } from './retry_call_cluster';
+export type { ScopeableRequest, FakeRequest } from './scopeable_request';
+export type { IScopedClusterClient } from './scoped_cluster_client';
export type {
+ UnauthorizedErrorHandler,
UnauthorizedErrorHandlerOptions,
+ UnauthorizedErrorHandlerResult,
UnauthorizedErrorHandlerResultRetryParams,
+ UnauthorizedErrorHandlerToolkit,
UnauthorizedErrorHandlerRetryResult,
UnauthorizedErrorHandlerNotHandledResult,
- UnauthorizedErrorHandlerResult,
- UnauthorizedErrorHandlerToolkit,
- UnauthorizedErrorHandler,
-} from './retry_unauthorized';
+} from './unauthorized_error_handler';
+export type { ElasticsearchClientConfig, ElasticsearchClientSslConfig } from './client_config';
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/client/scopeable_request.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/scopeable_request.ts
new file mode 100644
index 00000000000000..ab0eed169d5a8e
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/scopeable_request.ts
@@ -0,0 +1,27 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { Headers, KibanaRequest } from '@kbn/core-http-server';
+
+/**
+ * Fake request object created manually by Kibana plugins.
+ * @public
+ */
+export interface FakeRequest {
+ /** Headers used for authentication against Elasticsearch */
+ headers: Headers;
+}
+
+/**
+ A user credentials container.
+ * It accommodates the necessary auth credentials to impersonate the current user.
+ *
+ * @public
+ * See {@link KibanaRequest}.
+ */
+export type ScopeableRequest = KibanaRequest | FakeRequest;
diff --git a/src/core/server/elasticsearch/client/scoped_cluster_client.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/scoped_cluster_client.ts
similarity index 81%
rename from src/core/server/elasticsearch/client/scoped_cluster_client.ts
rename to packages/core/elasticsearch/core-elasticsearch-server/src/client/scoped_cluster_client.ts
index 9ef77e200b0edd..4e3f7b6924e7c2 100644
--- a/src/core/server/elasticsearch/client/scoped_cluster_client.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/scoped_cluster_client.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import { ElasticsearchClient } from './types';
+import { ElasticsearchClient } from './client';
/**
* Serves the same purpose as the normal {@link IClusterClient | cluster client} but exposes
@@ -28,11 +28,3 @@ export interface IScopedClusterClient {
*/
readonly asCurrentUser: ElasticsearchClient;
}
-
-/** @internal **/
-export class ScopedClusterClient implements IScopedClusterClient {
- constructor(
- public readonly asInternalUser: ElasticsearchClient,
- public readonly asCurrentUser: ElasticsearchClient
- ) {}
-}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/client/unauthorized_error_handler.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/client/unauthorized_error_handler.ts
new file mode 100644
index 00000000000000..3463e091a650c4
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/client/unauthorized_error_handler.ts
@@ -0,0 +1,73 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import { MaybePromise } from '@kbn/utility-types';
+import type { UnauthorizedError } from '@kbn/es-errors';
+import type { AuthHeaders, KibanaRequest } from '@kbn/core-http-server';
+
+/**
+ * @public
+ */
+export interface UnauthorizedErrorHandlerOptions {
+ error: UnauthorizedError;
+ request: KibanaRequest;
+}
+
+/**
+ * @public
+ */
+export interface UnauthorizedErrorHandlerResultRetryParams {
+ authHeaders: AuthHeaders;
+}
+
+/**
+ * @public
+ */
+export interface UnauthorizedErrorHandlerRetryResult
+ extends UnauthorizedErrorHandlerResultRetryParams {
+ type: 'retry';
+}
+
+/**
+ * @public
+ */
+export interface UnauthorizedErrorHandlerNotHandledResult {
+ type: 'notHandled';
+}
+
+/**
+ * @public
+ */
+export type UnauthorizedErrorHandlerResult =
+ | UnauthorizedErrorHandlerRetryResult
+ | UnauthorizedErrorHandlerNotHandledResult;
+
+/**
+ * Toolkit passed to a {@link UnauthorizedErrorHandler} used to generate responses from the handler
+ * @public
+ */
+export interface UnauthorizedErrorHandlerToolkit {
+ /**
+ * The handler cannot handle the error, or was not able to authenticate.
+ */
+ notHandled: () => UnauthorizedErrorHandlerNotHandledResult;
+ /**
+ * The handler was able to authenticate. Will retry the failed request with new auth headers
+ */
+ retry: (params: UnauthorizedErrorHandlerResultRetryParams) => UnauthorizedErrorHandlerRetryResult;
+}
+
+/**
+ * A handler used to handle unauthorized error returned by elasticsearch
+ *
+ * @public
+ */
+export type UnauthorizedErrorHandler = (
+ options: UnauthorizedErrorHandlerOptions,
+ toolkit: UnauthorizedErrorHandlerToolkit
+) => MaybePromise;
diff --git a/src/core/server/elasticsearch/types.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/contracts.ts
similarity index 72%
rename from src/core/server/elasticsearch/types.ts
rename to packages/core/elasticsearch/core-elasticsearch-server/src/contracts.ts
index 5caf4dabc4a5ae..39fed7cbd28036 100644
--- a/src/core/server/elasticsearch/types.ts
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/contracts.ts
@@ -7,13 +7,13 @@
*/
import { Observable } from 'rxjs';
-import type { Headers, KibanaRequest } from '@kbn/core-http-server';
-import { ElasticsearchConfig } from './elasticsearch_config';
-import { IClusterClient, ICustomClusterClient, ElasticsearchClientConfig } from './client';
-import { NodesVersionCompatibility } from './version_check/ensure_es_version';
-import { ServiceStatus } from '../status';
-import type { UnauthorizedErrorHandler } from './client/retry_unauthorized';
-import { ClusterInfo } from './get_cluster_info';
+import type {
+ IClusterClient,
+ ICustomClusterClient,
+ ElasticsearchClientConfig,
+ UnauthorizedErrorHandler,
+} from './client';
+import { IElasticsearchConfig } from './elasticsearch_config';
/**
* @public
@@ -88,20 +88,10 @@ export interface ElasticsearchServiceSetup {
*
* @deprecated Can be removed when https://github.com/elastic/kibana/issues/119862 is done.
*/
- readonly config$: Observable;
+ readonly config$: Observable;
};
}
-/** @internal */
-export type InternalElasticsearchServicePreboot = ElasticsearchServicePreboot;
-
-/** @internal */
-export interface InternalElasticsearchServiceSetup extends ElasticsearchServiceSetup {
- clusterInfo$: Observable;
- esNodesCompatibility$: Observable;
- status$: Observable>;
-}
-
/**
* @public
*/
@@ -138,36 +128,6 @@ export interface ElasticsearchServiceStart {
) => ICustomClusterClient;
}
-/**
- * @internal
- */
-export type InternalElasticsearchServiceStart = ElasticsearchServiceStart;
-
-/** @public */
-export interface ElasticsearchStatusMeta {
- warningNodes: NodesVersionCompatibility['warningNodes'];
- incompatibleNodes: NodesVersionCompatibility['incompatibleNodes'];
- nodesInfoRequestError?: NodesVersionCompatibility['nodesInfoRequestError'];
-}
-
-/**
- * Fake request object created manually by Kibana plugins.
- * @public
- */
-export interface FakeRequest {
- /** Headers used for authentication against Elasticsearch */
- headers: Headers;
-}
-
-/**
- A user credentials container.
- * It accommodates the necessary auth credentials to impersonate the current user.
- *
- * @public
- * See {@link KibanaRequest}.
- */
-export type ScopeableRequest = KibanaRequest | FakeRequest;
-
/**
* A limited set of Elasticsearch configuration entries exposed to the `preboot` plugins at `setup`.
*
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/elasticsearch_config.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/elasticsearch_config.ts
new file mode 100644
index 00000000000000..a0cd6a34cca899
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/elasticsearch_config.ts
@@ -0,0 +1,144 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { Duration } from 'moment';
+
+/**
+ * @public
+ */
+export interface IElasticsearchConfig {
+ /**
+ * The interval between health check requests Kibana sends to the Elasticsearch.
+ */
+ readonly healthCheckDelay: Duration;
+
+ /**
+ * Whether to allow kibana to connect to a non-compatible elasticsearch node.
+ */
+ readonly ignoreVersionMismatch: boolean;
+
+ /**
+ * Version of the Elasticsearch (6.7, 7.1 or `master`) client will be connecting to.
+ */
+ readonly apiVersion: string;
+
+ /**
+ * The maximum number of sockets that can be used for communications with elasticsearch.
+ */
+ readonly maxSockets: number;
+
+ /**
+ * Whether to use compression for communications with elasticsearch.
+ */
+ readonly compression: boolean;
+
+ /**
+ * Hosts that the client will connect to. If sniffing is enabled, this list will
+ * be used as seeds to discover the rest of your cluster.
+ */
+ readonly hosts: string[];
+
+ /**
+ * List of Kibana client-side headers to send to Elasticsearch when request
+ * scoped cluster client is used. If this is an empty array then *no* client-side
+ * will be sent.
+ */
+ readonly requestHeadersWhitelist: string[];
+
+ /**
+ * Timeout after which PING HTTP request will be aborted and retried.
+ */
+ readonly pingTimeout: Duration;
+
+ /**
+ * Timeout after which HTTP request will be aborted and retried.
+ */
+ readonly requestTimeout: Duration;
+
+ /**
+ * Timeout for Elasticsearch to wait for responses from shards. Set to 0 to disable.
+ */
+ readonly shardTimeout: Duration;
+
+ /**
+ * Specifies whether the client should attempt to detect the rest of the cluster
+ * when it is first instantiated.
+ */
+ readonly sniffOnStart: boolean;
+
+ /**
+ * Interval to perform a sniff operation and make sure the list of nodes is complete.
+ * If `false` then sniffing is disabled.
+ */
+ readonly sniffInterval: false | Duration;
+
+ /**
+ * Specifies whether the client should immediately sniff for a more current list
+ * of nodes when a connection dies.
+ */
+ readonly sniffOnConnectionFault: boolean;
+
+ /**
+ * If Elasticsearch is protected with basic authentication, this setting provides
+ * the username that the Kibana server uses to perform its administrative functions.
+ * Cannot be used in conjunction with serviceAccountToken.
+ */
+ readonly username?: string;
+
+ /**
+ * If Elasticsearch is protected with basic authentication, this setting provides
+ * the password that the Kibana server uses to perform its administrative functions.
+ */
+ readonly password?: string;
+
+ /**
+ * If Elasticsearch security features are enabled, this setting provides the service account
+ * token that the Kibana server users to perform its administrative functions.
+ *
+ * This is an alternative to specifying a username and password.
+ */
+ readonly serviceAccountToken?: string;
+
+ /**
+ * Header names and values to send to Elasticsearch with every request. These
+ * headers cannot be overwritten by client-side headers and aren't affected by
+ * `requestHeadersWhitelist` configuration.
+ */
+ readonly customHeaders: Record;
+
+ /**
+ * @internal
+ * Only valid in dev mode. Skip the valid connection check during startup. The connection check allows
+ * Kibana to ensure that the Elasticsearch connection is valid before allowing
+ * any other services to be set up.
+ *
+ * @remarks
+ * You should disable this check at your own risk: Other services in Kibana
+ * may fail if this step is not completed.
+ */
+ readonly skipStartupConnectionCheck: boolean;
+
+ /**
+ * Set of settings configure SSL connection between Kibana and Elasticsearch that
+ * are required when `xpack.ssl.verification_mode` in Elasticsearch is set to
+ * either `certificate` or `full`.
+ */
+ readonly ssl: ElasticsearchSslConfig;
+}
+
+/**
+ * @public
+ */
+export interface ElasticsearchSslConfig {
+ verificationMode: 'none' | 'certificate' | 'full';
+ certificate?: string;
+ certificateAuthorities?: string[];
+ key?: string;
+ keyPassphrase?: string;
+ alwaysPresentCertificate: boolean;
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/index.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/index.ts
new file mode 100644
index 00000000000000..ad418bc2f59404
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/index.ts
@@ -0,0 +1,34 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+export type {
+ ElasticsearchClient,
+ IScopedClusterClient,
+ IClusterClient,
+ ICustomClusterClient,
+ ScopeableRequest,
+ UnauthorizedErrorHandlerResult,
+ UnauthorizedErrorHandler,
+ UnauthorizedErrorHandlerRetryResult,
+ UnauthorizedErrorHandlerToolkit,
+ UnauthorizedErrorHandlerResultRetryParams,
+ UnauthorizedErrorHandlerNotHandledResult,
+ UnauthorizedErrorHandlerOptions,
+ FakeRequest,
+ ElasticsearchClientSslConfig,
+ ElasticsearchClientConfig,
+} from './client';
+
+export type {
+ ElasticsearchConfigPreboot,
+ ElasticsearchServicePreboot,
+ ElasticsearchServiceStart,
+ ElasticsearchServiceSetup,
+} from './contracts';
+export type { IElasticsearchConfig, ElasticsearchSslConfig } from './elasticsearch_config';
+export type { ElasticsearchRequestHandlerContext } from './request_handler_context';
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/src/request_handler_context.ts b/packages/core/elasticsearch/core-elasticsearch-server/src/request_handler_context.ts
new file mode 100644
index 00000000000000..af59db5c5d85b1
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/src/request_handler_context.ts
@@ -0,0 +1,17 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+import type { IScopedClusterClient } from './client';
+
+/**
+ * Core's `elasticsearch` request handler context.
+ * @public
+ */
+export interface ElasticsearchRequestHandlerContext {
+ client: IScopedClusterClient;
+}
diff --git a/packages/core/elasticsearch/core-elasticsearch-server/tsconfig.json b/packages/core/elasticsearch/core-elasticsearch-server/tsconfig.json
new file mode 100644
index 00000000000000..39d3c7097814ac
--- /dev/null
+++ b/packages/core/elasticsearch/core-elasticsearch-server/tsconfig.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../../../../tsconfig.bazel.json",
+ "compilerOptions": {
+ "declaration": true,
+ "declarationMap": true,
+ "emitDeclarationOnly": true,
+ "outDir": "target_types",
+ "rootDir": "src",
+ "stripInternal": false,
+ "types": [
+ "jest",
+ "node"
+ ]
+ },
+ "include": [
+ "src/**/*"
+ ]
+}
diff --git a/src/cli_setup/utils.ts b/src/cli_setup/utils.ts
index 6a5b60681a9f02..de047a0540db45 100644
--- a/src/cli_setup/utils.ts
+++ b/src/cli_setup/utils.ts
@@ -13,8 +13,8 @@ import { merge } from 'lodash';
import { kibanaPackageJson } from '@kbn/utils';
import { Logger } from '@kbn/core/server';
-import { ClusterClient } from '@kbn/core/server/elasticsearch/client';
-import { configSchema } from '@kbn/core/server/elasticsearch';
+import { ClusterClient } from '@kbn/core-elasticsearch-client-server-internal';
+import { configSchema } from '@kbn/core-elasticsearch-server-internal';
import { ElasticsearchService } from '@kbn/interactive-setup-plugin/server/elasticsearch_service';
import { KibanaConfigWriter } from '@kbn/interactive-setup-plugin/server/kibana_config_writer';
import type { EnrollmentToken } from '@kbn/interactive-setup-plugin/common';
diff --git a/src/core/server/core_route_handler_context.ts b/src/core/server/core_route_handler_context.ts
index ccdefc97f62931..3f4dfbcc8addeb 100644
--- a/src/core/server/core_route_handler_context.ts
+++ b/src/core/server/core_route_handler_context.ts
@@ -7,15 +7,13 @@
*/
import type { KibanaRequest } from '@kbn/core-http-server';
+import type { ElasticsearchRequestHandlerContext } from '@kbn/core-elasticsearch-server';
+import { CoreElasticsearchRouteHandlerContext } from '@kbn/core-elasticsearch-server-internal';
import type { InternalCoreStart } from './internal_types';
import {
CoreSavedObjectsRouteHandlerContext,
SavedObjectsRequestHandlerContext,
} from './saved_objects';
-import {
- CoreElasticsearchRouteHandlerContext,
- ElasticsearchRequestHandlerContext,
-} from './elasticsearch';
import { CoreUiSettingsRouteHandlerContext, UiSettingsRequestHandlerContext } from './ui_settings';
import {
CoreDeprecationsRouteHandlerContext,
diff --git a/src/core/server/core_usage_data/core_usage_data_service.test.ts b/src/core/server/core_usage_data/core_usage_data_service.test.ts
index c22f1d36673657..a9219ede9d6596 100644
--- a/src/core/server/core_usage_data/core_usage_data_service.test.ts
+++ b/src/core/server/core_usage_data/core_usage_data_service.test.ts
@@ -16,7 +16,7 @@ import { HotObservable } from 'rxjs/internal/testing/HotObservable';
import { configServiceMock } from '@kbn/config-mocks';
import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { config as RawLoggingConfig } from '@kbn/core-logging-server-internal';
-import { config as RawElasticsearchConfig } from '../elasticsearch/elasticsearch_config';
+import { config as RawElasticsearchConfig } from '@kbn/core-elasticsearch-server-internal';
import { config as RawHttpConfig } from '@kbn/core-http-server-internal';
import { savedObjectsConfig as RawSavedObjectsConfig } from '../saved_objects/saved_objects_config';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
@@ -24,7 +24,7 @@ import { metricsServiceMock } from '../metrics/metrics_service.mock';
import { savedObjectsServiceMock } from '../saved_objects/saved_objects_service.mock';
import { CoreUsageDataService } from './core_usage_data_service';
-import { elasticsearchServiceMock } from '../elasticsearch/elasticsearch_service.mock';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { typeRegistryMock } from '../saved_objects/saved_objects_type_registry.mock';
import { CORE_USAGE_STATS_TYPE } from './constants';
import { CoreUsageStatsClient } from './core_usage_stats_client';
diff --git a/src/core/server/core_usage_data/core_usage_data_service.ts b/src/core/server/core_usage_data/core_usage_data_service.ts
index f18dfe0dcd624d..10258ac004aa7b 100644
--- a/src/core/server/core_usage_data/core_usage_data_service.ts
+++ b/src/core/server/core_usage_data/core_usage_data_service.ts
@@ -20,8 +20,9 @@ import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import type { LoggingConfigType } from '@kbn/core-logging-server-internal';
import type { Logger } from '@kbn/logging';
import type { HttpConfigType, InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
+import type { ElasticsearchServiceStart } from '@kbn/core-elasticsearch-server';
+import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal';
import { SavedObjectsServiceStart, SavedObjectTypeRegistry } from '..';
-import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config';
import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config';
import type {
@@ -33,7 +34,6 @@ import type {
CoreConfigUsageData,
} from './types';
import { isConfigured } from './is_configured';
-import { ElasticsearchServiceStart } from '../elasticsearch';
import { coreUsageStatsType } from './core_usage_stats';
import { LEGACY_URL_ALIAS_TYPE } from '../saved_objects/object_types';
import { CORE_USAGE_STATS_TYPE } from './constants';
diff --git a/src/core/server/deprecations/deprecations_registry.mock.ts b/src/core/server/deprecations/deprecations_registry.mock.ts
index bb178c3935cdcf..65433f5eca5cba 100644
--- a/src/core/server/deprecations/deprecations_registry.mock.ts
+++ b/src/core/server/deprecations/deprecations_registry.mock.ts
@@ -7,10 +7,11 @@
*/
import type { PublicMethodsOf } from '@kbn/utility-types';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { DeprecationsRegistry } from './deprecations_registry';
import type { GetDeprecationsContext } from './types';
-import { elasticsearchClientMock } from '../elasticsearch/client/mocks';
import { savedObjectsClientMock } from '../saved_objects/service/saved_objects_client.mock';
+
type DeprecationsRegistryContract = PublicMethodsOf;
const createDeprecationsRegistryMock = () => {
diff --git a/src/core/server/deprecations/deprecations_route_handler_context.ts b/src/core/server/deprecations/deprecations_route_handler_context.ts
index 76e5d974056d46..bd19023a1ec782 100644
--- a/src/core/server/deprecations/deprecations_route_handler_context.ts
+++ b/src/core/server/deprecations/deprecations_route_handler_context.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import type { CoreElasticsearchRouteHandlerContext } from '../elasticsearch';
+import type { CoreElasticsearchRouteHandlerContext } from '@kbn/core-elasticsearch-server-internal';
import type { CoreSavedObjectsRouteHandlerContext } from '../saved_objects';
import type { DeprecationsClient, InternalDeprecationsServiceStart } from './deprecations_service';
diff --git a/src/core/server/deprecations/deprecations_service.ts b/src/core/server/deprecations/deprecations_service.ts
index 7b07b4c1d10dee..d9a8e14eb3b053 100644
--- a/src/core/server/deprecations/deprecations_service.ts
+++ b/src/core/server/deprecations/deprecations_service.ts
@@ -12,11 +12,11 @@ import type { IConfigService } from '@kbn/config';
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import { DomainDeprecationDetails } from '@kbn/core-deprecations-common';
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
+import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
import { DeprecationsFactory } from './deprecations_factory';
import { RegisterDeprecationsConfig } from './types';
import { registerRoutes } from './routes';
import { config as deprecationConfig, DeprecationConfigType } from './deprecation_config';
-import { IScopedClusterClient } from '../elasticsearch/client';
import { SavedObjectsClientContract } from '../saved_objects/types';
/**
diff --git a/src/core/server/deprecations/types.ts b/src/core/server/deprecations/types.ts
index 16104c6f9cc573..5cefb7b68dbe1f 100644
--- a/src/core/server/deprecations/types.ts
+++ b/src/core/server/deprecations/types.ts
@@ -8,8 +8,8 @@
import type { MaybePromise } from '@kbn/utility-types';
import type { DeprecationsDetails } from '@kbn/core-deprecations-common';
+import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsClientContract } from '../saved_objects/types';
-import type { IScopedClusterClient } from '../elasticsearch';
/**
* @public
diff --git a/src/core/server/elasticsearch/integration_tests/is_scripting_enabled.test.ts b/src/core/server/elasticsearch/integration_tests/is_scripting_enabled.test.ts
index 501193a833f271..353acbc70c18e8 100644
--- a/src/core/server/elasticsearch/integration_tests/is_scripting_enabled.test.ts
+++ b/src/core/server/elasticsearch/integration_tests/is_scripting_enabled.test.ts
@@ -11,7 +11,7 @@ import {
TestElasticsearchUtils,
TestKibanaUtils,
} from '../../../test_helpers/kbn_server';
-import { isInlineScriptingEnabled } from '../is_scripting_enabled';
+import { isInlineScriptingEnabled } from '@kbn/core-elasticsearch-server-internal';
describe('isInlineScriptingEnabled', () => {
let esServer: TestElasticsearchUtils;
diff --git a/src/core/server/http/integration_tests/core_services.test.ts b/src/core/server/http/integration_tests/core_services.test.ts
index 8bf0908ae4dc76..dbbc16105b070f 100644
--- a/src/core/server/http/integration_tests/core_services.test.ts
+++ b/src/core/server/http/integration_tests/core_services.test.ts
@@ -7,10 +7,10 @@
*/
import { MockElasticsearchClient } from './core_service.test.mocks';
-import { elasticsearchClientMock } from '../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { errors } from '@elastic/elasticsearch';
+import type { InternalElasticsearchServiceStart } from '@kbn/core-elasticsearch-server-internal';
import * as kbnTestServer from '../../../test_helpers/kbn_server';
-import { InternalElasticsearchServiceStart } from '../../elasticsearch';
const cookieOptions = {
name: 'sid',
diff --git a/src/core/server/index.ts b/src/core/server/index.ts
index 82d98f875241e7..c0e450ebde7650 100644
--- a/src/core/server/index.ts
+++ b/src/core/server/index.ts
@@ -52,12 +52,12 @@ import type {
HttpServiceStart,
} from '@kbn/core-http-server';
import type { PrebootServicePreboot } from '@kbn/core-preboot-server';
-import {
+import type {
ElasticsearchServiceSetup,
- configSchema as elasticsearchConfigSchema,
ElasticsearchServiceStart,
ElasticsearchServicePreboot,
-} from './elasticsearch';
+} from '@kbn/core-elasticsearch-server';
+import { configSchema as elasticsearchConfigSchema } from '@kbn/core-elasticsearch-server-internal';
import { HttpResources } from './http_resources';
import { PluginsServiceSetup, PluginsServiceStart, PluginOpaqueId } from './plugins';
@@ -115,22 +115,25 @@ export type {
export type { CoreId } from '@kbn/core-base-common-internal';
-export { ElasticsearchConfig, pollEsNodesVersion } from './elasticsearch';
+export { ElasticsearchConfig, pollEsNodesVersion } from '@kbn/core-elasticsearch-server-internal';
+export type {
+ NodesVersionCompatibility,
+ PollEsNodesVersionOptions,
+} from '@kbn/core-elasticsearch-server-internal';
export type {
ElasticsearchServicePreboot,
ElasticsearchServiceSetup,
ElasticsearchServiceStart,
- ElasticsearchStatusMeta,
- NodesVersionCompatibility,
+ ElasticsearchConfigPreboot,
+ ElasticsearchRequestHandlerContext,
FakeRequest,
ScopeableRequest,
ElasticsearchClient,
IClusterClient,
ICustomClusterClient,
ElasticsearchClientConfig,
+ ElasticsearchClientSslConfig,
IScopedClusterClient,
- ElasticsearchConfigPreboot,
- PollEsNodesVersionOptions,
UnauthorizedErrorHandlerOptions,
UnauthorizedErrorHandlerResultRetryParams,
UnauthorizedErrorHandlerRetryResult,
@@ -138,8 +141,7 @@ export type {
UnauthorizedErrorHandlerResult,
UnauthorizedErrorHandlerToolkit,
UnauthorizedErrorHandler,
- ElasticsearchRequestHandlerContext,
-} from './elasticsearch';
+} from '@kbn/core-elasticsearch-server';
export { CspConfig } from '@kbn/core-http-server-internal';
export { CoreKibanaRequest, kibanaResponseFactory } from '@kbn/core-http-router-server-internal';
diff --git a/src/core/server/internal_types.ts b/src/core/server/internal_types.ts
index ca02ad45eacf40..4338d55e7ac3d0 100644
--- a/src/core/server/internal_types.ts
+++ b/src/core/server/internal_types.ts
@@ -31,12 +31,12 @@ import type {
InternalHttpServiceSetup,
InternalHttpServiceStart,
} from '@kbn/core-http-server-internal';
-import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
-import {
+import type {
InternalElasticsearchServicePreboot,
InternalElasticsearchServiceSetup,
InternalElasticsearchServiceStart,
-} from './elasticsearch';
+} from '@kbn/core-elasticsearch-server-internal';
+import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import {
InternalSavedObjectsServiceSetup,
InternalSavedObjectsServiceStart,
diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts
index 9e693ac7600e83..c13051932f2d63 100644
--- a/src/core/server/mocks.ts
+++ b/src/core/server/mocks.ts
@@ -20,6 +20,7 @@ import { executionContextServiceMock } from '@kbn/core-execution-context-server-
import { prebootServiceMock } from '@kbn/core-preboot-server-mocks';
import { contextServiceMock } from '@kbn/core-http-context-server-mocks';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import type {
PluginInitializerContext,
CoreSetup,
@@ -28,7 +29,6 @@ import type {
CorePreboot,
RequestHandlerContext,
} from '.';
-import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock';
import { httpResourcesMock } from './http_resources/http_resources_service.mock';
import { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
import { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock';
@@ -46,8 +46,8 @@ import { deprecationsServiceMock } from './deprecations/deprecations_service.moc
export { configServiceMock, configDeprecationsMock } from '@kbn/config-mocks';
export { loggingSystemMock } from '@kbn/core-logging-server-mocks';
export { httpServerMock, sessionStorageMock, httpServiceMock } from '@kbn/core-http-server-mocks';
+export { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
export { httpResourcesMock } from './http_resources/http_resources_service.mock';
-export { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock';
export { savedObjectsRepositoryMock } from './saved_objects/service/lib/repository.mock';
export { savedObjectsServiceMock } from './saved_objects/saved_objects_service.mock';
export { savedObjectsClientMock } from './saved_objects/service/saved_objects_client.mock';
@@ -70,7 +70,7 @@ export type {
ElasticsearchClientMock,
ClusterClientMock,
ScopedClusterClientMock,
-} from './elasticsearch/client/mocks';
+} from '@kbn/core-elasticsearch-client-server-mocks';
type MockedPluginInitializerConfig = jest.Mocked['config']>;
diff --git a/src/core/server/plugins/legacy_config.ts b/src/core/server/plugins/legacy_config.ts
index 9dc4afc37515a1..4bee00d6157487 100644
--- a/src/core/server/plugins/legacy_config.ts
+++ b/src/core/server/plugins/legacy_config.ts
@@ -12,11 +12,11 @@ import { PathConfigType, config as pathConfig } from '@kbn/utils';
import { pick, deepFreeze } from '@kbn/std';
import { IConfigService } from '@kbn/config';
-import { SharedGlobalConfig, SharedGlobalConfigKeys } from './types';
import {
ElasticsearchConfigType,
config as elasticsearchConfig,
-} from '../elasticsearch/elasticsearch_config';
+} from '@kbn/core-elasticsearch-server-internal';
+import { SharedGlobalConfig, SharedGlobalConfigKeys } from './types';
import { SavedObjectsConfigType, savedObjectsConfig } from '../saved_objects/saved_objects_config';
const createGlobalConfig = ({
diff --git a/src/core/server/plugins/types.ts b/src/core/server/plugins/types.ts
index 98c5b6cb604970..a07eff177108e7 100644
--- a/src/core/server/plugins/types.ts
+++ b/src/core/server/plugins/types.ts
@@ -19,8 +19,8 @@ import type {
} from '@kbn/config';
import type { PluginName, PluginOpaqueId, PluginType } from '@kbn/core-base-common';
import type { NodeInfo } from '@kbn/core-node-server';
+import type { ElasticsearchConfigType } from '@kbn/core-elasticsearch-server-internal';
-import { ElasticsearchConfigType } from '../elasticsearch/elasticsearch_config';
import { SavedObjectsConfigType } from '../saved_objects/saved_objects_config';
import { CorePreboot, CoreSetup, CoreStart } from '..';
diff --git a/src/core/server/rendering/__mocks__/params.ts b/src/core/server/rendering/__mocks__/params.ts
index 47c5612555e481..71b4996590c645 100644
--- a/src/core/server/rendering/__mocks__/params.ts
+++ b/src/core/server/rendering/__mocks__/params.ts
@@ -8,7 +8,7 @@
import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { httpServiceMock } from '@kbn/core-http-server-mocks';
-import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_service.mock';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { pluginServiceMock } from '../../plugins/plugins_service.mock';
import { statusServiceMock } from '../../status/status_service.mock';
diff --git a/src/core/server/rendering/types.ts b/src/core/server/rendering/types.ts
index d6c660f3b5ec1b..0c5382627e9b66 100644
--- a/src/core/server/rendering/types.ts
+++ b/src/core/server/rendering/types.ts
@@ -14,7 +14,7 @@ import type {
InternalHttpServicePreboot,
InternalHttpServiceSetup,
} from '@kbn/core-http-server-internal';
-import { InternalElasticsearchServiceSetup } from '../elasticsearch';
+import type { InternalElasticsearchServiceSetup } from '@kbn/core-elasticsearch-server-internal';
import { UiPlugins } from '../plugins';
import { IUiSettingsClient } from '../ui_settings';
import type { InternalStatusServiceSetup } from '../status';
diff --git a/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts b/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts
index 84a8d94f8bf2c7..51f228f46438b8 100644
--- a/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts
+++ b/src/core/server/saved_objects/deprecations/unknown_object_types.test.ts
@@ -10,7 +10,7 @@ import { getIndexForTypeMock } from './unknown_object_types.test.mocks';
import { deleteUnknownTypeObjects, getUnknownTypesDeprecations } from './unknown_object_types';
import { typeRegistryMock } from '../saved_objects_type_registry.mock';
-import { elasticsearchClientMock } from '../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { SavedObjectsType } from '../..';
import { createAggregateTypesSearchResponse } from '../migrations/actions/check_for_unknown_docs.mocks';
diff --git a/src/core/server/saved_objects/deprecations/unknown_object_types.ts b/src/core/server/saved_objects/deprecations/unknown_object_types.ts
index d8762ebcfd1bd2..ba2b593dff9e57 100644
--- a/src/core/server/saved_objects/deprecations/unknown_object_types.ts
+++ b/src/core/server/saved_objects/deprecations/unknown_object_types.ts
@@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import type { DeprecationsDetails } from '@kbn/core-deprecations-common';
-import { IScopedClusterClient } from '../../elasticsearch';
+import type { IScopedClusterClient } from '@kbn/core-elasticsearch-server';
import { getAggregatedTypesDocuments } from '../migrations/actions/check_for_unknown_docs';
import { addExcludedTypesToBoolQuery } from '../migrations/model/helpers';
import { ISavedObjectTypeRegistry } from '../saved_objects_type_registry';
diff --git a/src/core/server/saved_objects/internal_types.ts b/src/core/server/saved_objects/internal_types.ts
index 4f8dc1f520e71c..9235f700f25ec9 100644
--- a/src/core/server/saved_objects/internal_types.ts
+++ b/src/core/server/saved_objects/internal_types.ts
@@ -7,7 +7,7 @@
*/
import type { IRouter, RequestHandlerContextBase } from '@kbn/core-http-server';
-import type { ElasticsearchRequestHandlerContext } from '../elasticsearch';
+import type { ElasticsearchRequestHandlerContext } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRequestHandlerContext } from './saved_objects_route_handler_context';
/**
diff --git a/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.test.ts b/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.test.ts
index 7f2cfa01ec42f6..06b5dd762cffc6 100644
--- a/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.test.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/Either';
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { bulkOverwriteTransformedDocuments } from './bulk_overwrite_transformed_documents';
diff --git a/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.ts b/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.ts
index 8318bd8f7a69b6..2948c56166133d 100644
--- a/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.ts
+++ b/src/core/server/saved_objects/migrations/actions/bulk_overwrite_transformed_documents.ts
@@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { errors as esErrors } from '@elastic/elasticsearch';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRawDoc } from '../../serialization';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.test.ts b/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.test.ts
index 68bd6c934a80f9..95a9a33831d09a 100644
--- a/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.test.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import { errors as esErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { calculateExcludeFilters } from './calculate_exclude_filters';
describe('calculateExcludeFilters', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.ts b/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.ts
index a2cea776792add..ecf29aa25f9f4d 100644
--- a/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.ts
+++ b/src/core/server/saved_objects/migrations/actions/calculate_exclude_filters.ts
@@ -10,8 +10,8 @@ import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/type
import { withTimeout } from '@kbn/std';
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { RetryableEsClientError } from '.';
-import type { ElasticsearchClient } from '../../../elasticsearch';
import type { SavedObjectTypeExcludeFromUpgradeFilterHook } from '../../types';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
diff --git a/src/core/server/saved_objects/migrations/actions/catch_retryable_es_client_errors.test.ts b/src/core/server/saved_objects/migrations/actions/catch_retryable_es_client_errors.test.ts
index 175631945d52fb..989e50af73683a 100644
--- a/src/core/server/saved_objects/migrations/actions/catch_retryable_es_client_errors.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/catch_retryable_es_client_errors.test.ts
@@ -7,7 +7,7 @@
*/
import { errors as esErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
describe('catchRetryableEsClientErrors', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.test.ts b/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.test.ts
index d5c99f01ada33e..465d4c8aa7ee84 100644
--- a/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.test.ts
@@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { checkForUnknownDocs } from './check_for_unknown_docs';
import { createAggregateTypesSearchResponse } from './check_for_unknown_docs.mocks';
diff --git a/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.ts b/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.ts
index b475f47e3d7f20..a7027c65d011e8 100644
--- a/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.ts
+++ b/src/core/server/saved_objects/migrations/actions/check_for_unknown_docs.ts
@@ -15,8 +15,8 @@ import type {
QueryDslQueryContainer,
SearchRequest,
} from '@elastic/elasticsearch/lib/api/types';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRawDocSource } from '../../serialization';
-import type { ElasticsearchClient } from '../../../elasticsearch';
import {
catchRetryableEsClientErrors,
type RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/clone_index.test.ts b/src/core/server/saved_objects/migrations/actions/clone_index.test.ts
index 84b4b00bc7e7fd..49e20d7fc7b393 100644
--- a/src/core/server/saved_objects/migrations/actions/clone_index.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/clone_index.test.ts
@@ -9,8 +9,9 @@
import { errors as EsErrors } from '@elastic/elasticsearch';
import { cloneIndex } from './clone_index';
import { setWriteBlock } from './set_write_block';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
+
jest.mock('./catch_retryable_es_client_errors');
describe('cloneIndex', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/clone_index.ts b/src/core/server/saved_objects/migrations/actions/clone_index.ts
index c64b715468c28a..8b0bce96989f27 100644
--- a/src/core/server/saved_objects/migrations/actions/clone_index.ts
+++ b/src/core/server/saved_objects/migrations/actions/clone_index.ts
@@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { errors as EsErrors } from '@elastic/elasticsearch';
import { pipe } from 'fp-ts/lib/pipeable';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
@@ -25,6 +25,7 @@ import {
} from './constants';
import { isClusterShardLimitExceeded } from './es_errors';
import { ClusterShardLimitExceeded } from './create_index';
+
export type CloneIndexResponse = AcknowledgeResponse;
/** @internal */
diff --git a/src/core/server/saved_objects/migrations/actions/close_pit.test.ts b/src/core/server/saved_objects/migrations/actions/close_pit.test.ts
index 5d9696239a61e3..d2e4a9439e3261 100644
--- a/src/core/server/saved_objects/migrations/actions/close_pit.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/close_pit.test.ts
@@ -6,11 +6,12 @@
* Side Public License, v 1.
*/
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
-jest.mock('./catch_retryable_es_client_errors');
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { closePit } from './close_pit';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('closePit', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/close_pit.ts b/src/core/server/saved_objects/migrations/actions/close_pit.ts
index cb340068560d4b..a3ea50edccae67 100644
--- a/src/core/server/saved_objects/migrations/actions/close_pit.ts
+++ b/src/core/server/saved_objects/migrations/actions/close_pit.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/create_index.test.ts b/src/core/server/saved_objects/migrations/actions/create_index.test.ts
index d5d906898943cc..47ea28ca2953d2 100644
--- a/src/core/server/saved_objects/migrations/actions/create_index.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/create_index.test.ts
@@ -8,11 +8,12 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { createIndex } from './create_index';
import { setWriteBlock } from './set_write_block';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('createIndex', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/create_index.ts b/src/core/server/saved_objects/migrations/actions/create_index.ts
index 3766a470984f5d..3436845f823820 100644
--- a/src/core/server/saved_objects/migrations/actions/create_index.ts
+++ b/src/core/server/saved_objects/migrations/actions/create_index.ts
@@ -10,8 +10,8 @@ import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { pipe } from 'fp-ts/lib/pipeable';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { AcknowledgeResponse } from '.';
-import { ElasticsearchClient } from '../../../elasticsearch';
import { IndexMapping } from '../../mappings';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/fetch_indices.test.ts b/src/core/server/saved_objects/migrations/actions/fetch_indices.test.ts
index ea53c8f4cfa54f..b0839c10a8a92a 100644
--- a/src/core/server/saved_objects/migrations/actions/fetch_indices.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/fetch_indices.test.ts
@@ -8,6 +8,9 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
+import { fetchIndices } from './fetch_indices';
+
// Create a mock powered by the actual implementation
jest.mock('./catch_retryable_es_client_errors', () => ({
catchRetryableEsClientErrors: jest
@@ -17,9 +20,6 @@ jest.mock('./catch_retryable_es_client_errors', () => ({
),
}));
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
-import { fetchIndices } from './fetch_indices';
-
describe('fetchIndices', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/fetch_indices.ts b/src/core/server/saved_objects/migrations/actions/fetch_indices.ts
index 8141670a7dbe63..a88d610a902215 100644
--- a/src/core/server/saved_objects/migrations/actions/fetch_indices.ts
+++ b/src/core/server/saved_objects/migrations/actions/fetch_indices.ts
@@ -7,12 +7,13 @@
*/
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as Either from 'fp-ts/lib/Either';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { IndexMapping } from '../../mappings';
-import { ElasticsearchClient } from '../../../elasticsearch';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
} from './catch_retryable_es_client_errors';
+
export type FetchIndexResponse = Record<
string,
{ aliases: Record; mappings: IndexMapping; settings: unknown }
diff --git a/src/core/server/saved_objects/migrations/actions/initialize_action.test.ts b/src/core/server/saved_objects/migrations/actions/initialize_action.test.ts
index 5d831a5bb8f788..ebcca7e1bb787f 100644
--- a/src/core/server/saved_objects/migrations/actions/initialize_action.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/initialize_action.test.ts
@@ -9,10 +9,11 @@
import * as Either from 'fp-ts/lib/Either';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { initAction } from './initialize_action';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('initAction', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/initialize_action.ts b/src/core/server/saved_objects/migrations/actions/initialize_action.ts
index b797d81a46ec3e..a1b5e013600187 100644
--- a/src/core/server/saved_objects/migrations/actions/initialize_action.ts
+++ b/src/core/server/saved_objects/migrations/actions/initialize_action.ts
@@ -9,7 +9,7 @@
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as Either from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/open_pit.test.ts b/src/core/server/saved_objects/migrations/actions/open_pit.test.ts
index c8fc29d06f42f7..5a6d00a1482d98 100644
--- a/src/core/server/saved_objects/migrations/actions/open_pit.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/open_pit.test.ts
@@ -8,10 +8,11 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { openPit } from './open_pit';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('openPit', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/open_pit.ts b/src/core/server/saved_objects/migrations/actions/open_pit.ts
index 7e1f3a77f2d1e7..c17b42d13a8c48 100644
--- a/src/core/server/saved_objects/migrations/actions/open_pit.ts
+++ b/src/core/server/saved_objects/migrations/actions/open_pit.ts
@@ -8,11 +8,12 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
} from './catch_retryable_es_client_errors';
+
/** @internal */
export interface OpenPitResponse {
pitId: string;
diff --git a/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.test.ts b/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.test.ts
index e319d4149dd1af..41253ebcd1ed2e 100644
--- a/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.test.ts
@@ -7,10 +7,11 @@
*/
import { errors as EsErrors } from '@elastic/elasticsearch';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { pickupUpdatedMappings } from './pickup_updated_mappings';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('pickupUpdatedMappings', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.ts b/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.ts
index c1e1111a4afe39..9cb37facc0b5a2 100644
--- a/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.ts
+++ b/src/core/server/saved_objects/migrations/actions/pickup_updated_mappings.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/read_with_pit.test.ts b/src/core/server/saved_objects/migrations/actions/read_with_pit.test.ts
index 3aca162218950c..d2f7a3ab3c3d7d 100644
--- a/src/core/server/saved_objects/migrations/actions/read_with_pit.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/read_with_pit.test.ts
@@ -8,10 +8,11 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { readWithPit } from './read_with_pit';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('readWithPit', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/read_with_pit.ts b/src/core/server/saved_objects/migrations/actions/read_with_pit.ts
index 9ba54d58d37a80..10d5ff6bfff886 100644
--- a/src/core/server/saved_objects/migrations/actions/read_with_pit.ts
+++ b/src/core/server/saved_objects/migrations/actions/read_with_pit.ts
@@ -9,7 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRawDoc } from '../../serialization';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/refresh_index.test.ts b/src/core/server/saved_objects/migrations/actions/refresh_index.test.ts
index 0ebdb2b2b18519..1de2a0142032d8 100644
--- a/src/core/server/saved_objects/migrations/actions/refresh_index.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/refresh_index.test.ts
@@ -8,10 +8,11 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { refreshIndex } from './refresh_index';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('refreshIndex', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/refresh_index.ts b/src/core/server/saved_objects/migrations/actions/refresh_index.ts
index 371247789af24e..7eb5c5d560d4cc 100644
--- a/src/core/server/saved_objects/migrations/actions/refresh_index.ts
+++ b/src/core/server/saved_objects/migrations/actions/refresh_index.ts
@@ -7,7 +7,7 @@
*/
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/reindex.test.ts b/src/core/server/saved_objects/migrations/actions/reindex.test.ts
index 3352e4eebadca4..969150a21cfcd7 100644
--- a/src/core/server/saved_objects/migrations/actions/reindex.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/reindex.test.ts
@@ -8,10 +8,11 @@
import * as Option from 'fp-ts/lib/Option';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { reindex } from './reindex';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('reindex', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/reindex.ts b/src/core/server/saved_objects/migrations/actions/reindex.ts
index 46f20928e1befa..594822f7247602 100644
--- a/src/core/server/saved_objects/migrations/actions/reindex.ts
+++ b/src/core/server/saved_objects/migrations/actions/reindex.ts
@@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as Option from 'fp-ts/lib/Option';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
type RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/remove_write_block.test.ts b/src/core/server/saved_objects/migrations/actions/remove_write_block.test.ts
index 497211cb693ab1..d8caaaca5eac61 100644
--- a/src/core/server/saved_objects/migrations/actions/remove_write_block.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/remove_write_block.test.ts
@@ -7,9 +7,10 @@
*/
import { removeWriteBlock } from './remove_write_block';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
+
jest.mock('./catch_retryable_es_client_errors');
describe('removeWriteBlock', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/remove_write_block.ts b/src/core/server/saved_objects/migrations/actions/remove_write_block.ts
index 47a3ecf7a44043..e5c64c8385e910 100644
--- a/src/core/server/saved_objects/migrations/actions/remove_write_block.ts
+++ b/src/core/server/saved_objects/migrations/actions/remove_write_block.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.test.ts b/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.test.ts
index ab133e9a564be7..9af32139bb78e8 100644
--- a/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.test.ts
@@ -8,10 +8,11 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { searchForOutdatedDocuments } from './search_for_outdated_documents';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('searchForOutdatedDocuments', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.ts b/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.ts
index bc6b6e5c29d467..fefc73c588fee0 100644
--- a/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.ts
+++ b/src/core/server/saved_objects/migrations/actions/search_for_outdated_documents.ts
@@ -9,7 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type { SavedObjectsRawDoc, SavedObjectsRawDocSource } from '../../serialization';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/set_write_block.test.ts b/src/core/server/saved_objects/migrations/actions/set_write_block.test.ts
index cf7b3091f38ffc..7da18cb4114534 100644
--- a/src/core/server/saved_objects/migrations/actions/set_write_block.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/set_write_block.test.ts
@@ -6,9 +6,10 @@
* Side Public License, v 1.
*/
import { setWriteBlock } from './set_write_block';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
+
jest.mock('./catch_retryable_es_client_errors');
describe('setWriteBlock', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/set_write_block.ts b/src/core/server/saved_objects/migrations/actions/set_write_block.ts
index fcb508aa6cf3f5..d5410cf11b57ed 100644
--- a/src/core/server/saved_objects/migrations/actions/set_write_block.ts
+++ b/src/core/server/saved_objects/migrations/actions/set_write_block.ts
@@ -9,7 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/update_aliases.test.ts b/src/core/server/saved_objects/migrations/actions/update_aliases.test.ts
index e2ea07d40281bf..960029252da24a 100644
--- a/src/core/server/saved_objects/migrations/actions/update_aliases.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/update_aliases.test.ts
@@ -8,11 +8,12 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { updateAliases } from './update_aliases';
import { setWriteBlock } from './set_write_block';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('updateAliases', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/update_aliases.ts b/src/core/server/saved_objects/migrations/actions/update_aliases.ts
index c8ac3655ba72a6..1a5e487ce9205c 100644
--- a/src/core/server/saved_objects/migrations/actions/update_aliases.ts
+++ b/src/core/server/saved_objects/migrations/actions/update_aliases.ts
@@ -9,7 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.test.ts b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.test.ts
index 3ecb990cd9e825..8fdb5550bd01e4 100644
--- a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.test.ts
@@ -8,10 +8,11 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { updateAndPickupMappings } from './update_and_pickup_mappings';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('updateAndPickupMappings', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts
index 06b3e9051ffa3b..bd1c2d6ff76148 100644
--- a/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts
+++ b/src/core/server/saved_objects/migrations/actions/update_and_pickup_mappings.ts
@@ -9,7 +9,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import { pipe } from 'fp-ts/lib/pipeable';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { IndexMapping } from '../../mappings';
import {
catchRetryableEsClientErrors,
diff --git a/src/core/server/saved_objects/migrations/actions/verify_reindex.ts b/src/core/server/saved_objects/migrations/actions/verify_reindex.ts
index 481daf459251df..866ec9974e929d 100644
--- a/src/core/server/saved_objects/migrations/actions/verify_reindex.ts
+++ b/src/core/server/saved_objects/migrations/actions/verify_reindex.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.test.ts b/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.test.ts
index 8cea34b80ffad1..ecff30c595a78c 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.test.ts
@@ -8,8 +8,9 @@
import { errors as EsErrors } from '@elastic/elasticsearch';
import { waitForIndexStatusYellow } from './wait_for_index_status_yellow';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
+
jest.mock('./catch_retryable_es_client_errors');
describe('waitForIndexStatusYellow', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.ts b/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.ts
index fed28252bd2a42..a306c0d2d058c2 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_index_status_yellow.ts
@@ -8,7 +8,7 @@
import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_pickup_updated_mappings_task.test.ts b/src/core/server/saved_objects/migrations/actions/wait_for_pickup_updated_mappings_task.test.ts
index f7c380be9427cb..896a687c1f8d36 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_pickup_updated_mappings_task.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_pickup_updated_mappings_task.test.ts
@@ -8,11 +8,12 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { waitForPickupUpdatedMappingsTask } from './wait_for_pickup_updated_mappings_task';
import { setWriteBlock } from './set_write_block';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('waitForPickupUpdatedMappingsTask', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_reindex_task.test.ts b/src/core/server/saved_objects/migrations/actions/wait_for_reindex_task.test.ts
index f6a236aab5c85b..bb9858c60cb24c 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_reindex_task.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_reindex_task.test.ts
@@ -8,11 +8,12 @@
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
import { errors as EsErrors } from '@elastic/elasticsearch';
-jest.mock('./catch_retryable_es_client_errors');
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { waitForReindexTask } from './wait_for_reindex_task';
import { setWriteBlock } from './set_write_block';
+jest.mock('./catch_retryable_es_client_errors');
+
describe('waitForReindexTask', () => {
beforeEach(() => {
jest.clearAllMocks();
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_task.test.ts b/src/core/server/saved_objects/migrations/actions/wait_for_task.test.ts
index c7ca9bf36a2c62..4a5fc20e1fe122 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_task.test.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_task.test.ts
@@ -7,8 +7,9 @@
*/
import { errors as EsErrors } from '@elastic/elasticsearch';
import { waitForTask } from './wait_for_task';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { catchRetryableEsClientErrors } from './catch_retryable_es_client_errors';
+
jest.mock('./catch_retryable_es_client_errors');
describe('waitForTask', () => {
diff --git a/src/core/server/saved_objects/migrations/actions/wait_for_task.ts b/src/core/server/saved_objects/migrations/actions/wait_for_task.ts
index f3f1e116ab3c08..a5762ff10a122e 100644
--- a/src/core/server/saved_objects/migrations/actions/wait_for_task.ts
+++ b/src/core/server/saved_objects/migrations/actions/wait_for_task.ts
@@ -10,11 +10,12 @@ import * as Either from 'fp-ts/lib/Either';
import * as TaskEither from 'fp-ts/lib/TaskEither';
import * as Option from 'fp-ts/lib/Option';
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import {
catchRetryableEsClientErrors,
RetryableEsClientError,
} from './catch_retryable_es_client_errors';
+
/** @internal */
export interface WaitForTaskResponse {
error: Option.Option<{ type: string; reason: string; index?: string }>;
diff --git a/src/core/server/saved_objects/migrations/integration_tests/7.7.2_xpack_100k.test.ts b/src/core/server/saved_objects/migrations/integration_tests/7.7.2_xpack_100k.test.ts
index 66c7d2e81b846c..530a4b92ead6a4 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/7.7.2_xpack_100k.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/7.7.2_xpack_100k.test.ts
@@ -11,8 +11,8 @@ import { unlink } from 'fs/promises';
import { REPO_ROOT } from '@kbn/utils';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import { ElasticsearchClient } from '../../../elasticsearch';
import { InternalCoreStart } from '../../../internal_types';
import { Root } from '../../../root';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_failed_action_tasks.test.ts b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_failed_action_tasks.test.ts
index d2bf71f023de74..cffc23b476c719 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_failed_action_tasks.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_failed_action_tasks.test.ts
@@ -8,9 +8,9 @@
import Path from 'path';
import fs from 'fs/promises';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '../../../root';
-import { ElasticsearchClient } from '../../../elasticsearch';
const logFilePath = Path.join(__dirname, '7_13_failed_action_tasks.log');
diff --git a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_transform_failures.test.ts b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_transform_failures.test.ts
index 714ce363c06e27..b177332322c00d 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_transform_failures.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_transform_failures.test.ts
@@ -12,7 +12,7 @@ import Util from 'util';
import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config-mocks';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '../../../root';
import { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_unknown_types.test.ts b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_unknown_types.test.ts
index 6ccb6497516f90..2008cc370f2cee 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/7_13_0_unknown_types.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/7_13_0_unknown_types.test.ts
@@ -12,9 +12,9 @@ import type { IndicesIndexSettings } from '@elastic/elasticsearch/lib/api/types'
import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config-mocks';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import type { Root } from '../../../root';
-import type { ElasticsearchClient } from '../../../elasticsearch';
const logFilePath = Path.join(__dirname, '7_13_unknown_types.log');
diff --git a/src/core/server/saved_objects/migrations/integration_tests/batch_size_bytes.test.ts b/src/core/server/saved_objects/migrations/integration_tests/batch_size_bytes.test.ts
index b6e10e6b3034b0..4d17ea2b90e2cd 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/batch_size_bytes.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/batch_size_bytes.test.ts
@@ -11,7 +11,7 @@ import fs from 'fs/promises';
import JSON5 from 'json5';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '../../../root';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Env } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { getEnvOptions } from '@kbn/config-mocks';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/incompatible_cluster_routing_allocation.test.ts b/src/core/server/saved_objects/migrations/integration_tests/incompatible_cluster_routing_allocation.test.ts
index 8a075aa08bbe21..c29108fc0bb850 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/incompatible_cluster_routing_allocation.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/incompatible_cluster_routing_allocation.test.ts
@@ -15,7 +15,7 @@ import { getDocLinksMeta } from '@kbn/doc-links';
import { getEnvOptions } from '@kbn/config-mocks';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
import { Root } from '../../../root';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { LogRecord } from '@kbn/logging';
import { retryAsync } from '../test_helpers/retry_async';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/migration_from_older_v1.test.ts b/src/core/server/saved_objects/migrations/integration_tests/migration_from_older_v1.test.ts
index 69c9cc38fc79d2..379ecd4421ce44 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/migration_from_older_v1.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/migration_from_older_v1.test.ts
@@ -14,7 +14,7 @@ import { REPO_ROOT } from '@kbn/utils';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsRawDoc } from '../../serialization';
import { InternalCoreStart } from '../../../internal_types';
import { Root } from '../../../root';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/migration_from_same_v1.test.ts b/src/core/server/saved_objects/migrations/integration_tests/migration_from_same_v1.test.ts
index 5c723b89c23d13..9c4413311c36c4 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/migration_from_same_v1.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/migration_from_same_v1.test.ts
@@ -14,7 +14,7 @@ import { REPO_ROOT } from '@kbn/utils';
import { Env } from '@kbn/config';
import { getEnvOptions } from '@kbn/config-mocks';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsRawDoc } from '../../serialization';
import { InternalCoreStart } from '../../../internal_types';
import { Root } from '../../../root';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/multiple_es_nodes.test.ts b/src/core/server/saved_objects/migrations/integration_tests/multiple_es_nodes.test.ts
index f88f97a677616b..adb7aeacf4610a 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/multiple_es_nodes.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/multiple_es_nodes.test.ts
@@ -11,7 +11,7 @@ import del from 'del';
import { kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '../../../root';
const LOG_FILE_PREFIX = 'migration_test_multiple_es_nodes';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/multiple_kibana_nodes.test.ts b/src/core/server/saved_objects/migrations/integration_tests/multiple_kibana_nodes.test.ts
index bc8c138e9ef20c..c5774e703a5b77 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/multiple_kibana_nodes.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/multiple_kibana_nodes.test.ts
@@ -11,7 +11,7 @@ import del from 'del';
import { esTestConfig, kibanaServerTestUser } from '@kbn/test';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsType } from '../../types';
import type { Root } from '../../../root';
diff --git a/src/core/server/saved_objects/migrations/integration_tests/outdated_docs.test.ts b/src/core/server/saved_objects/migrations/integration_tests/outdated_docs.test.ts
index bc1f41b542380f..74dc2d785c35e8 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/outdated_docs.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/outdated_docs.test.ts
@@ -11,7 +11,7 @@ import Fs from 'fs';
import Util from 'util';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '../../../root';
const logFilePath = Path.join(__dirname, 'outdated_docs.log');
diff --git a/src/core/server/saved_objects/migrations/integration_tests/rewriting_id.test.ts b/src/core/server/saved_objects/migrations/integration_tests/rewriting_id.test.ts
index cf350c0e9a35ed..33168999c0876d 100644
--- a/src/core/server/saved_objects/migrations/integration_tests/rewriting_id.test.ts
+++ b/src/core/server/saved_objects/migrations/integration_tests/rewriting_id.test.ts
@@ -11,7 +11,7 @@ import Fs from 'fs';
import Util from 'util';
import { kibanaPackageJson as pkg } from '@kbn/utils';
import * as kbnTestServer from '../../../../test_helpers/kbn_server';
-import type { ElasticsearchClient } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { Root } from '../../../root';
import { deterministicallyRegenerateObjectId } from '../core/document_migrator';
diff --git a/src/core/server/saved_objects/migrations/kibana_migrator.test.ts b/src/core/server/saved_objects/migrations/kibana_migrator.test.ts
index a19071a7d2d76f..926b6efcf18037 100644
--- a/src/core/server/saved_objects/migrations/kibana_migrator.test.ts
+++ b/src/core/server/saved_objects/migrations/kibana_migrator.test.ts
@@ -10,7 +10,7 @@ import { take } from 'rxjs/operators';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
-import { elasticsearchClientMock } from '../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { KibanaMigratorOptions, KibanaMigrator } from './kibana_migrator';
import { SavedObjectTypeRegistry } from '../saved_objects_type_registry';
import { SavedObjectsType } from '../types';
diff --git a/src/core/server/saved_objects/migrations/kibana_migrator.ts b/src/core/server/saved_objects/migrations/kibana_migrator.ts
index 7be5576e55241c..c7fb2533a89baf 100644
--- a/src/core/server/saved_objects/migrations/kibana_migrator.ts
+++ b/src/core/server/saved_objects/migrations/kibana_migrator.ts
@@ -15,7 +15,7 @@ import { BehaviorSubject } from 'rxjs';
import Semver from 'semver';
import type { Logger } from '@kbn/logging';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
-import { ElasticsearchClient } from '../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../mappings';
import {
SavedObjectUnsanitizedDoc,
diff --git a/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts b/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts
index 2a182873be0617..db319c63e216ff 100644
--- a/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts
+++ b/src/core/server/saved_objects/migrations/migrations_state_action_machine.test.ts
@@ -16,7 +16,7 @@ import { typeRegistryMock } from '../saved_objects_type_registry.mock';
import * as Either from 'fp-ts/lib/Either';
import * as Option from 'fp-ts/lib/Option';
import { errors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { AllControlStates, State } from './state';
import { createInitialState } from './initial_state';
import { ByteSizeValue } from '@kbn/config-schema';
diff --git a/src/core/server/saved_objects/migrations/migrations_state_action_machine.ts b/src/core/server/saved_objects/migrations/migrations_state_action_machine.ts
index 8eaae216914f7a..92806236203af8 100644
--- a/src/core/server/saved_objects/migrations/migrations_state_action_machine.ts
+++ b/src/core/server/saved_objects/migrations/migrations_state_action_machine.ts
@@ -9,8 +9,11 @@
import { errors as EsErrors } from '@elastic/elasticsearch';
import * as Option from 'fp-ts/lib/Option';
import type { Logger, LogMeta } from '@kbn/logging';
-import type { ElasticsearchClient } from '../../elasticsearch';
-import { getErrorMessage, getRequestDebugMeta } from '../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
+import {
+ getErrorMessage,
+ getRequestDebugMeta,
+} from '@kbn/core-elasticsearch-client-server-internal';
import { Model, Next, stateActionMachine } from './state_action_machine';
import { cleanup } from './migrations_state_machine_cleanup';
import { ReindexSourceToTempTransform, ReindexSourceToTempIndexBulk, State } from './state';
diff --git a/src/core/server/saved_objects/migrations/migrations_state_machine_cleanup.ts b/src/core/server/saved_objects/migrations/migrations_state_machine_cleanup.ts
index ff8ff57d41ce46..8b1f93c327857b 100644
--- a/src/core/server/saved_objects/migrations/migrations_state_machine_cleanup.ts
+++ b/src/core/server/saved_objects/migrations/migrations_state_machine_cleanup.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import type { ElasticsearchClient } from '../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import * as Actions from './actions';
import type { State } from './state';
diff --git a/src/core/server/saved_objects/migrations/next.test.ts b/src/core/server/saved_objects/migrations/next.test.ts
index 98a8690844872c..548c6b8c43b51b 100644
--- a/src/core/server/saved_objects/migrations/next.test.ts
+++ b/src/core/server/saved_objects/migrations/next.test.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import { ElasticsearchClient } from '../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { next } from './next';
import { State } from './state';
diff --git a/src/core/server/saved_objects/migrations/next.ts b/src/core/server/saved_objects/migrations/next.ts
index e50331d3b76588..7d73d4830259bf 100644
--- a/src/core/server/saved_objects/migrations/next.ts
+++ b/src/core/server/saved_objects/migrations/next.ts
@@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type {
AllActionStates,
ReindexSourceToTempOpenPit,
@@ -42,7 +43,6 @@ import type {
} from './state';
import type { TransformRawDocs } from './types';
import * as Actions from './actions';
-import type { ElasticsearchClient } from '../../elasticsearch';
type ActionMap = ReturnType;
diff --git a/src/core/server/saved_objects/migrations/run_resilient_migrator.ts b/src/core/server/saved_objects/migrations/run_resilient_migrator.ts
index 4d75bc09caf2d9..87618dcbab1c99 100644
--- a/src/core/server/saved_objects/migrations/run_resilient_migrator.ts
+++ b/src/core/server/saved_objects/migrations/run_resilient_migrator.ts
@@ -8,7 +8,7 @@
import type { Logger } from '@kbn/logging';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
-import { ElasticsearchClient } from '../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { IndexMapping } from '../mappings';
import type { SavedObjectsMigrationVersion } from '../types';
import type { TransformRawDocs } from './types';
diff --git a/src/core/server/saved_objects/routes/integration_tests/delete_unknown_types.test.ts b/src/core/server/saved_objects/routes/integration_tests/delete_unknown_types.test.ts
index 87376de2068103..24ba230a7012a8 100644
--- a/src/core/server/saved_objects/routes/integration_tests/delete_unknown_types.test.ts
+++ b/src/core/server/saved_objects/routes/integration_tests/delete_unknown_types.test.ts
@@ -8,7 +8,7 @@
import supertest from 'supertest';
import { registerDeleteUnknownTypesRoute } from '../deprecations';
-import { elasticsearchServiceMock } from '../../../elasticsearch/elasticsearch_service.mock';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';
import { setupServer } from '../test_utils';
import { SavedObjectsType } from '../../..';
diff --git a/src/core/server/saved_objects/saved_objects_service.test.ts b/src/core/server/saved_objects/saved_objects_service.test.ts
index e2b7cdb92c46be..c821ff9b4bbd2a 100644
--- a/src/core/server/saved_objects/saved_objects_service.test.ts
+++ b/src/core/server/saved_objects/saved_objects_service.test.ts
@@ -28,11 +28,11 @@ import { httpServiceMock, httpServerMock } from '@kbn/core-http-server-mocks';
import { SavedObjectsService } from './saved_objects_service';
import { configServiceMock } from '../mocks';
-import { elasticsearchServiceMock } from '../elasticsearch/elasticsearch_service.mock';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
import { coreUsageDataServiceMock } from '../core_usage_data/core_usage_data_service.mock';
import { deprecationsServiceMock } from '../deprecations/deprecations_service.mock';
import { SavedObjectsClientFactoryProvider } from './service/lib';
-import { NodesVersionCompatibility } from '../elasticsearch/version_check/ensure_es_version';
+import type { NodesVersionCompatibility } from '@kbn/core-elasticsearch-server-internal';
import { SavedObjectsRepository } from './service/lib/repository';
import { registerCoreObjectTypes } from './object_types';
import { getSavedObjectsDeprecationsProvider } from './deprecations';
diff --git a/src/core/server/saved_objects/saved_objects_service.ts b/src/core/server/saved_objects/saved_objects_service.ts
index 83f906f0d14c91..123550393f49bb 100644
--- a/src/core/server/saved_objects/saved_objects_service.ts
+++ b/src/core/server/saved_objects/saved_objects_service.ts
@@ -13,6 +13,11 @@ import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
import type { DocLinksServiceStart } from '@kbn/core-doc-links-server';
import type { KibanaRequest } from '@kbn/core-http-server';
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
+import type {
+ InternalElasticsearchServiceSetup,
+ InternalElasticsearchServiceStart,
+} from '@kbn/core-elasticsearch-server-internal';
import {
SavedObjectsClient,
SavedObjectsClientProvider,
@@ -20,11 +25,6 @@ import {
} from '.';
import { KibanaMigrator, IKibanaMigrator } from './migrations';
import { InternalCoreUsageDataSetup } from '../core_usage_data';
-import {
- ElasticsearchClient,
- InternalElasticsearchServiceSetup,
- InternalElasticsearchServiceStart,
-} from '../elasticsearch';
import { InternalDeprecationsServiceSetup } from '../deprecations';
import {
SavedObjectsConfigType,
diff --git a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts
index bac745995ce079..cc219579d9c0b8 100644
--- a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts
+++ b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.test.ts
@@ -12,7 +12,7 @@ import {
mockRawDocExistsInNamespace,
} from './collect_multi_namespace_references.test.mock';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';
import { SavedObjectsSerializer } from '../../serialization';
import {
diff --git a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts
index a6336a89ac6feb..fb6bd89f358f6f 100644
--- a/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts
+++ b/src/core/server/saved_objects/service/lib/collect_multi_namespace_references.ts
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
-import { isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
+import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import type { ISavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import type { SavedObjectsSerializer } from '../../serialization';
import type { SavedObject, SavedObjectsBaseOptions } from '../../types';
diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
index 4e187e85f81a74..a7aa52f7a0f5a3 100644
--- a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
+++ b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
@@ -7,7 +7,7 @@
*/
import { errors as esErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { decorateEsError } from './decorate_es_error';
import { SavedObjectsErrorHelpers } from './errors';
diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.ts
index cfe80df7891429..40eda7a854a25c 100644
--- a/src/core/server/saved_objects/service/lib/decorate_es_error.ts
+++ b/src/core/server/saved_objects/service/lib/decorate_es_error.ts
@@ -9,7 +9,7 @@
import { get } from 'lodash';
import { errors as esErrors } from '@elastic/elasticsearch';
import type { ElasticsearchErrorDetails } from '@kbn/es-errors';
-import { isSupportedEsServer } from '../../../elasticsearch';
+import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal';
const responseErrors = {
isServiceUnavailable: (statusCode?: number) => statusCode === 503,
diff --git a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.mock.ts b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.mock.ts
index fbd774f1c10d55..277d1ae4af34ac 100644
--- a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.mock.ts
+++ b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.mock.ts
@@ -6,8 +6,8 @@
* Side Public License, v 1.
*/
+import type { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import type * as InternalUtils from './internal_utils';
-import type { isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
export const mockGetSavedObjectFromSource = jest.fn() as jest.MockedFunction<
typeof InternalUtils['getSavedObjectFromSource']
@@ -28,8 +28,8 @@ jest.mock('./internal_utils', () => {
export const mockIsNotFoundFromUnsupportedServer = jest.fn() as jest.MockedFunction<
typeof isNotFoundFromUnsupportedServer
>;
-jest.mock('../../../elasticsearch', () => {
- const actual = jest.requireActual('../../../elasticsearch');
+jest.mock('@kbn/core-elasticsearch-server-internal', () => {
+ const actual = jest.requireActual('@kbn/core-elasticsearch-server-internal');
return {
...actual,
isNotFoundFromUnsupportedServer: mockIsNotFoundFromUnsupportedServer,
diff --git a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts
index 749eff0e338758..44940cd0ae0d75 100644
--- a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts
+++ b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.test.ts
@@ -12,7 +12,7 @@ import {
mockIsNotFoundFromUnsupportedServer,
} from './internal_bulk_resolve.test.mock';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LEGACY_URL_ALIAS_TYPE } from '../../object_types';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';
import { SavedObjectsSerializer } from '../../serialization';
diff --git a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts
index 3a59ab8a8d9f32..96ea29486520be 100644
--- a/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts
+++ b/src/core/server/saved_objects/service/lib/internal_bulk_resolve.ts
@@ -8,12 +8,12 @@
import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
+import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import {
CORE_USAGE_STATS_ID,
CORE_USAGE_STATS_TYPE,
REPOSITORY_RESOLVE_OUTCOME_STATS,
} from '../../../core_usage_data';
-import { isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../object_types';
import type { ISavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import type { SavedObjectsRawDocSource, SavedObjectsSerializer } from '../../serialization';
diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.mock.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.mock.ts
index d8c1b8edb95583..0922910936c521 100644
--- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.mock.ts
+++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.mock.ts
@@ -6,11 +6,11 @@
* Side Public License, v 1.
*/
-import type { getErrorMessage } from '../../../../elasticsearch';
+import type { getErrorMessage } from '@kbn/core-elasticsearch-client-server-internal';
export const mockGetEsErrorMessage = jest.fn() as jest.MockedFunction;
-jest.mock('../../../../elasticsearch', () => {
+jest.mock('@kbn/core-elasticsearch-client-server-internal', () => {
return { getErrorMessage: mockGetEsErrorMessage };
});
diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts
index e23f8ef1eb9fd1..dc261ee23aafb8 100644
--- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts
+++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.test.ts
@@ -10,7 +10,7 @@ import { mockGetEsErrorMessage } from './delete_legacy_url_aliases.test.mock'; /
import { errors as EsErrors } from '@elastic/elasticsearch';
-import { elasticsearchClientMock } from '../../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { typeRegistryMock } from '../../../saved_objects_type_registry.mock';
import { ALL_NAMESPACES_STRING } from '../utils';
import { deleteLegacyUrlAliases } from './delete_legacy_url_aliases';
diff --git a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts
index 690465f08bd36d..e562543125472b 100644
--- a/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts
+++ b/src/core/server/saved_objects/service/lib/legacy_url_aliases/delete_legacy_url_aliases.ts
@@ -8,7 +8,7 @@
import * as esKuery from '@kbn/es-query';
-import { getErrorMessage as getEsErrorMessage } from '../../../../elasticsearch';
+import { getErrorMessage as getEsErrorMessage } from '@kbn/core-elasticsearch-client-server-internal';
import type { ISavedObjectTypeRegistry } from '../../../saved_objects_type_registry';
import type { IndexMapping } from '../../../mappings';
import { LEGACY_URL_ALIAS_TYPE } from '../../../object_types';
diff --git a/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts b/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts
index b7c61bc6f77112..9563ebd51344f8 100644
--- a/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts
+++ b/src/core/server/saved_objects/service/lib/preflight_check_for_create.test.ts
@@ -13,8 +13,8 @@ import {
import type { DeeplyMockedKeys } from '@kbn/utility-types-jest';
-import type { ElasticsearchClient } from '../../../elasticsearch';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LEGACY_URL_ALIAS_TYPE } from '../../object_types';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';
import { SavedObjectsSerializer } from '../../serialization';
diff --git a/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts b/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts
index 55eb80dbc48741..2611ae19184c90 100644
--- a/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts
+++ b/src/core/server/saved_objects/service/lib/preflight_check_for_create.ts
@@ -5,8 +5,9 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
+
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-import { isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
+import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import { LegacyUrlAlias, LEGACY_URL_ALIAS_TYPE } from '../../object_types';
import type { ISavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import type {
diff --git a/src/core/server/saved_objects/service/lib/repository.test.ts b/src/core/server/saved_objects/service/lib/repository.test.ts
index 199ad514c28edb..c916953df2ad52 100644
--- a/src/core/server/saved_objects/service/lib/repository.test.ts
+++ b/src/core/server/saved_objects/service/lib/repository.test.ts
@@ -56,7 +56,7 @@ import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import { DocumentMigrator } from '../../migrations/core/document_migrator';
import { mockKibanaMigrator } from '../../migrations/kibana_migrator.mock';
import { LEGACY_URL_ALIAS_TYPE } from '../../object_types';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import * as esKuery from '@kbn/es-query';
import { errors as EsErrors } from '@elastic/elasticsearch';
import {
diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts
index 679d3fbdb498f9..6688b8ce184851 100644
--- a/src/core/server/saved_objects/service/lib/repository.ts
+++ b/src/core/server/saved_objects/service/lib/repository.ts
@@ -10,8 +10,11 @@ import { omit, isObject } from 'lodash';
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import * as esKuery from '@kbn/es-query';
import type { Logger } from '@kbn/logging';
-import type { ElasticsearchClient } from '../../../elasticsearch';
-import { isSupportedEsServer, isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
+import {
+ isSupportedEsServer,
+ isNotFoundFromUnsupportedServer,
+} from '@kbn/core-elasticsearch-server-internal';
import { getRootPropertiesObjects, IndexMapping } from '../../mappings';
import {
ISavedObjectsPointInTimeFinder,
diff --git a/src/core/server/saved_objects/service/lib/repository_es_client.test.mock.ts b/src/core/server/saved_objects/service/lib/repository_es_client.test.mock.ts
index 22702a6a565f17..700786beb64aa1 100644
--- a/src/core/server/saved_objects/service/lib/repository_es_client.test.mock.ts
+++ b/src/core/server/saved_objects/service/lib/repository_es_client.test.mock.ts
@@ -7,6 +7,6 @@
*/
export const retryCallClusterMock = jest.fn((fn) => fn());
-jest.doMock('../../../elasticsearch/client/retry_call_cluster', () => ({
+jest.doMock('@kbn/core-elasticsearch-server-internal', () => ({
retryCallCluster: retryCallClusterMock,
}));
diff --git a/src/core/server/saved_objects/service/lib/repository_es_client.test.ts b/src/core/server/saved_objects/service/lib/repository_es_client.test.ts
index d06172fc6a673a..f465ffb6a3dab4 100644
--- a/src/core/server/saved_objects/service/lib/repository_es_client.test.ts
+++ b/src/core/server/saved_objects/service/lib/repository_es_client.test.ts
@@ -9,7 +9,7 @@
import { retryCallClusterMock } from './repository_es_client.test.mock';
import { createRepositoryEsClient, RepositoryEsClient } from './repository_es_client';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { SavedObjectsErrorHelpers } from './errors';
describe('RepositoryEsClient', () => {
diff --git a/src/core/server/saved_objects/service/lib/repository_es_client.ts b/src/core/server/saved_objects/service/lib/repository_es_client.ts
index 9c9d84d975d0d1..14dcb996267892 100644
--- a/src/core/server/saved_objects/service/lib/repository_es_client.ts
+++ b/src/core/server/saved_objects/service/lib/repository_es_client.ts
@@ -8,8 +8,8 @@
import type { TransportRequestOptions } from '@elastic/elasticsearch';
-import { ElasticsearchClient } from '../../../elasticsearch';
-import { retryCallCluster } from '../../../elasticsearch/client/retry_call_cluster';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
+import { retryCallCluster } from '@kbn/core-elasticsearch-server-internal';
import { decorateEsError } from './decorate_es_error';
const methods = [
diff --git a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts
index 5a600128a38ecd..194caef879fe89 100644
--- a/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts
+++ b/src/core/server/saved_objects/service/lib/update_objects_spaces.test.ts
@@ -13,7 +13,7 @@ import {
mockDeleteLegacyUrlAliases,
} from './update_objects_spaces.test.mock';
-import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { loggerMock } from '@kbn/logging-mocks';
import { typeRegistryMock } from '../../saved_objects_type_registry.mock';
diff --git a/src/core/server/saved_objects/service/lib/update_objects_spaces.ts b/src/core/server/saved_objects/service/lib/update_objects_spaces.ts
index 9a1ca70b83fc74..b8ffd0ad7e5280 100644
--- a/src/core/server/saved_objects/service/lib/update_objects_spaces.ts
+++ b/src/core/server/saved_objects/service/lib/update_objects_spaces.ts
@@ -11,7 +11,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import intersection from 'lodash/intersection';
import type { Logger } from '@kbn/logging';
-import { isNotFoundFromUnsupportedServer } from '../../../elasticsearch';
+import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal';
import type { IndexMapping } from '../../mappings';
import type { ISavedObjectTypeRegistry } from '../../saved_objects_type_registry';
import type { SavedObjectsRawDocSource, SavedObjectsSerializer } from '../../serialization';
diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts
index eb4eb77f8d4b8a..134289cb2b4935 100644
--- a/src/core/server/saved_objects/types.ts
+++ b/src/core/server/saved_objects/types.ts
@@ -7,6 +7,7 @@
*/
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
+import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { SavedObjectsClient } from './service/saved_objects_client';
import { SavedObjectsTypeMappingDefinition } from './mappings';
import { SavedObjectMigrationMap } from './migrations';
@@ -30,7 +31,6 @@ export type {
} from './import/types';
import { SavedObject } from '../../types';
-import { ElasticsearchClient } from '../elasticsearch';
type KueryNode = any;
diff --git a/src/core/server/server.test.mocks.ts b/src/core/server/server.test.mocks.ts
index e1b294fb6778af..4b7f7ec958979d 100644
--- a/src/core/server/server.test.mocks.ts
+++ b/src/core/server/server.test.mocks.ts
@@ -20,10 +20,10 @@ jest.doMock('./plugins/plugins_service', () => ({
PluginsService: jest.fn(() => mockPluginsService),
}));
-import { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock';
+import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks';
export const mockElasticsearchService = elasticsearchServiceMock.create();
-jest.doMock('./elasticsearch/elasticsearch_service', () => ({
+jest.doMock('@kbn/core-elasticsearch-server-internal', () => ({
ElasticsearchService: jest.fn(() => mockElasticsearchService),
}));
diff --git a/src/core/server/server.ts b/src/core/server/server.ts
index 5f811723845c11..6f2039cf41eb2c 100644
--- a/src/core/server/server.ts
+++ b/src/core/server/server.ts
@@ -37,9 +37,12 @@ import {
cspConfig,
externalUrlConfig,
} from '@kbn/core-http-server-internal';
+import {
+ ElasticsearchService,
+ config as elasticsearchConfig,
+} from '@kbn/core-elasticsearch-server-internal';
import { CoreApp } from './core_app';
import { I18nService } from './i18n';
-import { ElasticsearchService } from './elasticsearch';
import { HttpResourcesService } from './http_resources';
import { RenderingService } from './rendering';
import { UiSettingsService } from './ui_settings';
@@ -50,7 +53,6 @@ import { CapabilitiesService } from './capabilities';
// do not try to shorten the import to `./status`, it will break server test mocking
import { StatusService } from './status/status_service';
-import { config as elasticsearchConfig } from './elasticsearch';
import { savedObjectsConfig, savedObjectsMigrationConfig } from './saved_objects';
import { config as uiSettingsConfig } from './ui_settings';
import { config as statusConfig } from './status';
diff --git a/src/core/server/status/status_service.ts b/src/core/server/status/status_service.ts
index dc73bd83c4625b..733a3373447a97 100644
--- a/src/core/server/status/status_service.ts
+++ b/src/core/server/status/status_service.ts
@@ -25,7 +25,7 @@ import type { PluginName } from '@kbn/core-base-common';
import type { AnalyticsServiceSetup } from '@kbn/core-analytics-server';
import type { InternalEnvironmentServiceSetup } from '@kbn/core-environment-server-internal';
import type { InternalHttpServiceSetup } from '@kbn/core-http-server-internal';
-import { InternalElasticsearchServiceSetup } from '../elasticsearch';
+import type { InternalElasticsearchServiceSetup } from '@kbn/core-elasticsearch-server-internal';
import { InternalSavedObjectsServiceSetup } from '../saved_objects';
import { InternalMetricsServiceSetup } from '../metrics';
import { registerStatusRoute } from './routes';
diff --git a/src/core/server/status/types.ts b/src/core/server/status/types.ts
index b44dde13983bbe..8217b29463700c 100644
--- a/src/core/server/status/types.ts
+++ b/src/core/server/status/types.ts
@@ -7,100 +7,10 @@
*/
import { Observable } from 'rxjs';
-import { deepFreeze } from '@kbn/std';
-import type { PluginName } from '@kbn/core-base-common';
+import type { PluginName, ServiceStatus } from '@kbn/core-base-common';
-/**
- * The current status of a service at a point in time.
- *
- * @typeParam Meta - JSON-serializable object. Plugins should export this type to allow other plugins to read the `meta`
- * field in a type-safe way.
- * @public
- */
-export interface ServiceStatus | unknown = unknown> {
- /**
- * The current availability level of the service.
- */
- level: ServiceStatusLevel;
- /**
- * A high-level summary of the service status.
- */
- summary: string;
- /**
- * A more detailed description of the service status.
- */
- detail?: string;
- /**
- * A URL to open in a new tab about how to resolve or troubleshoot the problem.
- */
- documentationUrl?: string;
- /**
- * Any JSON-serializable data to be included in the HTTP API response. Useful for providing more fine-grained,
- * machine-readable information about the service status. May include status information for underlying features.
- */
- meta?: Meta;
-}
-
-/**
- * The current "level" of availability of a service.
- *
- * @remarks
- * The values implement `valueOf` to allow for easy comparisons between status levels with <, >, etc. Higher values
- * represent higher severities. Note that the default `Array.prototype.sort` implementation does not correctly sort
- * these values.
- *
- * A snapshot serializer is available in `src/core/server/test_utils` to ease testing of these values with Jest.
- *
- * @public
- */
-export const ServiceStatusLevels = deepFreeze({
- /**
- * Everything is working!
- */
- available: {
- toString: () => 'available',
- valueOf: () => 0,
- toJSON() {
- return this.toString();
- },
- },
- /**
- * Some features may not be working.
- */
- degraded: {
- toString: () => 'degraded',
- valueOf: () => 1,
- toJSON() {
- return this.toString();
- },
- },
- /**
- * The service is unavailable, but other functions that do not depend on this service should work.
- */
- unavailable: {
- toString: () => 'unavailable',
- valueOf: () => 2,
- toJSON() {
- return this.toString();
- },
- },
- /**
- * Block all user functions and display the status page, reserved for Core services only.
- */
- critical: {
- toString: () => 'critical',
- valueOf: () => 3,
- toJSON() {
- return this.toString();
- },
- },
-});
-
-/**
- * A convenience type that represents the union of each value in {@link ServiceStatusLevels}.
- * @public
- */
-export type ServiceStatusLevel = typeof ServiceStatusLevels[keyof typeof ServiceStatusLevels];
+export type { ServiceStatusLevel, ServiceStatus } from '@kbn/core-base-common';
+export { ServiceStatusLevels } from '@kbn/core-base-common';
/**
* Status of core services.
diff --git a/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts b/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts
index 98093b685cab2f..4dfcccdbc13f7d 100644
--- a/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts
+++ b/x-pack/plugins/actions/server/builtin_action_types/es_index.test.ts
@@ -19,8 +19,7 @@ import {
ESIndexActionTypeExecutorOptions,
} from './es_index';
import { AlertHistoryEsIndexConnectorId } from '../../common';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
const ACTION_TYPE_ID = '.index';
diff --git a/x-pack/plugins/actions/server/usage/actions_telemetry.test.ts b/x-pack/plugins/actions/server/usage/actions_telemetry.test.ts
index 9fff9f9299ead4..532cefec75f204 100644
--- a/x-pack/plugins/actions/server/usage/actions_telemetry.test.ts
+++ b/x-pack/plugins/actions/server/usage/actions_telemetry.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { getExecutionsPerDayCount, getInUseTotalCount, getTotalCount } from './actions_telemetry';
diff --git a/x-pack/plugins/cloud_security_posture/server/create_transforms/create_transforms.test.ts b/x-pack/plugins/cloud_security_posture/server/create_transforms/create_transforms.test.ts
index 65a4507de2511b..e701e7c94cadaa 100644
--- a/x-pack/plugins/cloud_security_posture/server/create_transforms/create_transforms.test.ts
+++ b/x-pack/plugins/cloud_security_posture/server/create_transforms/create_transforms.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { createTransformIfNotExists, startTransformIfNotStarted } from './create_transforms';
import { latestFindingsTransform } from './latest_findings_transform';
diff --git a/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.test.ts b/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.test.ts
index 2d06ce9f394a79..861fd1365fe4fb 100644
--- a/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.test.ts
+++ b/x-pack/plugins/cloud_security_posture/server/routes/benchmarks/benchmarks.test.ts
@@ -10,10 +10,7 @@ import {
loggingSystemMock,
savedObjectsClientMock,
} from '@kbn/core/server/mocks';
-import {
- ElasticsearchClientMock,
- // eslint-disable-next-line @kbn/eslint/no-restricted-paths
-} from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { KibanaRequest } from '@kbn/core/server';
import {
benchmarksQueryParamsSchema,
@@ -71,6 +68,7 @@ function createMockAgentPolicy(props: Partial = {}): AgentPolicy {
...props,
};
}
+
describe('benchmarks API', () => {
let logger: ReturnType;
diff --git a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.test.ts b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.test.ts
index 587eb53768cc58..ffed0854858af5 100644
--- a/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.test.ts
+++ b/x-pack/plugins/cloud_security_posture/server/routes/compliance_dashboard/compliance_dashboard.test.ts
@@ -5,8 +5,6 @@
* 2.0.
*/
import { httpServerMock, httpServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
-import // eslint-disable-next-line @kbn/eslint/no-restricted-paths
-'@kbn/core/server/elasticsearch/client/mocks';
import type { KibanaRequest } from '@kbn/core/server';
import { defineGetComplianceDashboardRoute } from './compliance_dashboard';
diff --git a/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.test.ts b/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.test.ts
index 4b5ed5ddfc662a..480ffa9bcd10a0 100644
--- a/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.test.ts
+++ b/x-pack/plugins/cloud_security_posture/server/routes/configuration/update_rules_configuration.test.ts
@@ -4,8 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
savedObjectsClientMock,
httpServiceMock,
diff --git a/x-pack/plugins/cloud_security_posture/server/routes/es_pit/es_pit.test.ts b/x-pack/plugins/cloud_security_posture/server/routes/es_pit/es_pit.test.ts
index b540db9f08f7b6..c432e1e0a29689 100644
--- a/x-pack/plugins/cloud_security_posture/server/routes/es_pit/es_pit.test.ts
+++ b/x-pack/plugins/cloud_security_posture/server/routes/es_pit/es_pit.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
import { Chance } from 'chance';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { ElasticsearchClient } from '@kbn/core/server';
import { httpServerMock, httpServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
import { DEFAULT_PIT_KEEP_ALIVE, defineEsPitRoute, esPitInputSchema } from './es_pit';
diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.test.ts
index 5e3ba27a5357b2..d69fd167ee1170 100644
--- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.test.ts
+++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/ingest_pipeline/install.test.ts
@@ -4,8 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { loggerMock } from '@kbn/logging-mocks';
import { getArchiveEntry } from '../../archive/cache';
diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts
index 74e49031861c16..3155380b6c3655 100644
--- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts
+++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/transform/transform.test.ts
@@ -24,8 +24,7 @@ import { loggerMock } from '@kbn/logging-mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { savedObjectsClientMock } from '@kbn/core/server/saved_objects/service/saved_objects_client.mock';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getInstallation, getInstallationObject } from '../../packages';
import type { Installation, RegistryPackage } from '../../../../types';
diff --git a/x-pack/plugins/lists/server/services/items/create_list_item.mock.ts b/x-pack/plugins/lists/server/services/items/create_list_item.mock.ts
index 302b5919fbbdfd..ad0cb15ccfa03d 100644
--- a/x-pack/plugins/lists/server/services/items/create_list_item.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/create_list_item.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/items/create_list_item.test.ts b/x-pack/plugins/lists/server/services/items/create_list_item.test.ts
index ccbfac5819c910..ec8ba2876126ca 100644
--- a/x-pack/plugins/lists/server/services/items/create_list_item.test.ts
+++ b/x-pack/plugins/lists/server/services/items/create_list_item.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/create_list_items_bulk.mock.ts b/x-pack/plugins/lists/server/services/items/create_list_items_bulk.mock.ts
index 68c01610df9889..95ed50235ea32a 100644
--- a/x-pack/plugins/lists/server/services/items/create_list_items_bulk.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/create_list_items_bulk.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/items/delete_list_item.mock.ts b/x-pack/plugins/lists/server/services/items/delete_list_item.mock.ts
index 4b2807fdb5d7fb..b9928c4bd27b99 100644
--- a/x-pack/plugins/lists/server/services/items/delete_list_item.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/delete_list_item.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ITEM_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/delete_list_item_by_value.mock.ts b/x-pack/plugins/lists/server/services/items/delete_list_item_by_value.mock.ts
index 74d7016653c15a..fe0438c07c5548 100644
--- a/x-pack/plugins/lists/server/services/items/delete_list_item_by_value.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/delete_list_item_by_value.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/find_list_item.mock.ts b/x-pack/plugins/lists/server/services/items/find_list_item.mock.ts
index 7e0c18ebbe4879..87428a2773b166 100644
--- a/x-pack/plugins/lists/server/services/items/find_list_item.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/find_list_item.mock.ts
@@ -6,8 +6,7 @@
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_INDEX, LIST_ITEM_INDEX } from '../../../common/constants.mock';
import { getShardMock } from '../../schemas/common/get_shard.mock';
diff --git a/x-pack/plugins/lists/server/services/items/find_list_item.test.ts b/x-pack/plugins/lists/server/services/items/find_list_item.test.ts
index 7eee57887f227e..8b1457f0ce53d3 100644
--- a/x-pack/plugins/lists/server/services/items/find_list_item.test.ts
+++ b/x-pack/plugins/lists/server/services/items/find_list_item.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getFoundListItemSchemaMock } from '../../../common/schemas/response/found_list_item_schema.mock';
import { getShardMock } from '../../schemas/common/get_shard.mock';
diff --git a/x-pack/plugins/lists/server/services/items/get_list_item.test.ts b/x-pack/plugins/lists/server/services/items/get_list_item.test.ts
index 361b8a8b36327a..2c2b703246a5d2 100644
--- a/x-pack/plugins/lists/server/services/items/get_list_item.test.ts
+++ b/x-pack/plugins/lists/server/services/items/get_list_item.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
import {
diff --git a/x-pack/plugins/lists/server/services/items/get_list_item_by_value.mock.ts b/x-pack/plugins/lists/server/services/items/get_list_item_by_value.mock.ts
index 7847b39c9b6bd5..60fbdc4d2ab17a 100644
--- a/x-pack/plugins/lists/server/services/items/get_list_item_by_value.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/get_list_item_by_value.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/get_list_item_by_values.mock.ts b/x-pack/plugins/lists/server/services/items/get_list_item_by_values.mock.ts
index 4efa627b90cdfd..d248481b9e6a0f 100644
--- a/x-pack/plugins/lists/server/services/items/get_list_item_by_values.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/get_list_item_by_values.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE, VALUE_2 } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/get_list_item_by_values.test.ts b/x-pack/plugins/lists/server/services/items/get_list_item_by_values.test.ts
index 5d6bef3db9fe70..9f0b183b97b5c1 100644
--- a/x-pack/plugins/lists/server/services/items/get_list_item_by_values.test.ts
+++ b/x-pack/plugins/lists/server/services/items/get_list_item_by_values.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/items/search_list_item_by_values.mock.ts b/x-pack/plugins/lists/server/services/items/search_list_item_by_values.mock.ts
index 4b085a990627d0..5fb965dec55858 100644
--- a/x-pack/plugins/lists/server/services/items/search_list_item_by_values.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/search_list_item_by_values.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE, VALUE_2 } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/search_list_item_by_values.test.ts b/x-pack/plugins/lists/server/services/items/search_list_item_by_values.test.ts
index 5b75860297ae62..7673347d488dd4 100644
--- a/x-pack/plugins/lists/server/services/items/search_list_item_by_values.test.ts
+++ b/x-pack/plugins/lists/server/services/items/search_list_item_by_values.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { SearchListItemArraySchema } from '@kbn/securitysolution-io-ts-list-types';
import { LIST_ID, LIST_ITEM_INDEX, TYPE, VALUE, VALUE_2 } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/items/update_list_item.mock.ts b/x-pack/plugins/lists/server/services/items/update_list_item.mock.ts
index c68b278e6b7356..307e4e190be91e 100644
--- a/x-pack/plugins/lists/server/services/items/update_list_item.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/update_list_item.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/items/update_list_item.test.ts b/x-pack/plugins/lists/server/services/items/update_list_item.test.ts
index c3ff32d4e5074a..14fe97638e7101 100644
--- a/x-pack/plugins/lists/server/services/items/update_list_item.test.ts
+++ b/x-pack/plugins/lists/server/services/items/update_list_item.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { ListItemSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getListItemResponseMock } from '../../../common/schemas/response/list_item_schema.mock';
diff --git a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.mock.ts b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.mock.ts
index ff0baba16576d2..9a2d1f6a500bfc 100644
--- a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
LIST_ID,
diff --git a/x-pack/plugins/lists/server/services/items/write_list_items_to_stream.test.ts b/x-pack/plugins/lists/server/services/items/write_list_items_to_stream.test.ts
index 0a5395d022b633..0c12d38fb97463 100644
--- a/x-pack/plugins/lists/server/services/items/write_list_items_to_stream.test.ts
+++ b/x-pack/plugins/lists/server/services/items/write_list_items_to_stream.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
import { getSearchListItemMock } from '../../schemas/elastic_response/search_es_list_item_schema.mock';
diff --git a/x-pack/plugins/lists/server/services/items/write_list_items_to_streams.mock.ts b/x-pack/plugins/lists/server/services/items/write_list_items_to_streams.mock.ts
index b725ed7856e917..95203974440757 100644
--- a/x-pack/plugins/lists/server/services/items/write_list_items_to_streams.mock.ts
+++ b/x-pack/plugins/lists/server/services/items/write_list_items_to_streams.mock.ts
@@ -7,8 +7,7 @@
import { Stream } from 'stream';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_ITEM_INDEX } from '../../../common/constants.mock';
import { getSearchListItemMock } from '../../schemas/elastic_response/search_es_list_item_schema.mock';
diff --git a/x-pack/plugins/lists/server/services/lists/create_list.mock.ts b/x-pack/plugins/lists/server/services/lists/create_list.mock.ts
index 3b5522ea4f5a8e..19ff08a15c5062 100644
--- a/x-pack/plugins/lists/server/services/lists/create_list.mock.ts
+++ b/x-pack/plugins/lists/server/services/lists/create_list.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/lists/create_list.test.ts b/x-pack/plugins/lists/server/services/lists/create_list.test.ts
index 1a9a6977ac907f..96744d9f55bae7 100644
--- a/x-pack/plugins/lists/server/services/lists/create_list.test.ts
+++ b/x-pack/plugins/lists/server/services/lists/create_list.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { ListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
diff --git a/x-pack/plugins/lists/server/services/lists/delete_list.mock.ts b/x-pack/plugins/lists/server/services/lists/delete_list.mock.ts
index fc8bdc797465cf..172488a9d741dc 100644
--- a/x-pack/plugins/lists/server/services/lists/delete_list.mock.ts
+++ b/x-pack/plugins/lists/server/services/lists/delete_list.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { LIST_ID, LIST_INDEX, LIST_ITEM_INDEX } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/lists/get_list.test.ts b/x-pack/plugins/lists/server/services/lists/get_list.test.ts
index aa04539c687c94..b027d3e6933499 100644
--- a/x-pack/plugins/lists/server/services/lists/get_list.test.ts
+++ b/x-pack/plugins/lists/server/services/lists/get_list.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
import { LIST_ID, LIST_INDEX } from '../../../common/constants.mock';
diff --git a/x-pack/plugins/lists/server/services/lists/list_client.mock.ts b/x-pack/plugins/lists/server/services/lists/list_client.mock.ts
index 6ad3985ccddbf4..5489722f401210 100644
--- a/x-pack/plugins/lists/server/services/lists/list_client.mock.ts
+++ b/x-pack/plugins/lists/server/services/lists/list_client.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getFoundListItemSchemaMock } from '../../../common/schemas/response/found_list_item_schema.mock';
import { getFoundListSchemaMock } from '../../../common/schemas/response/found_list_schema.mock';
diff --git a/x-pack/plugins/lists/server/services/lists/update_list.mock.ts b/x-pack/plugins/lists/server/services/lists/update_list.mock.ts
index 5b8742b8bf5b30..f0f57a52f65ff6 100644
--- a/x-pack/plugins/lists/server/services/lists/update_list.mock.ts
+++ b/x-pack/plugins/lists/server/services/lists/update_list.mock.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
DATE_NOW,
diff --git a/x-pack/plugins/lists/server/services/lists/update_list.test.ts b/x-pack/plugins/lists/server/services/lists/update_list.test.ts
index 9d0f9a9d775a37..8e68acd3588617 100644
--- a/x-pack/plugins/lists/server/services/lists/update_list.test.ts
+++ b/x-pack/plugins/lists/server/services/lists/update_list.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { ListSchema } from '@kbn/securitysolution-io-ts-list-types';
import { getListResponseMock } from '../../../common/schemas/response/list_schema.mock';
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_ccr_read_exceptions.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_ccr_read_exceptions.test.ts
index c6f63b0a8a63ca..23de6bd1016732 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_ccr_read_exceptions.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_ccr_read_exceptions.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchCCRReadExceptions } from './fetch_ccr_read_exceptions';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_cluster_health.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_cluster_health.test.ts
index 1c369c159595ae..d87792f347eb0e 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_cluster_health.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_cluster_health.test.ts
@@ -6,8 +6,7 @@
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchClusterHealth } from './fetch_cluster_health';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts
index af90f99eb82886..5d7505c492da45 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_cpu_usage_node_stats.test.ts
@@ -6,8 +6,7 @@
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchCpuUsageNodeStats } from './fetch_cpu_usage_node_stats';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_memory_usage_node_stats.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_memory_usage_node_stats.test.ts
index d717edf9feb435..06227c53b25fac 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_memory_usage_node_stats.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_memory_usage_node_stats.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchMemoryUsageNodeStats } from './fetch_memory_usage_node_stats';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts
index 90cfbc96617cbb..a0c5e1b2472431 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_missing_monitoring_data.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchMissingMonitoringData } from './fetch_missing_monitoring_data';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring/server/lib/alerts/fetch_nodes_from_cluster_stats.test.ts b/x-pack/plugins/monitoring/server/lib/alerts/fetch_nodes_from_cluster_stats.test.ts
index 12c49f89aa4871..fe03ffec6d137e 100644
--- a/x-pack/plugins/monitoring/server/lib/alerts/fetch_nodes_from_cluster_stats.test.ts
+++ b/x-pack/plugins/monitoring/server/lib/alerts/fetch_nodes_from_cluster_stats.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchNodesFromClusterStats } from './fetch_nodes_from_cluster_stats';
jest.mock('../../static_globals', () => ({
diff --git a/x-pack/plugins/monitoring_collection/server/lib/get_es_cluster_uuid.test.ts b/x-pack/plugins/monitoring_collection/server/lib/get_es_cluster_uuid.test.ts
index 1e60b49181dec4..8b28221947a2d3 100644
--- a/x-pack/plugins/monitoring_collection/server/lib/get_es_cluster_uuid.test.ts
+++ b/x-pack/plugins/monitoring_collection/server/lib/get_es_cluster_uuid.test.ts
@@ -4,8 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getESClusterUuid } from '.';
describe('getESClusterUuid', () => {
diff --git a/x-pack/plugins/monitoring_collection/server/routes/api/v1/dynamic_route/get_metrics_by_type.test.ts b/x-pack/plugins/monitoring_collection/server/routes/api/v1/dynamic_route/get_metrics_by_type.test.ts
index edc6c6cef7c8ee..92ff711006a25f 100644
--- a/x-pack/plugins/monitoring_collection/server/routes/api/v1/dynamic_route/get_metrics_by_type.test.ts
+++ b/x-pack/plugins/monitoring_collection/server/routes/api/v1/dynamic_route/get_metrics_by_type.test.ts
@@ -8,8 +8,7 @@
import { registerDynamicRoute } from '.';
import { KibanaRequest, KibanaResponseFactory, ServiceStatusLevels } from '@kbn/core/server';
import { httpServerMock, httpServiceMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
beforeEach(() => {
jest.resetAllMocks();
diff --git a/x-pack/plugins/rule_registry/server/alert_data_client/tests/bulk_update.test.ts b/x-pack/plugins/rule_registry/server/alert_data_client/tests/bulk_update.test.ts
index 3f9143ac7922b1..bf3e1e9d919944 100644
--- a/x-pack/plugins/rule_registry/server/alert_data_client/tests/bulk_update.test.ts
+++ b/x-pack/plugins/rule_registry/server/alert_data_client/tests/bulk_update.test.ts
@@ -14,8 +14,7 @@ import {
} from '@kbn/rule-data-utils';
import { AlertsClient, ConstructorOptions } from '../alerts_client';
import { loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { alertingAuthorizationMock } from '@kbn/alerting-plugin/server/authorization/alerting_authorization.mock';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { AlertingAuthorizationEntity } from '@kbn/alerting-plugin/server';
diff --git a/x-pack/plugins/rule_registry/server/alert_data_client/tests/find_alerts.test.ts b/x-pack/plugins/rule_registry/server/alert_data_client/tests/find_alerts.test.ts
index 00c034b980109d..bdb278cb2a3bab 100644
--- a/x-pack/plugins/rule_registry/server/alert_data_client/tests/find_alerts.test.ts
+++ b/x-pack/plugins/rule_registry/server/alert_data_client/tests/find_alerts.test.ts
@@ -13,8 +13,7 @@ import {
} from '@kbn/rule-data-utils';
import { AlertsClient, ConstructorOptions } from '../alerts_client';
import { loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { alertingAuthorizationMock } from '@kbn/alerting-plugin/server/authorization/alerting_authorization.mock';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { AlertingAuthorizationEntity } from '@kbn/alerting-plugin/server';
diff --git a/x-pack/plugins/rule_registry/server/alert_data_client/tests/get.test.ts b/x-pack/plugins/rule_registry/server/alert_data_client/tests/get.test.ts
index a9bfe02443f731..58a9e2cec235fb 100644
--- a/x-pack/plugins/rule_registry/server/alert_data_client/tests/get.test.ts
+++ b/x-pack/plugins/rule_registry/server/alert_data_client/tests/get.test.ts
@@ -14,8 +14,7 @@ import {
} from '@kbn/rule-data-utils';
import { AlertsClient, ConstructorOptions } from '../alerts_client';
import { loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { alertingAuthorizationMock } from '@kbn/alerting-plugin/server/authorization/alerting_authorization.mock';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { AlertingAuthorizationEntity } from '@kbn/alerting-plugin/server';
diff --git a/x-pack/plugins/rule_registry/server/alert_data_client/tests/update.test.ts b/x-pack/plugins/rule_registry/server/alert_data_client/tests/update.test.ts
index 785926656b825f..ef2cc30c891e74 100644
--- a/x-pack/plugins/rule_registry/server/alert_data_client/tests/update.test.ts
+++ b/x-pack/plugins/rule_registry/server/alert_data_client/tests/update.test.ts
@@ -13,8 +13,7 @@ import {
} from '@kbn/rule-data-utils';
import { AlertsClient, ConstructorOptions } from '../alerts_client';
import { loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { alertingAuthorizationMock } from '@kbn/alerting-plugin/server/authorization/alerting_authorization.mock';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { AlertingAuthorizationEntity } from '@kbn/alerting-plugin/server';
diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/metadata/check_metadata_transforms_task.test.ts b/x-pack/plugins/security_solution/server/endpoint/lib/metadata/check_metadata_transforms_task.test.ts
index e9c088d17e00ad..84d124a398a93f 100644
--- a/x-pack/plugins/security_solution/server/endpoint/lib/metadata/check_metadata_transforms_task.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/lib/metadata/check_metadata_transforms_task.test.ts
@@ -19,8 +19,7 @@ import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
import type { TaskManagerSetupContract } from '@kbn/task-manager-plugin/server';
import { TaskStatus } from '@kbn/task-manager-plugin/server';
import type { CoreSetup } from '@kbn/core/server';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import type { ElasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { TRANSFORM_STATES } from '../../../../common/constants';
import { METADATA_TRANSFORMS_PATTERN } from '../../../../common/endpoint/constants';
import type { RunResult } from '@kbn/task-manager-plugin/server/task';
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts
index 36ae8d9f95af3c..5746e1e93f9bb9 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/metadata/metadata.test.ts
@@ -57,8 +57,7 @@ import { AgentNotFoundError } from '@kbn/fleet-plugin/server';
import type {
ClusterClientMock,
ScopedClusterClientMock,
- // eslint-disable-next-line @kbn/eslint/no-restricted-paths
-} from '@kbn/core/server/elasticsearch/client/mocks';
+} from '@kbn/core-elasticsearch-client-server-mocks';
import { EndpointHostNotFoundError } from '../../services/metadata';
import { FleetAgentGenerator } from '../../../../common/endpoint/data_generators/fleet_agent_generator';
import { createMockAgentClient, createMockPackageService } from '@kbn/fleet-plugin/server/mocks';
diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts b/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts
index 7cd02dace23ea8..a9a7c7c4837e34 100644
--- a/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/routes/policy/handlers.test.ts
@@ -31,8 +31,7 @@ import {
import type { Agent } from '@kbn/fleet-plugin/common/types/models';
import type { AgentClient, AgentService } from '@kbn/fleet-plugin/server/services';
import { get } from 'lodash';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import type { ScopedClusterClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ScopedClusterClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
describe('test policy response handler', () => {
let endpointAppContextService: EndpointAppContextService;
diff --git a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/mocks.ts b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/mocks.ts
index 5fa55f9a3cbba5..814dd457347ab7 100644
--- a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/mocks.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/mocks.ts
@@ -7,8 +7,7 @@
import type { SavedObjectsClientContract } from '@kbn/core/server';
import { savedObjectsClientMock, elasticsearchServiceMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import type { ElasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
// Because mocks are for testing only, should be ok to import the FleetArtifactsClient directly
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FleetArtifactsClient } from '@kbn/fleet-plugin/server/services';
diff --git a/x-pack/plugins/security_solution/server/endpoint/services/metadata/endpoint_metadata_service.test.ts b/x-pack/plugins/security_solution/server/endpoint/services/metadata/endpoint_metadata_service.test.ts
index adc41b3ec7df81..2e7d606e10f5d1 100644
--- a/x-pack/plugins/security_solution/server/endpoint/services/metadata/endpoint_metadata_service.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/services/metadata/endpoint_metadata_service.test.ts
@@ -8,8 +8,7 @@
import type { EndpointMetadataServiceTestContextMock } from './mocks';
import { createEndpointMetadataServiceTestContextMock } from './mocks';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import type { ElasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
legacyMetadataSearchResponseMock,
unitedMetadataSearchResponseMock,
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.test.ts
index 002b4c2264eee6..40c82c255c1f5f 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.test.ts
@@ -8,8 +8,7 @@
import { readPrivilegesRoute } from './read_privileges_route';
import { serverMock, requestContextMock } from '../__mocks__';
import { getPrivilegeRequest, getMockPrivilegesResult } from '../__mocks__/request_responses';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
describe('read_privileges route', () => {
let server: ReturnType;
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.test.ts
index f56a1a4be67d33..6c6cfde2cbaa8f 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.test.ts
@@ -18,8 +18,7 @@ import { addPrepackedRulesRoute, createPrepackagedRules } from './add_prepackage
import { listMock } from '@kbn/lists-plugin/server/mocks';
import type { ExceptionListClient } from '@kbn/lists-plugin/server';
import { installPrepackagedTimelines } from '../../../timeline/routes/prepackaged_timelines/install_prepackaged_timelines';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getQueryRuleParams } from '../../schemas/rule_schemas.mock';
import { legacyMigrate } from '../../rules/utils';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.test.ts
index 8b23aca24c791e..c845f2e0a381c0 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.test.ts
@@ -20,8 +20,7 @@ import {
import { requestContextMock, serverMock, requestMock } from '../__mocks__';
import { createRulesBulkRoute } from './create_rules_bulk_route';
import { getCreateRulesSchemaMock } from '../../../../../common/detection_engine/schemas/request/rule_schemas.mock';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getQueryRuleParams } from '../../schemas/rule_schemas.mock';
import { loggingSystemMock } from '@kbn/core/server/mocks';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.test.ts
index 163a6b8e432299..658461f148cb89 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.test.ts
@@ -20,8 +20,7 @@ import { buildMlAuthz } from '../../../machine_learning/authz';
import { requestContextMock, serverMock, requestMock } from '../__mocks__';
import { createRulesRoute } from './create_rules_route';
import { getCreateRulesSchemaMock } from '../../../../../common/detection_engine/schemas/request/rule_schemas.mock';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getQueryRuleParams } from '../../schemas/rule_schemas.mock';
jest.mock('../../../machine_learning/authz', () => mockMlAuthzFactory.create());
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
index 578ba7786780b2..bf83471631a8cd 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.test.ts
@@ -25,8 +25,7 @@ import {
ruleIdsToNdJsonString,
rulesToNdJsonString,
} from '../../../../../common/detection_engine/schemas/request/import_rules_schema.mock';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getQueryRuleParams } from '../../schemas/rule_schemas.mock';
jest.mock('../../../machine_learning/authz', () => mockMlAuthzFactory.create());
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/query/create_query_alert_type.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/query/create_query_alert_type.test.ts
index 91d92a4d076ef3..4a6b6b3c9d867d 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/query/create_query_alert_type.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_types/query/create_query_alert_type.test.ts
@@ -5,8 +5,7 @@
* 2.0.
*/
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { allowedExperimentalValues } from '../../../../../common/experimental_features';
import { createQueryAlertType } from './create_query_alert_type';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threshold.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threshold.test.ts
index e21e8ae21d91fd..79966e6d9887fb 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threshold.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/executors/threshold.test.ts
@@ -7,8 +7,7 @@
import dateMath from '@kbn/datemath';
import { loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import type { RuleExecutorServicesMock } from '@kbn/alerting-plugin/server/mocks';
import { alertsMock } from '@kbn/alerting-plugin/server/mocks';
import { thresholdExecutor } from './threshold';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.test.ts
index 88f12f71576833..bcc70e3fb735f4 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/search_after_bulk_create.test.ts
@@ -24,8 +24,7 @@ import type { BulkCreate, BulkResponse, RuleRangeTuple, WrapHits } from './types
import type { SearchListItemArraySchema } from '@kbn/securitysolution-io-ts-list-types';
import { getSearchListItemResponseMock } from '@kbn/lists-plugin/common/schemas/response/search_list_item_schema.mock';
import { getRuleRangeTuples } from './utils';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { getCompleteRuleMock, getQueryRuleParams } from '../schemas/rule_schemas.mock';
import { bulkCreateFactory } from '../rule_types/factories/bulk_create_factory';
import { wrapHitsFactory } from '../rule_types/factories/wrap_hits_factory';
diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/single_search_after.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/single_search_after.test.ts
index f2411b8a981bce..b75eb81eb41634 100644
--- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/single_search_after.test.ts
+++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/single_search_after.test.ts
@@ -14,8 +14,7 @@ import { singleSearchAfter } from './single_search_after';
import type { RuleExecutorServicesMock } from '@kbn/alerting-plugin/server/mocks';
import { alertsMock } from '@kbn/alerting-plugin/server/mocks';
import { buildRuleMessageFactory } from './rule_messages';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
const buildRuleMessage = buildRuleMessageFactory({
id: 'fake id',
diff --git a/x-pack/plugins/stack_alerts/server/alert_types/es_query/rule_type.test.ts b/x-pack/plugins/stack_alerts/server/alert_types/es_query/rule_type.test.ts
index 8e54a9ac9da8f6..ad3c96c69cde30 100644
--- a/x-pack/plugins/stack_alerts/server/alert_types/es_query/rule_type.test.ts
+++ b/x-pack/plugins/stack_alerts/server/alert_types/es_query/rule_type.test.ts
@@ -18,8 +18,7 @@ import { getRuleType } from './rule_type';
import { EsQueryRuleParams, EsQueryRuleState } from './rule_type_params';
import { ActionContext } from './action_context';
import { ESSearchResponse, ESSearchRequest } from '@kbn/core/types/elasticsearch';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { elasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { coreMock } from '@kbn/core/server/mocks';
import { ActionGroupId, ConditionMetAlertInstanceId } from './constants';
import { OnlyEsQueryRuleParams, OnlySearchSourceRuleParams } from './types';
diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/helper.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/helper.ts
index 315b0bd3d0f968..96de0a435ee727 100644
--- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/helper.ts
+++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/helper.ts
@@ -6,8 +6,7 @@
*/
import { AggregationsAggregate } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { ElasticsearchClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { elasticsearchServiceMock, savedObjectsClientMock } from '@kbn/core/server/mocks';
import { createUptimeESClient, UptimeESClient } from '../lib';
diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.test.ts
index c17cc160a6ce16..3afe9b3b54bad7 100644
--- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.test.ts
+++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_actions.test.ts
@@ -7,8 +7,7 @@
import { SavedObjectsErrorHelpers } from '@kbn/core/server';
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { ScopedClusterClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ScopedClusterClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import moment from 'moment';
import {
diff --git a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_service.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_service.test.ts
index 062782560ef2ba..ae979ddcf9d220 100644
--- a/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_service.test.ts
+++ b/x-pack/plugins/upgrade_assistant/server/lib/reindexing/reindex_service.test.ts
@@ -10,8 +10,7 @@ import { BehaviorSubject } from 'rxjs';
import { TransportResult } from '@elastic/elasticsearch';
import { Logger } from '@kbn/core/server';
import { elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks';
-// eslint-disable-next-line @kbn/eslint/no-restricted-paths
-import { ScopedClusterClientMock } from '@kbn/core/server/elasticsearch/client/mocks';
+import type { ScopedClusterClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import {
ReindexOperation,
diff --git a/yarn.lock b/yarn.lock
index 032bc7f3a24233..03d0d3695ab270 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3163,6 +3163,30 @@
version "0.0.0"
uid ""
+"@kbn/core-elasticsearch-client-server-internal@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-internal":
+ version "0.0.0"
+ uid ""
+
+"@kbn/core-elasticsearch-client-server-mocks@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-mocks":
+ version "0.0.0"
+ uid ""
+
+"@kbn/core-elasticsearch-client-server@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server":
+ version "0.0.0"
+ uid ""
+
+"@kbn/core-elasticsearch-server-internal@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-internal":
+ version "0.0.0"
+ uid ""
+
+"@kbn/core-elasticsearch-server-mocks@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-mocks":
+ version "0.0.0"
+ uid ""
+
+"@kbn/core-elasticsearch-server@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server":
+ version "0.0.0"
+ uid ""
+
"@kbn/core-environment-server-internal@link:bazel-bin/packages/core/environment/core-environment-server-internal":
version "0.0.0"
uid ""
@@ -6894,6 +6918,30 @@
version "0.0.0"
uid ""
+"@types/kbn__core-elasticsearch-client-server-internal@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-internal/npm_module_types":
+ version "0.0.0"
+ uid ""
+
+"@types/kbn__core-elasticsearch-client-server-mocks@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server-mocks/npm_module_types":
+ version "0.0.0"
+ uid ""
+
+"@types/kbn__core-elasticsearch-client-server@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-client-server/npm_module_types":
+ version "0.0.0"
+ uid ""
+
+"@types/kbn__core-elasticsearch-server-internal@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-internal/npm_module_types":
+ version "0.0.0"
+ uid ""
+
+"@types/kbn__core-elasticsearch-server-mocks@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server-mocks/npm_module_types":
+ version "0.0.0"
+ uid ""
+
+"@types/kbn__core-elasticsearch-server@link:bazel-bin/packages/core/elasticsearch/core-elasticsearch-server/npm_module_types":
+ version "0.0.0"
+ uid ""
+
"@types/kbn__core-environment-server-internal@link:bazel-bin/packages/core/environment/core-environment-server-internal/npm_module_types":
version "0.0.0"
uid ""