From b8b16853014ff6e85f55425500fd1b76b7e00dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Thu, 19 Dec 2024 03:09:02 +0100 Subject: [PATCH 1/6] [ES `body` removal] `@elastic/kibana-core` --- .../src/is_scripting_enabled.test.ts | 2 +- .../src/lib/apis/bulk_delete.test.ts | 2 +- .../src/lib/apis/bulk_get.isolated.test.ts | 2 +- .../src/lib/apis/bulk_get.test.ts | 2 +- .../src/lib/apis/bulk_update.test.ts | 2 +- .../src/lib/apis/check_conflicts.test.ts | 2 +- .../src/lib/apis/create.test.ts | 10 ++--- .../src/lib/apis/delete.test.ts | 2 +- .../src/lib/apis/find.isolated.test.ts | 2 +- .../src/lib/apis/find.ts | 2 +- .../src/lib/apis/get.test.ts | 2 +- .../src/lib/apis/increment_counter.test.ts | 2 +- .../apis/internals/internal_bulk_resolve.ts | 2 +- .../internals/preflight_check_for_create.ts | 2 +- .../apis/internals/update_objects_spaces.ts | 2 +- .../src/lib/apis/remove_references_to.test.ts | 2 +- .../src/lib/apis/update.test.ts | 28 +++++++------- .../src/lib/apis/utils/es_responses.ts | 2 +- .../src/lib/apis/utils/internal_utils.ts | 2 +- .../src/lib/apis/utils/merge_for_update.ts | 2 +- .../src/lib/point_in_time_finder.ts | 2 +- .../repository.encryption_extension.test.ts | 2 +- .../lib/repository.spaces_extension.test.ts | 2 +- .../search/aggregations/validation.test.ts | 2 +- .../src/lib/search/aggregations/validation.ts | 2 +- .../src/lib/search/search_dsl/search_dsl.ts | 2 +- .../lib/search/search_dsl/sorting_params.ts | 2 +- .../test_helpers/repository.test.common.ts | 2 +- .../src/apis/find.ts | 2 +- .../src/utils/get_field_list.ts | 2 +- .../bulk_overwrite_transformed_documents.ts | 2 +- .../src/actions/create_index.ts | 2 +- .../src/actions/read_with_pit.ts | 2 +- .../src/mapping_definition.ts | 2 +- .../src/saved_objects_type.ts | 2 +- .../src/core_usage_data_service.ts | 2 +- packages/kbn-es-types/index.ts | 1 - packages/kbn-es-types/src/index.ts | 9 +---- packages/kbn-es-types/src/search.ts | 10 ++--- .../group3/actions/es_errors.test.ts | 2 +- .../get_local_stats.test.ts | 2 +- .../telemetry_collection/get_local_stats.ts | 2 +- .../telemetry_collection/get_nodes_usage.ts | 2 +- .../licensing/server/license_fetcher.test.ts | 2 +- .../licensing/server/license_fetcher.ts | 2 +- .../plugins/licensing/server/plugin.test.ts | 2 +- .../telemetry_collection/get_license.ts | 2 +- .../get_stats_with_xpack.test.ts | 2 +- .../apps/group3/upgrade_assistant.ts | 38 +++++++++---------- 49 files changed, 87 insertions(+), 95 deletions(-) diff --git a/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts index d77121cec13c0..e94981d88966b 100644 --- a/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts +++ b/packages/core/elasticsearch/core-elasticsearch-server-internal/src/is_scripting_enabled.test.ts @@ -8,7 +8,7 @@ */ import { isRetryableEsClientErrorMock } from './is_scripting_enabled.test.mocks'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import { isInlineScriptingEnabled } from './is_scripting_enabled'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts index d0efc5bf6be4f..249e1542455eb 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts @@ -18,7 +18,7 @@ import { } from '../repository.test.mock'; import type { Payload } from '@hapi/boom'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsBulkDeleteObject, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.isolated.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.isolated.test.ts index 792bc652b0f6a..9c24ab6d68d4e 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.isolated.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.isolated.test.ts @@ -11,7 +11,7 @@ import { getSavedObjectFromSourceMock, rawDocExistsInNamespaceMock, } from './bulk_get.isolated.test.mocks'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { SavedObject, CheckAuthorizationResult } from '@kbn/core-saved-objects-server'; import { apiContextMock, ApiExecutionContextMock } from '../../mocks'; import { performBulkGet } from './bulk_get'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts index 3e5310952c116..5a21c742dd5de 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts @@ -15,7 +15,7 @@ import { } from '../repository.test.mock'; import type { Payload } from '@hapi/boom'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsBulkGetObject } from '@kbn/core-saved-objects-api-server'; import { type SavedObjectsRawDocSource, type SavedObject } from '@kbn/core-saved-objects-server'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts index 183c33e6f4079..bc1822ac7849b 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts @@ -17,7 +17,7 @@ import { } from '../repository.test.mock'; import type { Payload } from '@hapi/boom'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsBulkUpdateObject, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts index 2858ae5288819..6104ed0466455 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts @@ -13,7 +13,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; import { SavedObjectsRepository } from '../repository'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts index b1a3c951613d2..8b19a92c44983 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts @@ -16,7 +16,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsCreateOptions } from '@kbn/core-saved-objects-api-server'; import { @@ -234,8 +234,8 @@ describe('#create', () => { it(`defaults to empty references array`, async () => { await createSuccess(type, attributes, { id }); expect( - (client.create.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.create.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual([]); }); @@ -244,7 +244,7 @@ describe('#create', () => { await createSuccess(type, attributes, { id, references }); expect( (client.create.mock.calls[0][0] as estypes.CreateRequest) - .body!.references + .document!.references ).toEqual(references); client.create.mockClear(); }; @@ -259,7 +259,7 @@ describe('#create', () => { await createSuccess(type, attributes, { id, references }); expect( (client.create.mock.calls[0][0] as estypes.CreateRequest) - .body!.references + .document!.references ).not.toBeDefined(); client.create.mockClear(); }; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete.test.ts index 1c501b1fb5ec5..d788c5edff65e 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete.test.ts @@ -16,7 +16,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsDeleteOptions } from '@kbn/core-saved-objects-api-server'; import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.isolated.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.isolated.test.ts index f92e074ec4a26..a3d5778083574 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.isolated.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.isolated.test.ts @@ -8,7 +8,7 @@ */ import { isSupportedEsServerMock } from './find.isolated.test.mocks'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { SavedObject, AuthorizationTypeMap } from '@kbn/core-saved-objects-server'; import { apiContextMock, ApiExecutionContextMock } from '../../mocks'; import { performFind } from './find'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts index 40501a0d80a37..662b3759f5133 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts @@ -8,7 +8,7 @@ */ import Boom from '@hapi/boom'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { isSupportedEsServer } from '@kbn/core-elasticsearch-server-internal'; import { SavedObjectsErrorHelpers, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/get.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/get.test.ts index b04f7266b85f4..501e3b8a587cf 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/get.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/get.test.ts @@ -15,7 +15,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsBaseOptions } from '@kbn/core-saved-objects-api-server'; import { ALL_NAMESPACES_STRING } from '@kbn/core-saved-objects-utils-server'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts index b4062ecbe7f2b..0db217b927fa5 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts @@ -16,7 +16,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsIncrementCounterField, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts index 208056be6fc92..7a3a6c00db82f 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/types'; import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal'; import type { diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts index 341c65e722dd5..5f9a71e84eb32 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal'; import { type ISavedObjectTypeRegistry, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts index e3e7fcf42bb88..9dc10c77e4a09 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts @@ -8,7 +8,7 @@ */ import pMap from 'p-map'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import intersection from 'lodash/intersection'; import type { Logger } from '@kbn/logging'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts index e8dc5a4fe5fb1..81466f05aa62f 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts @@ -15,7 +15,7 @@ import { mockGetSearchDsl, } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { SavedObjectsRepository } from '../repository'; import { loggerMock } from '@kbn/logging-mocks'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts index 728f8c42ce71b..1de72f31b80a0 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts @@ -11,7 +11,7 @@ import { mockGetCurrentTime, mockPreflightCheckForCreate } from '../repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { type SavedObjectUnsanitizedDoc, type SavedObjectReference, @@ -250,8 +250,8 @@ describe('#update', () => { migrator.migrateDocument.mockImplementationOnce((doc) => ({ ...doc })); await updateSuccess(client, repository, registry, type, id, attributes); expect( - (client.index.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.index.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual([]); // we're indexing a full new doc, serializer adds default if not defined }); @@ -262,8 +262,8 @@ describe('#update', () => { references, }); expect( - (client.index.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.index.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual(references); client.index.mockClear(); }; @@ -277,8 +277,8 @@ describe('#update', () => { references, }); expect( - (client.index.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.index.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual(references); client.index.mockClear(); }; @@ -292,8 +292,8 @@ describe('#update', () => { references, }); expect( - (client.index.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.index.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual(references); client.index.mockClear(); }; @@ -324,7 +324,8 @@ describe('#update', () => { ...mockTimestampFieldsWithCreated, }; expect( - (client.create.mock.calls[0][0] as estypes.CreateRequest).body! + (client.create.mock.calls[0][0] as estypes.CreateRequest) + .document! ).toEqual(expected); }); @@ -357,7 +358,8 @@ describe('#update', () => { ...mockTimestampFieldsWithCreated, }; expect( - (client.create.mock.calls[0][0] as estypes.CreateRequest).body! + (client.create.mock.calls[0][0] as estypes.CreateRequest) + .document! ).toEqual(expectedType); }); @@ -403,8 +405,8 @@ describe('#update', () => { references, }); expect( - (client.index.mock.calls[0][0] as estypes.CreateRequest).body! - .references + (client.index.mock.calls[0][0] as estypes.CreateRequest) + .document!.references ).toEqual([]); client.index.mockClear(); client.create.mockClear(); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/es_responses.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/es_responses.ts index 70979081bc960..0079d276bbe29 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/es_responses.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/es_responses.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; /** * Type and type guard function for converting a possibly not existent doc to an existent doc. diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/internal_utils.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/internal_utils.ts index fed582f5c43d9..411d452b1a82f 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/internal_utils.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/internal_utils.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { Payload } from '@hapi/boom'; import { SavedObjectsErrorHelpers, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/merge_for_update.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/merge_for_update.ts index 909ac19a18d6c..a930b0841b3df 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/merge_for_update.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/utils/merge_for_update.ts @@ -9,7 +9,7 @@ import { isPlainObject } from 'lodash'; import { set } from '@kbn/safer-lodash-set'; -import type { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsTypeMappingDefinition, SavedObjectsFieldMapping, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/point_in_time_finder.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/point_in_time_finder.ts index cce8ca83dc5d9..7342690a4024a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/point_in_time_finder.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/point_in_time_finder.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { Logger } from '@kbn/logging'; import type { SavedObjectsFindOptions, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts index cf66621565577..a02c20b2db9a4 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts @@ -14,7 +14,7 @@ import { mockGetSearchDsl, } from './repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { SavedObjectsRepository } from './repository'; import { loggerMock } from '@kbn/logging-mocks'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts index d91effdb90f19..73e663133007a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts @@ -18,7 +18,7 @@ import { mockDeleteLegacyUrlAliases, } from './repository.test.mock'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { SavedObjectsRepository } from './repository'; import { loggerMock } from '@kbn/logging-mocks'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.test.ts index f7337ba2ca5dd..79cfd0c582458 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.test.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { validateAndConvertAggregations } from './validation'; type AggsMap = Record; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.ts index 2345261284519..3ee6d7077499a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/aggregations/validation.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { ObjectType } from '@kbn/config-schema'; import { isPlainObject, isArray } from 'lodash'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/search_dsl.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/search_dsl.ts index 639798aa27ec8..90bb8ae96fb8f 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/search_dsl.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/search_dsl.ts @@ -9,7 +9,7 @@ import Boom from '@hapi/boom'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server'; import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; import type { IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/sorting_params.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/sorting_params.ts index d64c290da0569..c62f12dac8002 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/sorting_params.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/search/search_dsl/sorting_params.ts @@ -8,7 +8,7 @@ */ import Boom from '@hapi/boom'; -import type { SortOrder, SortCombinations } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { SortOrder, SortCombinations } from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsPitParams } from '@kbn/core-saved-objects-api-server/src/apis'; import { getProperty, type IndexMapping } from '@kbn/core-saved-objects-base-server-internal'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts index 5670062c69ef2..25be3695db92f 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import { schema } from '@kbn/config-schema'; import { loggerMock } from '@kbn/logging-mocks'; import type { Payload } from 'elastic-apm-node'; diff --git a/packages/core/saved-objects/core-saved-objects-api-server/src/apis/find.ts b/packages/core/saved-objects/core-saved-objects-api-server/src/apis/find.ts index 83bd08ba8b9c7..6d70566c7a8ad 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server/src/apis/find.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server/src/apis/find.ts @@ -11,7 +11,7 @@ import type { SortOrder, AggregationsAggregationContainer, SortResults, -} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +} from '@elastic/elasticsearch/lib/api/types'; import type { SavedObject } from '../..'; type KueryNode = any; diff --git a/packages/core/saved-objects/core-saved-objects-base-server-internal/src/utils/get_field_list.ts b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/utils/get_field_list.ts index 1e3c29bb24a56..a0f07c300d271 100644 --- a/packages/core/saved-objects/core-saved-objects-base-server-internal/src/utils/get_field_list.ts +++ b/packages/core/saved-objects/core-saved-objects-base-server-internal/src/utils/get_field_list.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { MappingProperty as EsMappingProperty } from '@elastic/elasticsearch/lib/api/types'; import type { SavedObjectsTypeMappingDefinition, SavedObjectsFieldMapping, diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/bulk_overwrite_transformed_documents.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/bulk_overwrite_transformed_documents.ts index b2222c562f9ad..fa5ab8e09b3d6 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/bulk_overwrite_transformed_documents.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/bulk_overwrite_transformed_documents.ts @@ -9,7 +9,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 type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { errors as esErrors } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/create_index.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/create_index.ts index 60d3eb2aba762..5895f6b1cca0a 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/create_index.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/create_index.ts @@ -10,7 +10,7 @@ import * as Either from 'fp-ts/lib/Either'; import * as TaskEither from 'fp-ts/lib/TaskEither'; import { pipe } from 'fp-ts/lib/function'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import type { ElasticsearchClient, ElasticsearchCapabilities, diff --git a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/read_with_pit.ts b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/read_with_pit.ts index d22f05919aeb4..283786a4d90f5 100644 --- a/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/actions/read_with_pit.ts +++ b/packages/core/saved-objects/core-saved-objects-migration-server-internal/src/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 * as estypes from '@elastic/elasticsearch/lib/api/types'; import { errors as EsErrors } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import type { SavedObjectsRawDoc } from '@kbn/core-saved-objects-server'; diff --git a/packages/core/saved-objects/core-saved-objects-server/src/mapping_definition.ts b/packages/core/saved-objects/core-saved-objects-server/src/mapping_definition.ts index 1eee67f537095..d238d2298fc3e 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/mapping_definition.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/mapping_definition.ts @@ -11,7 +11,7 @@ import type { PropertyName as EsPropertyName, MappingProperty as EsMappingProperty, MappingPropertyBase as EsMappingPropertyBase, -} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +} from '@elastic/elasticsearch/lib/api/types'; /** * Describe a saved object type mapping. diff --git a/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_type.ts b/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_type.ts index cb2930f5d4676..dee93ada50cb3 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_type.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_type.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; import type { MaybePromise } from '@kbn/utility-types'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import type { SavedObjectsNamespaceType } from '@kbn/core-saved-objects-common'; diff --git a/packages/core/usage-data/core-usage-data-server-internal/src/core_usage_data_service.ts b/packages/core/usage-data/core-usage-data-server-internal/src/core_usage_data_service.ts index 7ac7cbb7fbb57..c970bd4abfa6d 100644 --- a/packages/core/usage-data/core-usage-data-server-internal/src/core_usage_data_service.ts +++ b/packages/core/usage-data/core-usage-data-server-internal/src/core_usage_data_service.ts @@ -16,7 +16,7 @@ import type { AggregationsMultiBucketAggregateBase, AggregationsSingleBucketAggregateBase, SearchTotalHits, -} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +} from '@elastic/elasticsearch/lib/api/types'; 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'; diff --git a/packages/kbn-es-types/index.ts b/packages/kbn-es-types/index.ts index d4ba23840e2a6..683fddb541baf 100644 --- a/packages/kbn-es-types/index.ts +++ b/packages/kbn-es-types/index.ts @@ -13,7 +13,6 @@ export type { SearchHit, ESSearchResponse, ESSearchRequest, - ESSearchRequestWithoutBody, ESSourceOptions, InferSearchResponseOf, AggregationResultOf, diff --git a/packages/kbn-es-types/src/index.ts b/packages/kbn-es-types/src/index.ts index 77d02320b6f2d..ecf2d710e2f50 100644 --- a/packages/kbn-es-types/src/index.ts +++ b/packages/kbn-es-types/src/index.ts @@ -7,12 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import * as estypesWithoutBody from '@elastic/elasticsearch/lib/api/types'; -import type { - Field, - QueryDslFieldAndFormat, -} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; +import type { Field, QueryDslFieldAndFormat } from '@elastic/elasticsearch/lib/api/types'; import { InferSearchResponseOf, AggregateOf as AggregationResultOf, @@ -27,7 +23,6 @@ import { export type ESFilter = estypes.QueryDslQueryContainer; export type ESSearchRequest = estypes.SearchRequest; -export type ESSearchRequestWithoutBody = estypesWithoutBody.SearchRequest; export type AggregationOptionsByType = Required; // Typings for Elasticsearch queries and aggregations. These are intended to be diff --git a/packages/kbn-es-types/src/search.ts b/packages/kbn-es-types/src/search.ts index 1c9a9e16fd4a7..8e8dc5436983c 100644 --- a/packages/kbn-es-types/src/search.ts +++ b/packages/kbn-es-types/src/search.ts @@ -8,7 +8,7 @@ */ import type { ValuesType, UnionToIntersection } from 'utility-types'; -import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import * as estypes from '@elastic/elasticsearch/lib/api/types'; import * as estypesWithoutBodyKey from '@elastic/elasticsearch/lib/api/types'; interface AggregationsAggregationContainer extends Record { @@ -61,7 +61,7 @@ type ValueTypeOfField = T extends Record type MaybeArray = T | T[]; -type Fields = Required['body']>['fields']; +type Fields = Required>['fields']; type DocValueFields = MaybeArray; export type ChangePointType = @@ -639,8 +639,8 @@ export type InferSearchResponseOf< | (estypesWithoutBodyKey.SearchRequest & { body?: never }) = estypes.SearchRequest, TOptions extends { restTotalHitsAsInt?: boolean } = {} > = Omit, 'aggregations' | 'hits'> & - (TSearchRequest['body'] extends TopLevelAggregationRequest - ? WrapAggregationResponse> + (TSearchRequest extends TopLevelAggregationRequest + ? WrapAggregationResponse> : TSearchRequest extends TopLevelAggregationRequest ? WrapAggregationResponse> : { aggregations?: InvalidAggregationRequest }) & { @@ -656,7 +656,7 @@ export type InferSearchResponseOf< }; }) & { hits: HitsOf< - TSearchRequest extends estypes.SearchRequest ? TSearchRequest['body'] : TSearchRequest, + TSearchRequest extends estypes.SearchRequest ? TSearchRequest : TSearchRequest, TDocument >; }; diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/actions/es_errors.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/actions/es_errors.test.ts index 108d92fc9a12a..a0d725324d9a1 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/actions/es_errors.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/actions/es_errors.test.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { InternalCoreStart } from '@kbn/core-lifecycle-server-internal'; import { Root } from '@kbn/core-root-server-internal'; import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; diff --git a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts index d07743c2fc1aa..17a984841bb38 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts @@ -8,7 +8,7 @@ */ import { merge, omit } from 'lodash'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { getLocalStats, handleLocalStats } from './get_local_stats'; import { diff --git a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.ts b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.ts index a0d54d043d11c..df3fc3d154ede 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.ts @@ -7,7 +7,7 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { StatsGetter, StatsCollectionContext, diff --git a/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.ts b/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.ts index 4fc70b95532d3..aaa27dd1ee98a 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.ts @@ -8,7 +8,7 @@ */ import type { ElasticsearchClient } from '@kbn/core/server'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { TIMEOUT } from './constants'; /** diff --git a/x-pack/plugins/licensing/server/license_fetcher.test.ts b/x-pack/plugins/licensing/server/license_fetcher.test.ts index 195c70c7c7c49..9c97489cf5c85 100644 --- a/x-pack/plugins/licensing/server/license_fetcher.test.ts +++ b/x-pack/plugins/licensing/server/license_fetcher.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { getLicenseFetcher } from './license_fetcher'; import { loggerMock, type MockedLogger } from '@kbn/logging-mocks'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; diff --git a/x-pack/plugins/licensing/server/license_fetcher.ts b/x-pack/plugins/licensing/server/license_fetcher.ts index 278142e5c39b2..6357fb7170a4c 100644 --- a/x-pack/plugins/licensing/server/license_fetcher.ts +++ b/x-pack/plugins/licensing/server/license_fetcher.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { createHash } from 'crypto'; import pRetry from 'p-retry'; import stringify from 'json-stable-stringify'; diff --git a/x-pack/plugins/licensing/server/plugin.test.ts b/x-pack/plugins/licensing/server/plugin.test.ts index d46d9e675f6d3..87190d8450692 100644 --- a/x-pack/plugins/licensing/server/plugin.test.ts +++ b/x-pack/plugins/licensing/server/plugin.test.ts @@ -7,7 +7,7 @@ import moment from 'moment'; import { BehaviorSubject, firstValueFrom, take, toArray } from 'rxjs'; -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { ClusterClientMock, coreMock, diff --git a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_license.ts b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_license.ts index 11f2b1359ab13..4a13dd72f8cef 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_license.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_license.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { ElasticsearchClient } from '@kbn/core/server'; export type ESLicense = estypes.LicenseGetLicenseInformation; diff --git a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts index f2adb257f9cb6..436acb643d8a4 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type * as estypes from '@elastic/elasticsearch/lib/api/types'; import { coreMock, elasticsearchServiceMock } from '@kbn/core/server/mocks'; import { getStatsWithXpack } from './get_stats_with_xpack'; import { SavedObjectsClient } from '@kbn/core/server'; diff --git a/x-pack/test/accessibility/apps/group3/upgrade_assistant.ts b/x-pack/test/accessibility/apps/group3/upgrade_assistant.ts index 02f823ef6a674..63f1f468a47b6 100644 --- a/x-pack/test/accessibility/apps/group3/upgrade_assistant.ts +++ b/x-pack/test/accessibility/apps/group3/upgrade_assistant.ts @@ -10,36 +10,32 @@ * valid deprecations */ -import type { IndicesCreateRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { IndicesCreateRequest } from '@elastic/elasticsearch/lib/api/types'; import { FtrProviderContext } from '../../ftr_provider_context'; const translogSettingsIndexDeprecation: IndicesCreateRequest = { index: 'deprecated_settings', - body: { - settings: { - 'translog.retention.size': '1b', - 'translog.retention.age': '5m', - 'index.soft_deletes.enabled': true, - }, + settings: { + 'translog.retention.size': '1b', + 'translog.retention.age': '5m', + 'index.soft_deletes.enabled': true, }, }; const multiFieldsIndexDeprecation: IndicesCreateRequest = { index: 'nested_multi_fields', - body: { - mappings: { - properties: { - text: { - type: 'text', - fields: { - english: { - type: 'text', - analyzer: 'english', - fields: { - english: { - type: 'text', - analyzer: 'english', - }, + mappings: { + properties: { + text: { + type: 'text', + fields: { + english: { + type: 'text', + analyzer: 'english', + fields: { + english: { + type: 'text', + analyzer: 'english', }, }, }, From 5846261b2f919c42be6dec90627c63f6cdccdeb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2024 12:02:10 +0100 Subject: [PATCH 2/6] `@kbn/es-types` accepts body temporarily --- packages/kbn-es-types/src/index.ts | 5 ++++- packages/kbn-es-types/src/search.ts | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/kbn-es-types/src/index.ts b/packages/kbn-es-types/src/index.ts index ecf2d710e2f50..354a26169c328 100644 --- a/packages/kbn-es-types/src/index.ts +++ b/packages/kbn-es-types/src/index.ts @@ -8,6 +8,8 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/types'; +// TODO: Remove when all usages have been migrated to non-body +import { SearchRequest as SearchRequestWithBodyKey } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { Field, QueryDslFieldAndFormat } from '@elastic/elasticsearch/lib/api/types'; import { InferSearchResponseOf, @@ -22,7 +24,8 @@ import { } from './search'; export type ESFilter = estypes.QueryDslQueryContainer; -export type ESSearchRequest = estypes.SearchRequest; +// For now, we also accept with body to unblock the migration to without body. +export type ESSearchRequest = estypes.SearchRequest | SearchRequestWithBodyKey; export type AggregationOptionsByType = Required; // Typings for Elasticsearch queries and aggregations. These are intended to be diff --git a/packages/kbn-es-types/src/search.ts b/packages/kbn-es-types/src/search.ts index 8e8dc5436983c..1f61c7a424541 100644 --- a/packages/kbn-es-types/src/search.ts +++ b/packages/kbn-es-types/src/search.ts @@ -9,7 +9,8 @@ import type { ValuesType, UnionToIntersection } from 'utility-types'; import * as estypes from '@elastic/elasticsearch/lib/api/types'; -import * as estypesWithoutBodyKey from '@elastic/elasticsearch/lib/api/types'; +// TODO: Remove when all usages have been migrated to non-body +import { SearchRequest as SearchRequestWithBodyKey } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; interface AggregationsAggregationContainer extends Record { aggs?: any; @@ -61,7 +62,7 @@ type ValueTypeOfField = T extends Record type MaybeArray = T | T[]; -type Fields = Required>['fields']; +type Fields = Required['fields']; type DocValueFields = MaybeArray; export type ChangePointType = @@ -635,12 +636,12 @@ type WrapAggregationResponse = keyof UnionToIntersection extends never export type InferSearchResponseOf< TDocument = unknown, TSearchRequest extends - | estypes.SearchRequest - | (estypesWithoutBodyKey.SearchRequest & { body?: never }) = estypes.SearchRequest, + | (estypes.SearchRequest & { body?: never }) // the union is necessary for the check 4 lines below + | SearchRequestWithBodyKey = estypes.SearchRequest, TOptions extends { restTotalHitsAsInt?: boolean } = {} > = Omit, 'aggregations' | 'hits'> & - (TSearchRequest extends TopLevelAggregationRequest - ? WrapAggregationResponse> + (TSearchRequest['body'] extends TopLevelAggregationRequest + ? WrapAggregationResponse> : TSearchRequest extends TopLevelAggregationRequest ? WrapAggregationResponse> : { aggregations?: InvalidAggregationRequest }) & { @@ -656,7 +657,7 @@ export type InferSearchResponseOf< }; }) & { hits: HitsOf< - TSearchRequest extends estypes.SearchRequest ? TSearchRequest : TSearchRequest, + TSearchRequest extends estypes.SearchRequest ? TSearchRequest : TSearchRequest['body'], TDocument >; }; @@ -690,5 +691,5 @@ export interface ESQLSearchParams { locale?: string; include_ccs_metadata?: boolean; dropNullColumns?: boolean; - params?: estypesWithoutBodyKey.ScalarValue[] | Array>; + params?: estypes.ScalarValue[] | Array>; } From 19e8f0969ab97b19de6227737436477ecc10255e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2024 13:09:47 +0100 Subject: [PATCH 3/6] Add workarounds to be able to merge --- packages/kbn-es-types/src/search.ts | 2 +- .../application/services/forecast_service.ts | 96 ++++++++----------- .../create_entities_es_client.ts | 3 +- .../lib/helpers/get_apm_alerts_client.ts | 3 +- .../routes/alerts/alerting_es_client.ts | 3 +- .../get_container_id_from_signals.ts | 2 +- .../get_service_name_from_signals.ts | 2 +- .../create_apm_event_client/index.ts | 3 +- .../create_alerts_client.ts | 3 +- .../lib/helpers/get_infra_alerts_client.ts | 3 +- .../lib/helpers/get_infra_metrics_client.ts | 3 +- .../clients/create_entities_es_client.ts | 3 +- .../server/services/get_alerts_client.ts | 3 +- 13 files changed, 63 insertions(+), 66 deletions(-) diff --git a/packages/kbn-es-types/src/search.ts b/packages/kbn-es-types/src/search.ts index 1f61c7a424541..e02b8a4a5e843 100644 --- a/packages/kbn-es-types/src/search.ts +++ b/packages/kbn-es-types/src/search.ts @@ -657,7 +657,7 @@ export type InferSearchResponseOf< }; }) & { hits: HitsOf< - TSearchRequest extends estypes.SearchRequest ? TSearchRequest : TSearchRequest['body'], + TSearchRequest extends SearchRequestWithBodyKey ? TSearchRequest['body'] : TSearchRequest, TDocument >; }; diff --git a/x-pack/platform/plugins/shared/ml/public/application/services/forecast_service.ts b/x-pack/platform/plugins/shared/ml/public/application/services/forecast_service.ts index 51ddc3ef9a926..ddce5e0b69f44 100644 --- a/x-pack/platform/plugins/shared/ml/public/application/services/forecast_service.ts +++ b/x-pack/platform/plugins/shared/ml/public/application/services/forecast_service.ts @@ -61,16 +61,13 @@ export function forecastServiceFactory(mlApi: MlApi) { mlApi.results .anomalySearch( { - // @ts-expect-error SearchRequest type has not been updated to include size size: maxResults, - body: { - query: { - bool: { - filter: filterCriteria, - }, + query: { + bool: { + filter: filterCriteria, }, - sort: [{ forecast_create_timestamp: { order: 'desc' } }], }, + sort: [{ forecast_create_timestamp: { order: 'desc' } }], }, [job.job_id] ) @@ -124,24 +121,21 @@ export function forecastServiceFactory(mlApi: MlApi) { mlApi.results .anomalySearch( { - // @ts-expect-error SearchRequest type has not been updated to include size size: 0, - body: { - query: { - bool: { - filter: filterCriteria, - }, + query: { + bool: { + filter: filterCriteria, }, - aggs: { - earliest: { - min: { - field: 'timestamp', - }, + }, + aggs: { + earliest: { + min: { + field: 'timestamp', }, - latest: { - max: { - field: 'timestamp', - }, + }, + latest: { + max: { + field: 'timestamp', }, }, }, @@ -264,36 +258,33 @@ export function forecastServiceFactory(mlApi: MlApi) { return mlApi.results .anomalySearch$( { - // @ts-expect-error SearchRequest type has not been updated to include size size: 0, - body: { - query: { - bool: { - filter: filterCriteria, - }, + query: { + bool: { + filter: filterCriteria, }, - aggs: { - times: { - date_histogram: { - field: 'timestamp', - fixed_interval: `${intervalMs}ms`, - min_doc_count: 1, - }, - aggs: { - prediction: { - [forecastAggs.avg]: { - field: 'forecast_prediction', - }, + }, + aggs: { + times: { + date_histogram: { + field: 'timestamp', + fixed_interval: `${intervalMs}ms`, + min_doc_count: 1, + }, + aggs: { + prediction: { + [forecastAggs.avg]: { + field: 'forecast_prediction', }, - forecastUpper: { - [forecastAggs.max]: { - field: 'forecast_upper', - }, + }, + forecastUpper: { + [forecastAggs.max]: { + field: 'forecast_upper', }, - forecastLower: { - [forecastAggs.min]: { - field: 'forecast_lower', - }, + }, + forecastLower: { + [forecastAggs.min]: { + field: 'forecast_lower', }, }, }, @@ -368,13 +359,10 @@ export function forecastServiceFactory(mlApi: MlApi) { mlApi.results .anomalySearch( { - // @ts-expect-error SearchRequest type has not been updated to include size size: 1, - body: { - query: { - bool: { - filter: filterCriteria, - }, + query: { + bool: { + filter: filterCriteria, }, }, }, diff --git a/x-pack/plugins/observability_solution/apm/server/lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client.ts b/x-pack/plugins/observability_solution/apm/server/lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client.ts index 6754d0b75dc6d..b5bc0adc860bf 100644 --- a/x-pack/plugins/observability_solution/apm/server/lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client.ts +++ b/x-pack/plugins/observability_solution/apm/server/lib/helpers/create_es_client/create_entities_es_client/create_entities_es_client.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { InferSearchResponseOf } from '@kbn/es-types'; import type { KibanaRequest } from '@kbn/core/server'; import { ElasticsearchClient } from '@kbn/core/server'; import { entitiesAliasPattern, ENTITY_LATEST, ENTITY_HISTORY } from '@kbn/entities-schema'; diff --git a/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_apm_alerts_client.ts b/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_apm_alerts_client.ts index fb519e2ef859f..bbdef89edba9c 100644 --- a/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_apm_alerts_client.ts +++ b/x-pack/plugins/observability_solution/apm/server/lib/helpers/get_apm_alerts_client.ts @@ -6,7 +6,8 @@ */ import { isEmpty } from 'lodash'; -import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { InferSearchResponseOf } from '@kbn/es-types'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; import { DataTier } from '@kbn/observability-shared-plugin/common'; import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys'; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/alerting_es_client.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/alerting_es_client.ts index 5638acd293538..fb99627956fcc 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/alerting_es_client.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/alerting_es_client.ts @@ -5,7 +5,8 @@ * 2.0. */ -import type { ESSearchRequest, ESSearchResponse } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { ESSearchResponse } from '@kbn/es-types'; import { RuleExecutorServices } from '@kbn/alerting-plugin/server'; import { IUiSettingsClient } from '@kbn/core/server'; import type { DataTier } from '@kbn/observability-shared-plugin/common'; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts index 93c55cf1a9a30..95a575eed9555 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_container_id_from_signals.ts @@ -5,12 +5,12 @@ * 2.0. */ +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { CoreRequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; import { rangeQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries'; import * as t from 'io-ts'; import moment from 'moment'; -import { ESSearchRequest } from '@kbn/es-types'; import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; import { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { CONTAINER_ID } from '@kbn/apm-types'; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts index bd966c500d1bc..a1ba8e264fabb 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/assistant_functions/get_observability_alert_details_context/get_service_name_from_signals.ts @@ -5,11 +5,11 @@ * 2.0. */ +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import { rangeQuery, termQuery, typedSearch } from '@kbn/observability-plugin/server/utils/queries'; import * as t from 'io-ts'; import moment from 'moment'; -import { ESSearchRequest } from '@kbn/es-types'; import { alertDetailsContextRt } from '@kbn/observability-plugin/server/services'; import type { LogSourcesService } from '@kbn/logs-data-access-plugin/common/types'; import { unflattenKnownApmEventFields } from '@kbn/apm-data-access-plugin/server/utils'; diff --git a/x-pack/plugins/observability_solution/apm_data_access/server/lib/helpers/create_es_client/create_apm_event_client/index.ts b/x-pack/plugins/observability_solution/apm_data_access/server/lib/helpers/create_es_client/create_apm_event_client/index.ts index 9f04bb9a750f3..a57b62718b2e7 100644 --- a/x-pack/plugins/observability_solution/apm_data_access/server/lib/helpers/create_es_client/create_apm_event_client/index.ts +++ b/x-pack/plugins/observability_solution/apm_data_access/server/lib/helpers/create_es_client/create_apm_event_client/index.ts @@ -14,8 +14,9 @@ import type { TermsEnumRequest, TermsEnumResponse, } from '@elastic/elasticsearch/lib/api/types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { ElasticsearchClient, KibanaRequest } from '@kbn/core/server'; -import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import type { InferSearchResponseOf } from '@kbn/es-types'; import { ProcessorEvent } from '@kbn/observability-plugin/common'; import { unwrapEsResponse } from '@kbn/observability-plugin/server'; import { compact, omit } from 'lodash'; diff --git a/x-pack/plugins/observability_solution/inventory/server/lib/create_alerts_client/create_alerts_client.ts b/x-pack/plugins/observability_solution/inventory/server/lib/create_alerts_client/create_alerts_client.ts index 878abd516e5bd..4ceaa03f1774e 100644 --- a/x-pack/plugins/observability_solution/inventory/server/lib/create_alerts_client/create_alerts_client.ts +++ b/x-pack/plugins/observability_solution/inventory/server/lib/create_alerts_client/create_alerts_client.ts @@ -6,7 +6,8 @@ */ import { isEmpty } from 'lodash'; -import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { InferSearchResponseOf } from '@kbn/es-types'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils'; import { InventoryRouteHandlerResources } from '../../routes/types'; diff --git a/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_alerts_client.ts b/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_alerts_client.ts index 99464efd02567..fb93a544684bc 100644 --- a/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_alerts_client.ts +++ b/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_alerts_client.ts @@ -5,7 +5,8 @@ * 2.0. */ import { isEmpty } from 'lodash'; -import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { InferSearchResponseOf } from '@kbn/es-types'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; import type { KibanaRequest } from '@kbn/core/server'; import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils'; diff --git a/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_metrics_client.ts b/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_metrics_client.ts index 96ae89b902285..4119f8ecfc34c 100644 --- a/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_metrics_client.ts +++ b/x-pack/solutions/observability/plugins/infra/server/lib/helpers/get_infra_metrics_client.ts @@ -4,7 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import type { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { InferSearchResponseOf } from '@kbn/es-types'; import type { KibanaRequest } from '@kbn/core/server'; import { searchExcludedDataTiers } from '@kbn/observability-plugin/common/ui_settings_keys'; import type { DataTier } from '@kbn/observability-shared-plugin/common'; diff --git a/x-pack/solutions/observability/plugins/investigate_app/server/clients/create_entities_es_client.ts b/x-pack/solutions/observability/plugins/investigate_app/server/clients/create_entities_es_client.ts index c11cd3eb9bc02..6eb1beaf0ede6 100644 --- a/x-pack/solutions/observability/plugins/investigate_app/server/clients/create_entities_es_client.ts +++ b/x-pack/solutions/observability/plugins/investigate_app/server/clients/create_entities_es_client.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { InferSearchResponseOf } from '@kbn/es-types'; import type { KibanaRequest } from '@kbn/core/server'; import { ElasticsearchClient } from '@kbn/core/server'; import { entitiesAliasPattern, ENTITY_LATEST } from '@kbn/entities-schema'; diff --git a/x-pack/solutions/observability/plugins/investigate_app/server/services/get_alerts_client.ts b/x-pack/solutions/observability/plugins/investigate_app/server/services/get_alerts_client.ts index c5eaf3f4c3d8e..eae37e54c5648 100644 --- a/x-pack/solutions/observability/plugins/investigate_app/server/services/get_alerts_client.ts +++ b/x-pack/solutions/observability/plugins/investigate_app/server/services/get_alerts_client.ts @@ -6,7 +6,8 @@ */ import { isEmpty } from 'lodash'; -import { ESSearchRequest, InferSearchResponseOf } from '@kbn/es-types'; +import { SearchRequest as ESSearchRequest } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { InferSearchResponseOf } from '@kbn/es-types'; import { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; import { OBSERVABILITY_RULE_TYPE_IDS } from '@kbn/rule-data-utils'; import { InvestigateAppRouteHandlerResources } from '../routes/types'; From 2271b85f18f8c387143c3bf45904c8412cd3f0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2024 16:02:56 +0100 Subject: [PATCH 4/6] Fix tests --- .../src/lib/apis/bulk_create.test.ts | 77 ++++++++++--------- .../src/lib/apis/bulk_create.ts | 2 +- .../src/lib/apis/bulk_delete.test.ts | 14 ++-- .../src/lib/apis/bulk_delete.ts | 2 +- .../src/lib/apis/bulk_get.test.ts | 14 ++-- .../src/lib/apis/bulk_get.ts | 6 +- .../src/lib/apis/bulk_update.test.ts | 26 +++---- .../src/lib/apis/bulk_update.ts | 4 +- .../src/lib/apis/check_conflicts.test.ts | 14 ++-- .../src/lib/apis/check_conflicts.ts | 6 +- .../src/lib/apis/create.test.ts | 30 ++++---- .../src/lib/apis/create.ts | 9 ++- .../src/lib/apis/delete_by_namespace.ts | 40 +++++----- .../src/lib/apis/find.test.ts | 38 ++++----- .../src/lib/apis/find.ts | 48 ++++++------ .../src/lib/apis/helpers/preflight_check.ts | 5 +- .../src/lib/apis/increment_counter.test.ts | 44 +++++------ ...collect_multi_namespace_references.test.ts | 2 +- .../collect_multi_namespace_references.ts | 2 +- .../delete_legacy_url_aliases.test.ts | 28 +++---- .../internals/delete_legacy_url_aliases.ts | 28 ++++--- .../internals/increment_counter_internal.ts | 54 +++++++------ .../internals/internal_bulk_resolve.test.ts | 12 ++- .../apis/internals/internal_bulk_resolve.ts | 4 +- .../preflight_check_for_create.test.ts | 5 +- .../internals/preflight_check_for_create.ts | 2 +- .../internals/update_objects_spaces.test.ts | 8 +- .../apis/internals/update_objects_spaces.ts | 4 +- .../src/lib/apis/open_point_in_time.test.ts | 4 +- .../src/lib/apis/remove_references_to.test.ts | 21 ++--- .../src/lib/apis/remove_references_to.ts | 44 +++++------ .../src/lib/apis/update.test.ts | 6 +- .../src/lib/apis/update.ts | 10 ++- .../repository.encryption_extension.test.ts | 14 ++-- .../lib/repository.spaces_extension.test.ts | 54 ++++++------- .../src/lib/repository.ts | 4 +- .../src/lib/repository_es_client.test.ts | 8 +- 37 files changed, 320 insertions(+), 373 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.test.ts index 92dbeb4339a27..cd0ddf183da42 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.test.ts @@ -168,9 +168,9 @@ describe('#bulkCreate', () => { getId = () => expect.any(String), }: { method: string; _index?: string; getId?: (type: string, id?: string) => string } ) => { - const body = []; + const operations = []; for (const { type, id, if_primary_term: ifPrimaryTerm, if_seq_no: ifSeqNo } of objects) { - body.push({ + operations.push({ [method]: { _index, _id: getId(type, id), @@ -179,10 +179,10 @@ describe('#bulkCreate', () => { : {}), }, }); - body.push(expect.any(Object)); + operations.push(expect.any(Object)); } expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }; @@ -290,9 +290,9 @@ describe('#bulkCreate', () => { it(`formats the ES request`, async () => { await bulkCreateSuccess(client, repository, [obj1, obj2]); - const body = [...expectObjArgs(obj1), ...expectObjArgs(obj2)]; + const operations = [...expectObjArgs(obj1), ...expectObjArgs(obj2)]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -301,9 +301,12 @@ describe('#bulkCreate', () => { const obj1WithManagedTrue = { ...obj1, managed: true }; const obj2WithManagedTrue = { ...obj2, managed: true }; await bulkCreateSuccess(client, repository, [obj1WithManagedTrue, obj2WithManagedTrue]); - const body = [...expectObjArgs(obj1WithManagedTrue), ...expectObjArgs(obj2WithManagedTrue)]; + const operations = [ + ...expectObjArgs(obj1WithManagedTrue), + ...expectObjArgs(obj2WithManagedTrue), + ]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -333,9 +336,9 @@ describe('#bulkCreate', () => { await bulkCreateSuccess(client, repository, objects); const expected = expect.not.objectContaining({ originId: expect.anything() }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -360,9 +363,9 @@ describe('#bulkCreate', () => { ]; await bulkCreateSuccess(client, repository, objects); const expected = expect.objectContaining({ originId: 'some-originId' }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -375,9 +378,9 @@ describe('#bulkCreate', () => { ]; await bulkCreateSuccess(client, repository, objects); const expected = expect.not.objectContaining({ originId: expect.anything() }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -389,9 +392,9 @@ describe('#bulkCreate', () => { ]; await bulkCreateSuccess(client, repository, objects); const expected = expect.objectContaining({ originId: 'existing-originId' }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -401,9 +404,9 @@ describe('#bulkCreate', () => { it(`adds namespace to request body for any types that are single-namespace`, async () => { await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace }); const expected = expect.objectContaining({ namespace }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -412,9 +415,9 @@ describe('#bulkCreate', () => { it(`adds managed=false to request body if declared for any types that are single-namespace`, async () => { await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace, managed: false }); const expected = expect.objectContaining({ namespace, managed: false }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -422,9 +425,9 @@ describe('#bulkCreate', () => { it(`adds managed=true to request body if declared for any types that are single-namespace`, async () => { await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace, managed: true }); const expected = expect.objectContaining({ namespace, managed: true }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -432,9 +435,9 @@ describe('#bulkCreate', () => { it(`normalizes options.namespace from 'default' to undefined`, async () => { await bulkCreateSuccess(client, repository, [obj1, obj2], { namespace: 'default' }); const expected = expect.not.objectContaining({ namespace: 'default' }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -446,9 +449,9 @@ describe('#bulkCreate', () => { ]; await bulkCreateSuccess(client, repository, objects, { namespace }); const expected = expect.not.objectContaining({ namespace: expect.anything() }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -468,9 +471,9 @@ describe('#bulkCreate', () => { await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true }); const expected1 = expect.objectContaining({ namespaces: [namespace ?? 'default'] }); const expected2 = expect.objectContaining({ namespaces: ['*'] }); - const body = [expect.any(Object), expected1, expect.any(Object), expected2]; + const operations = [expect.any(Object), expected1, expect.any(Object), expected2]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); @@ -503,7 +506,7 @@ describe('#bulkCreate', () => { }, ]); await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true }); - const body = [ + const operations = [ { index: expect.objectContaining({ _id: `${ns2}:dashboard:${o1.id}` }) }, expect.objectContaining({ namespace: ns2 }), { @@ -525,7 +528,7 @@ describe('#bulkCreate', () => { }) ); expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); @@ -539,12 +542,12 @@ describe('#bulkCreate', () => { const test = async (namespace?: string) => { const objects = [{ ...obj1, type: 'dashboard', initialNamespaces: ['default'] }]; await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true }); - const body = [ + const operations = [ { index: expect.objectContaining({ _id: `dashboard:${obj1.id}` }) }, expect.not.objectContaining({ namespace: 'default' }), ]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); @@ -558,9 +561,9 @@ describe('#bulkCreate', () => { const objects = [obj1, { ...obj2, type: NAMESPACE_AGNOSTIC_TYPE }]; await bulkCreateSuccess(client, repository, objects, { namespace, overwrite: true }); const expected = expect.not.objectContaining({ namespaces: expect.anything() }); - const body = [expect.any(Object), expected, expect.any(Object), expected]; + const operations = [expect.any(Object), expected, expect.any(Object), expected]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); @@ -652,9 +655,9 @@ describe('#bulkCreate', () => { const result = await repository.bulkCreate(objects); expect(client.bulk).toHaveBeenCalled(); const objCall = isBulkError ? expectObjArgs(obj) : []; - const body = [...expectObjArgs(obj1), ...objCall, ...expectObjArgs(obj2)]; + const operations = [...expectObjArgs(obj1), ...objCall, ...expectObjArgs(obj2)]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); expect(result).toEqual({ @@ -765,7 +768,7 @@ describe('#bulkCreate', () => { ); expect(client.bulk).toHaveBeenCalled(); expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body: [...expectObjArgs(o1), ...expectObjArgs(o5)] }), + expect.objectContaining({ operations: [...expectObjArgs(o1), ...expectObjArgs(o5)] }), expect.anything() ); expect(result).toEqual({ diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.ts index 95e9c9acb7953..1a9b8956a3084 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_create.ts @@ -282,7 +282,7 @@ export const performBulkCreate = async ( ? await client.bulk({ refresh, require_alias: true, - body: bulkCreateParams, + operations: bulkCreateParams, }) : undefined; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts index 249e1542455eb..a4c6f365529f1 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.test.ts @@ -131,9 +131,9 @@ describe('#bulkDelete', () => { overrides?: Record; } ) => { - const body = []; + const operations = []; for (const { type, id } of objects) { - body.push({ + operations.push({ [method]: { _index, _id: getId(type, id), @@ -143,7 +143,7 @@ describe('#bulkDelete', () => { } expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }; @@ -202,9 +202,9 @@ describe('#bulkDelete', () => { overrides?: Record; } ) => { - const body = []; + const operations = []; for (const { type, id } of objects) { - body.push({ + operations.push({ [method]: { _index, _id: getId(type, id), @@ -213,7 +213,7 @@ describe('#bulkDelete', () => { }); } expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }; @@ -266,7 +266,7 @@ describe('#bulkDelete', () => { expect.objectContaining({ _id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${obj2.id}` }), ]; expect(client.mget).toHaveBeenCalledWith( - expect.objectContaining({ body: { docs } }), + expect.objectContaining({ docs }), expect.anything() ); }); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.ts index e3fcff2dd1003..6495272fccdb0 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_delete.ts @@ -141,7 +141,7 @@ export const performBulkDelete = async ( const bulkDeleteResponse = bulkDeleteParams.length ? await client.bulk({ refresh, - body: bulkDeleteParams, + operations: bulkDeleteParams, require_alias: true, }) : undefined; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts index 5a21c742dd5de..eff12c97379c8 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.test.ts @@ -149,14 +149,12 @@ describe('#bulkGet', () => { ) => { expect(client.mget).toHaveBeenCalledWith( expect.objectContaining({ - body: { - docs: objects.map(({ type, id }) => - expect.objectContaining({ - _index, - _id: getId(type, id), - }) - ), - }, + docs: objects.map(({ type, id }) => + expect.objectContaining({ + _index, + _id: getId(type, id), + }) + ), }), expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.ts index 3cc6511adefa2..858b4830a7270 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_get.ts @@ -134,11 +134,7 @@ export const performBulkGet = async ( })); const bulkGetResponse = bulkGetDocs.length ? await client.mget( - { - body: { - docs: bulkGetDocs, - }, - }, + { docs: bulkGetDocs }, { ignore: [404], meta: true } ) : undefined; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts index bc1822ac7849b..411caec4d319b 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.test.ts @@ -164,13 +164,13 @@ describe('#bulkUpdate', () => { overrides?: Record; } ) => { - const body = []; + const operations = []; for (const object of objects) { - body.push(getBulkIndexEntry(method, object, _index, getId, overrides)); - body.push(expect.any(Object)); + operations.push(getBulkIndexEntry(method, object, _index, getId, overrides)); + operations.push(expect.any(Object)); } expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }; @@ -214,7 +214,7 @@ describe('#bulkUpdate', () => { expect.objectContaining({ _id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${obj2.id}` }), ]; expect(client.mget).toHaveBeenCalledWith( - expect.objectContaining({ body: { docs } }), + expect.objectContaining({ docs }), expect.anything() ); }); @@ -239,7 +239,7 @@ describe('#bulkUpdate', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: [ + operations: [ getBulkIndexEntry('index', _obj1), expect.objectContaining({ [obj1.type]: { @@ -267,7 +267,7 @@ describe('#bulkUpdate', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: [ + operations: [ getBulkIndexEntry('index', _obj1), expect.objectContaining({ [obj1.type]: { @@ -288,12 +288,12 @@ describe('#bulkUpdate', () => { it(`defaults to no references`, async () => { await bulkUpdateSuccess(client, repository, registry, [obj1, obj2]); - const body = [ + const operations = [ ...expectObjArgs({ ...obj1, references: [] }), ...expectObjArgs({ ...obj2, references: [] }), ]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); }); @@ -302,12 +302,12 @@ describe('#bulkUpdate', () => { const test = async (references: SavedObjectReference[]) => { const objects = [obj1, obj2].map((obj) => ({ ...obj, references })); await bulkUpdateSuccess(client, repository, registry, objects); - const body = [ + const operations = [ ...expectObjArgs({ ...obj1, references }), ...expectObjArgs({ ...obj2, references }), ]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); @@ -322,12 +322,12 @@ describe('#bulkUpdate', () => { const test = async (references: unknown) => { const objects = [obj1, obj2]; await bulkUpdateSuccess(client, repository, registry, objects); - const body = [ + const operations = [ ...expectObjArgs({ ...obj1, references: expect.not.arrayContaining([references]) }), ...expectObjArgs({ ...obj2, references: expect.not.arrayContaining([references]) }), ]; expect(client.bulk).toHaveBeenCalledWith( - expect.objectContaining({ body }), + expect.objectContaining({ operations }), expect.anything() ); client.bulk.mockClear(); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts index b8515ac1bf9e1..4ca0635066884 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts @@ -168,7 +168,7 @@ export const performBulkUpdate = async ( const bulkGetResponse = bulkGetDocs.length ? await client.mget( - { body: { docs: bulkGetDocs } }, + { docs: bulkGetDocs }, { ignore: [404], meta: true } ) : undefined; @@ -344,7 +344,7 @@ export const performBulkUpdate = async ( const bulkUpdateResponse = bulkUpdateParams.length ? await client.bulk({ refresh, - body: bulkUpdateParams, + operations: bulkUpdateParams, _source_includes: ['originId'], require_alias: true, }) diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts index 6104ed0466455..e67c6b623aa6a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.test.ts @@ -100,14 +100,12 @@ describe('#checkConflicts', () => { ) => { expect(client.mget).toHaveBeenCalledWith( expect.objectContaining({ - body: { - docs: objects.map(({ type, id }) => - expect.objectContaining({ - _index, - _id: getId(type, id), - }) - ), - }, + docs: objects.map(({ type, id }) => + expect.objectContaining({ + _index, + _id: getId(type, id), + }) + ), }), expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.ts index c85564b1a0eac..40cf6e590ddcf 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/check_conflicts.ts @@ -85,11 +85,7 @@ export const performCheckConflicts = async ( })); const bulkGetResponse = bulkGetDocs.length ? await client.mget( - { - body: { - docs: bulkGetDocs, - }, - }, + { docs: bulkGetDocs }, { ignore: [404], meta: true } ) : undefined; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts index 8b19a92c44983..6473af396945e 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.test.ts @@ -286,9 +286,7 @@ describe('#create', () => { it(`${objType} defaults to no originId`, async () => { await createSuccess(objType, attributes, { id }); expect(client.create).toHaveBeenCalledWith( - expect.objectContaining({ - body: expect.not.objectContaining({ originId: expect.anything() }), - }), + expect.not.objectContaining({ originId: expect.anything() }), expect.anything() ); }); @@ -310,7 +308,7 @@ describe('#create', () => { await createSuccess(objType, attributes, { id, originId: 'some-originId' }); expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ originId: 'some-originId' }), + document: expect.objectContaining({ originId: 'some-originId' }), }), expect.anything() ); @@ -321,7 +319,7 @@ describe('#create', () => { await createSuccess(objType, attributes, { id, originId: undefined }); expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.not.objectContaining({ originId: expect.anything() }), + document: expect.not.objectContaining({ originId: expect.anything() }), }), expect.anything() ); @@ -331,7 +329,7 @@ describe('#create', () => { await createSuccess(objType, attributes, { id }); expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ originId: 'existing-originId' }), + document: expect.objectContaining({ originId: 'existing-originId' }), }), expect.anything() ); @@ -388,7 +386,7 @@ describe('#create', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: `${namespace}:${type}:${id}`, - body: expect.objectContaining({ namespace }), + document: expect.objectContaining({ namespace }), }), expect.anything() ); @@ -399,7 +397,7 @@ describe('#create', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: `${type}:${id}`, - body: expect.not.objectContaining({ namespace: expect.anything() }), + document: expect.not.objectContaining({ namespace: expect.anything() }), }), expect.anything() ); @@ -410,7 +408,7 @@ describe('#create', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: `${type}:${id}`, - body: expect.not.objectContaining({ namespace: expect.anything() }), + document: expect.not.objectContaining({ namespace: expect.anything() }), }), expect.anything() ); @@ -457,7 +455,7 @@ describe('#create', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: `${MULTI_NAMESPACE_TYPE}:${id}`, - body: expect.objectContaining({ namespaces: [namespace] }), + document: expect.objectContaining({ namespaces: [namespace] }), }), expect.anything() ); @@ -465,7 +463,7 @@ describe('#create', () => { expect(client.index).toHaveBeenCalledWith( expect.objectContaining({ id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${id}`, - body: expect.objectContaining({ namespaces: ['*'] }), + document: expect.objectContaining({ namespaces: ['*'] }), }), expect.anything() ); @@ -524,7 +522,7 @@ describe('#create', () => { 1, expect.objectContaining({ id: `${ns2}:dashboard:${id}`, - body: expect.objectContaining({ namespace: ns2 }), + document: expect.objectContaining({ namespace: ns2 }), }), expect.anything() ); @@ -532,7 +530,7 @@ describe('#create', () => { 2, expect.objectContaining({ id: `${MULTI_NAMESPACE_TYPE}:${id}`, - body: expect.objectContaining({ namespaces: [ns2, ns3] }), + document: expect.objectContaining({ namespaces: [ns2, ns3] }), }), expect.anything() ); @@ -540,7 +538,7 @@ describe('#create', () => { expect(client.index).toHaveBeenCalledWith( expect.objectContaining({ id: `${MULTI_NAMESPACE_ISOLATED_TYPE}:${id}`, - body: expect.objectContaining({ namespaces: [ns2] }), + document: expect.objectContaining({ namespaces: [ns2] }), }), expect.anything() ); @@ -558,7 +556,7 @@ describe('#create', () => { 1, expect.objectContaining({ id: `dashboard:${id}`, - body: expect.not.objectContaining({ namespace: 'default' }), + document: expect.not.objectContaining({ namespace: 'default' }), }), expect.anything() ); @@ -569,7 +567,7 @@ describe('#create', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: `${NAMESPACE_AGNOSTIC_TYPE}:${id}`, - body: expect.not.objectContaining({ + document: expect.not.objectContaining({ namespace: expect.anything(), namespaces: expect.anything(), }), diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.ts index 5fb22be52febd..4c7e0a17842f7 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/create.ts @@ -16,6 +16,7 @@ import { import { SavedObjectsUtils } from '@kbn/core-saved-objects-utils-server'; import { decodeRequestVersion } from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsCreateOptions } from '@kbn/core-saved-objects-api-server'; +import { CreateRequest, type IndexRequest } from '@elastic/elasticsearch/lib/api/types'; import { DEFAULT_REFRESH_SETTING } from '../constants'; import type { PreflightCheckForCreateResult } from './internals/preflight_check_for_create'; import { getSavedObjectNamespaces, getCurrentTime, normalizeNamespace, setManaged } from './utils'; @@ -152,19 +153,19 @@ export const performCreate = async ( const raw = serializer.savedObjectToRaw(migrated as SavedObjectSanitizedDoc); - const requestParams = { + const requestParams: IndexRequest | CreateRequest = { id: raw._id, index: commonHelper.getIndexForType(type), refresh, - body: raw._source, + document: raw._source, ...(overwrite && version ? decodeRequestVersion(version) : {}), require_alias: true, }; const { body, statusCode, headers } = id && overwrite - ? await client.index(requestParams, { meta: true }) - : await client.create(requestParams, { meta: true }); + ? await client.index(requestParams as IndexRequest, { meta: true }) + : await client.create(requestParams as CreateRequest, { meta: true }); // throw if we can't verify a 404 response is from Elasticsearch if (isNotFoundFromUnsupportedServer({ statusCode, headers })) { diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete_by_namespace.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete_by_namespace.ts index 14b9143fa6225..fc8bed73802c6 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete_by_namespace.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/delete_by_namespace.ts @@ -49,28 +49,26 @@ export const performDeleteByNamespace = async ( { index: commonHelper.getIndicesForTypes(typesToUpdate), refresh: options.refresh, - body: { - script: { - source: ` - if (!ctx._source.containsKey('namespaces')) { - ctx.op = "delete"; - } else { - ctx._source['namespaces'].removeAll(Collections.singleton(params['namespace'])); - if (ctx._source['namespaces'].empty) { - ctx.op = "delete"; - } - } - `, - lang: 'painless', - params: { namespace }, - }, - conflicts: 'proceed', - ...getSearchDsl(mappings, registry, { - namespaces: [namespace], - type: typesToUpdate, - kueryNode, - }), + script: { + source: ` + if (!ctx._source.containsKey('namespaces')) { + ctx.op = "delete"; + } else { + ctx._source['namespaces'].removeAll(Collections.singleton(params['namespace'])); + if (ctx._source['namespaces'].empty) { + ctx.op = "delete"; + } + } + `, + lang: 'painless', + params: { namespace }, }, + conflicts: 'proceed', + ...(getSearchDsl(mappings, registry, { + namespaces: [namespace], + type: typesToUpdate, + kueryNode, + }) as Omit, 'sort'>), // Sort types don't match and we're not sorting anyways }, { ignore: [404], meta: true } ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.test.ts index 12b14bb6f1a32..6c9cca176c4d6 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.test.ts @@ -106,9 +106,7 @@ describe('find', () => { await findSuccess(client, repository, { type }); expect(client.search).toHaveBeenCalledWith( - expect.objectContaining({ - body: expect.objectContaining({ ...query }), - }), + expect.objectContaining({ ...query }), expect.anything() ); }); @@ -138,24 +136,22 @@ describe('find', () => { await findSuccess(client, repository, { type, fields: ['title'] }); expect(client.search).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - _source: [ - `${type}.title`, - 'namespace', - 'namespaces', - 'type', - 'references', - 'migrationVersion', - 'coreMigrationVersion', - 'typeMigrationVersion', - 'managed', - 'updated_at', - 'updated_by', - 'created_at', - 'created_by', - 'originId', - ], - }), + _source: [ + `${type}.title`, + 'namespace', + 'namespaces', + 'type', + 'references', + 'migrationVersion', + 'coreMigrationVersion', + 'typeMigrationVersion', + 'managed', + 'updated_at', + 'updated_by', + 'created_at', + 'created_by', + 'originId', + ], }), expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts index 662b3759f5133..c333642dd206a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts @@ -191,31 +191,29 @@ export const performFind = async ( preference, rest_total_hits_as_int: true, size: perPage, - body: { - size: perPage, - seq_no_primary_term: true, - from: perPage * (page - 1), - _source: includedFields(allowedTypes, fields), - ...(aggsObject ? { aggs: aggsObject } : {}), - ...getSearchDsl(mappings, registry, { - search, - defaultSearchOperator, - searchFields, - pit, - rootSearchFields, - type: allowedTypes, - searchAfter, - sortField, - sortOrder, - namespaces, - typeToNamespacesMap, // If defined, this takes precedence over the `type` and `namespaces` fields - hasReference, - hasReferenceOperator, - hasNoReference, - hasNoReferenceOperator, - kueryNode, - }), - }, + size: perPage, + seq_no_primary_term: true, + from: perPage * (page - 1), + _source: includedFields(allowedTypes, fields), + ...(aggsObject ? { aggs: aggsObject } : {}), + ...getSearchDsl(mappings, registry, { + search, + defaultSearchOperator, + searchFields, + pit, + rootSearchFields, + type: allowedTypes, + searchAfter, + sortField, + sortOrder, + namespaces, + typeToNamespacesMap, // If defined, this takes precedence over the `type` and `namespaces` fields + hasReference, + hasReferenceOperator, + hasNoReference, + hasNoReferenceOperator, + kueryNode, + }), }; const { body, statusCode, headers } = await client.search(esOptions, { diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/helpers/preflight_check.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/helpers/preflight_check.ts index 73428ebcc8529..ab05a435a445b 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/helpers/preflight_check.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/helpers/preflight_check.ts @@ -88,10 +88,7 @@ export class PreflightCheckHelper { })); const bulkGetMultiNamespaceDocsResponse = bulkGetMultiNamespaceDocs.length - ? await this.client.mget( - { body: { docs: bulkGetMultiNamespaceDocs } }, - { ignore: [404], meta: true } - ) + ? await this.client.mget({ docs: bulkGetMultiNamespaceDocs }, { ignore: [404], meta: true }) : undefined; // fail fast if we can't verify a 404 response is from Elasticsearch if ( diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts index 0db217b927fa5..88ce6fb865f57 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/increment_counter.test.ts @@ -222,19 +222,17 @@ describe('#incrementCounter', () => { await incrementCounterSuccess(type, id, counterFields, { namespace, upsertAttributes }); expect(client.update).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - upsert: expect.objectContaining({ - [type]: { - foo: 'bar', - hello: 'dolly', - ...counterFields.reduce((aggs, field) => { - return { - ...aggs, - [field]: 1, - }; - }, {}), - }, - }), + upsert: expect.objectContaining({ + [type]: { + foo: 'bar', + hello: 'dolly', + ...counterFields.reduce((aggs, field) => { + return { + ...aggs, + [field]: 1, + }; + }, {}), + }, }), }), expect.anything() @@ -495,12 +493,10 @@ describe('#incrementCounter', () => { expect(client.update).toBeCalledTimes(1); expect(client.update).toBeCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - script: expect.objectContaining({ - params: expect.objectContaining({ - counterFieldNames: [counterFields[0]], - counts: [3], - }), + script: expect.objectContaining({ + params: expect.objectContaining({ + counterFieldNames: [counterFields[0]], + counts: [3], }), }), }), @@ -514,12 +510,10 @@ describe('#incrementCounter', () => { expect(client.update).toBeCalledTimes(1); expect(client.update).toBeCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - script: expect.objectContaining({ - params: expect.objectContaining({ - counterFieldNames: [counterFields[0]], - counts: [0], - }), + script: expect.objectContaining({ + params: expect.objectContaining({ + counterFieldNames: [counterFields[0]], + counts: [0], }), }), }), diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts index 3d0ef40a2a22a..e43eeb570620a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.test.ts @@ -134,7 +134,7 @@ describe('collectMultiNamespaceReferences', () => { ...objects: SavedObjectsCollectMultiNamespaceReferencesObject[] ) { const docs = objects.map(({ type, id }) => expect.objectContaining({ _id: `${type}:${id}` })); - expect(client.mget).toHaveBeenNthCalledWith(n, { body: { docs } }, expect.anything()); + expect(client.mget).toHaveBeenNthCalledWith(n, { docs }, expect.anything()); } it('returns an empty array if no object args are passed in', async () => { diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.ts index 4b35b45b89bb9..f802b8a97bcfd 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/collect_multi_namespace_references.ts @@ -185,7 +185,7 @@ async function getObjectsAndReferences({ ); } const bulkGetResponse = await client.mget( - { body: { docs: makeBulkGetDocs(bulkGetObjects) } }, + { docs: makeBulkGetDocs(bulkGetObjects) }, { ignore: [404], meta: true } ); // exit early if we can't verify a 404 response is from Elasticsearch diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.test.ts index 2334a5a5a3eeb..f4bba00e26968 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.test.ts @@ -86,14 +86,12 @@ describe('deleteLegacyUrlAliases', () => { expect(params.client.updateByQuery).toHaveBeenCalledTimes(1); expect(params.client.updateByQuery).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - script: expect.objectContaining({ - params: { - namespaces, - matchTargetNamespaceOp: 'delete', - notMatchTargetNamespaceOp: 'noop', - }, - }), + script: expect.objectContaining({ + params: { + namespaces, + matchTargetNamespaceOp: 'delete', + notMatchTargetNamespaceOp: 'noop', + }, }), }), expect.anything() @@ -111,14 +109,12 @@ describe('deleteLegacyUrlAliases', () => { expect(params.client.updateByQuery).toHaveBeenCalledTimes(1); expect(params.client.updateByQuery).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - script: expect.objectContaining({ - params: { - namespaces, - matchTargetNamespaceOp: 'noop', - notMatchTargetNamespaceOp: 'delete', - }, - }), + script: expect.objectContaining({ + params: { + namespaces, + matchTargetNamespaceOp: 'noop', + notMatchTargetNamespaceOp: 'delete', + }, }), }), expect.anything() diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.ts index b56eaddd35583..4486051898da5 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/delete_legacy_url_aliases.ts @@ -69,29 +69,27 @@ export async function deleteLegacyUrlAliases(params: DeleteLegacyUrlAliasesParam { index: getIndexForType(LEGACY_URL_ALIAS_TYPE), refresh: false, // This could be called many times in succession, intentionally do not wait for a refresh - body: { - ...getSearchDsl(mappings, registry, { - type: LEGACY_URL_ALIAS_TYPE, - kueryNode: createKueryNode(type, id), - }), - script: { - // Intentionally use one script source with variable params to take advantage of ES script caching - source: ` + ...(getSearchDsl(mappings, registry, { + type: LEGACY_URL_ALIAS_TYPE, + kueryNode: createKueryNode(type, id), + }) as Omit, 'sort'>), // Omitting sort in the types in this operation because types expect only string[] and we're not really sorting + script: { + // Intentionally use one script source with variable params to take advantage of ES script caching + source: ` if (params['namespaces'].indexOf(ctx._source['${LEGACY_URL_ALIAS_TYPE}']['targetNamespace']) > -1) { ctx.op = params['matchTargetNamespaceOp']; } else { ctx.op = params['notMatchTargetNamespaceOp']; } `, - params: { - namespaces, - matchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'delete' : 'noop', - notMatchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'noop' : 'delete', - }, - lang: 'painless', + params: { + namespaces, + matchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'delete' : 'noop', + notMatchTargetNamespaceOp: deleteBehavior === 'inclusive' ? 'noop' : 'delete', }, - conflicts: 'proceed', + lang: 'painless', }, + conflicts: 'proceed', }, { ignore: [404] } ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/increment_counter_internal.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/increment_counter_internal.ts index 00a588fb4d006..23a7091aefad6 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/increment_counter_internal.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/increment_counter_internal.ts @@ -125,36 +125,34 @@ export const incrementCounterInternal = async ( refresh, require_alias: true, _source: true, - body: { - script: { - source: ` - for (int i = 0; i < params.counterFieldNames.length; i++) { - def counterFieldName = params.counterFieldNames[i]; - def count = params.counts[i]; - - if (ctx._source[params.type][counterFieldName] == null) { - ctx._source[params.type][counterFieldName] = count; - } - else { - ctx._source[params.type][counterFieldName] += count; - } - } - ctx._source.updated_at = params.time; - `, - lang: 'painless', - params: { - counts: normalizedCounterFields.map( - (normalizedCounterField) => normalizedCounterField.incrementBy - ), - counterFieldNames: normalizedCounterFields.map( - (normalizedCounterField) => normalizedCounterField.fieldName - ), - time, - type, - }, + script: { + source: ` + for (int i = 0; i < params.counterFieldNames.length; i++) { + def counterFieldName = params.counterFieldNames[i]; + def count = params.counts[i]; + + if (ctx._source[params.type][counterFieldName] == null) { + ctx._source[params.type][counterFieldName] = count; + } + else { + ctx._source[params.type][counterFieldName] += count; + } + } + ctx._source.updated_at = params.time; + `, + lang: 'painless', + params: { + counts: normalizedCounterFields.map( + (normalizedCounterField) => normalizedCounterField.incrementBy + ), + counterFieldNames: normalizedCounterFields.map( + (normalizedCounterField) => normalizedCounterField.fieldName + ), + time, + type, }, - upsert: raw._source, }, + upsert: raw._source, }); const { originId } = body.get?._source ?? {}; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.test.ts index 55141d196709c..527ef0a855b28 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.test.ts @@ -147,7 +147,7 @@ describe('internalBulkResolve', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: aliasIds + operations: aliasIds .map((id) => [ { update: { @@ -169,12 +169,10 @@ describe('internalBulkResolve', () => { expect(client.mget).toHaveBeenCalledTimes(1); expect(client.mget).toHaveBeenCalledWith( { - body: { - docs: objectIds.map((id) => ({ - _id: serializer.generateRawId(normalizedNamespace, OBJ_TYPE, id), - _index: `index-for-${OBJ_TYPE}`, - })), - }, + docs: objectIds.map((id) => ({ + _id: serializer.generateRawId(normalizedNamespace, OBJ_TYPE, id), + _index: `index-for-${OBJ_TYPE}`, + })), }, expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts index 7a3a6c00db82f..b76fe9402d20b 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/internal_bulk_resolve.ts @@ -141,7 +141,7 @@ export async function internalBulkResolve( const bulkGetResponse = docsToBulkGet.length ? await client.mget( - { body: { docs: docsToBulkGet } }, + { docs: docsToBulkGet }, { ignore: [404], meta: true } ) : undefined; @@ -330,7 +330,7 @@ async function fetchAndUpdateAliases( const bulkUpdateResponse = await client.bulk({ refresh: false, require_alias: true, - body: bulkUpdateDocs, + operations: bulkUpdateDocs, }); return bulkUpdateResponse.items.map((item) => { // Map the bulk update response to the `_source` fields that were returned for each document diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts index ba355acd01c5f..2b2ddd5d41592 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts @@ -65,8 +65,7 @@ describe('preflightCheckForCreate', () => { docs: results.map(({ found, disabled }, i) => { return found ? { - // @ts-expect-error - _id: params!.body!.docs![i]._id as string, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions + _id: params!.docs![i]._id, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions _index: 'doesnt-matter', _source: { ...(disabled !== undefined && { [LEGACY_URL_ALIAS_TYPE]: { disabled } }), @@ -86,7 +85,7 @@ describe('preflightCheckForCreate', () => { /** Asserts that mget is called for the given raw object IDs */ function expectMgetArgs(...rawObjectIds: string[]) { const docs = rawObjectIds.map((_id) => expect.objectContaining({ _id })); - expect(client.mget).toHaveBeenCalledWith({ body: { docs } }, expect.anything()); + expect(client.mget).toHaveBeenCalledWith({ docs }, expect.anything()); } /** Asserts that findLegacyUrlAliases is called for the given objects */ diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts index 5f9a71e84eb32..4bae59efefdca 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.ts @@ -278,7 +278,7 @@ async function bulkGetObjectsAndAliases( const bulkGetResponse = docsToBulkGet.length ? await client.mget( - { body: { docs: docsToBulkGet } }, + { docs: docsToBulkGet }, { ignore: [404], meta: true } ) : undefined; diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.test.ts index 537bd2db5e81c..426db23b6c57a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.test.ts @@ -134,7 +134,7 @@ describe('#updateObjectsSpaces', () => { /** Asserts that mget is called for the given objects */ function expectMgetArgs(...objects: SavedObjectsUpdateObjectsSpacesObject[]) { const docs = objects.map(({ type, id }) => expect.objectContaining({ _id: `${type}:${id}` })); - expect(client.mget).toHaveBeenCalledWith({ body: { docs } }, expect.anything()); + expect(client.mget).toHaveBeenCalledWith({ docs }, expect.anything()); } /** Mocks the saved objects client so it returns the expected results */ @@ -153,14 +153,14 @@ describe('#updateObjectsSpaces', () => { }); } - /** Asserts that mget is called for the given objects */ + /** Asserts that bulk is called for the given objects */ function expectBulkArgs( ...objectActions: Array<{ object: { type: string; id: string; namespaces?: string[] }; action: 'update' | 'delete'; }> ) { - const body = objectActions.flatMap( + const operations = objectActions.flatMap( ({ object: { type, id, namespaces = expect.any(Array) }, action }) => { const operation = { [action]: { @@ -174,7 +174,7 @@ describe('#updateObjectsSpaces', () => { : [operation]; // 'delete' only uses an operation } ); - expect(client.bulk).toHaveBeenCalledWith(expect.objectContaining({ body })); + expect(client.bulk).toHaveBeenCalledWith(expect.objectContaining({ operations })); } beforeEach(() => { diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts index 9dc10c77e4a09..747db5976f004 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/update_objects_spaces.ts @@ -155,7 +155,7 @@ export async function updateObjectsSpaces({ })); const bulkGetResponse = bulkGetDocs.length ? await client.mget( - { body: { docs: bulkGetDocs } }, + { docs: bulkGetDocs }, { ignore: [404], meta: true } ) : undefined; @@ -261,7 +261,7 @@ export async function updateObjectsSpaces({ const { refresh = DEFAULT_REFRESH_SETTING } = options; const bulkOperationResponse = bulkOperationParams.length - ? await client.bulk({ refresh, body: bulkOperationParams, require_alias: true }) + ? await client.bulk({ refresh, operations: bulkOperationParams, require_alias: true }) : undefined; // Delete aliases if necessary, ensuring we don't have too many concurrent operations running. diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/open_point_in_time.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/open_point_in_time.test.ts index 2efc33eddddfd..bda6952138c41 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/open_point_in_time.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/open_point_in_time.test.ts @@ -189,9 +189,7 @@ describe('SavedObjectsRepository', () => { await successResponse('abc123'); expect(client.closePointInTime).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - id: 'abc123', - }), + id: 'abc123', }), expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts index 81466f05aa62f..cbc864adf0e39 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.test.ts @@ -106,9 +106,7 @@ describe('SavedObjectsRepository', () => { await removeReferencesToSuccess(client, repository, type, id, { type }); expect(client.updateByQuery).toHaveBeenCalledWith( - expect.objectContaining({ - body: expect.objectContaining({ ...query }), - }), + expect.objectContaining({ ...query }), expect.anything() ); }); @@ -139,13 +137,11 @@ describe('SavedObjectsRepository', () => { await removeReferencesToSuccess(client, repository, type, id); expect(client.updateByQuery).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - script: expect.objectContaining({ - params: { - type, - id, - }, - }), + script: expect.objectContaining({ + params: { + type, + id, + }, }), }), expect.anything() @@ -270,11 +266,10 @@ describe('SavedObjectsRepository', () => { const client = apiExecutionContext.client; expect(client.updateByQuery).toHaveBeenCalledTimes(1); expect(client.updateByQuery).toHaveBeenLastCalledWith( - { + expect.objectContaining({ refresh: false, index: indices, - body: expect.any(Object), - }, + }), { ignore: [404], meta: true } ); }); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts index ec34343d9818c..e279643da041a 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts @@ -43,32 +43,30 @@ export const performRemoveReferencesTo = async ( { index: targetIndices, refresh, - body: { - script: { - source: ` - if (ctx._source.containsKey('references')) { - def items_to_remove = []; - for (item in ctx._source.references) { - if ( (item['type'] == params['type']) && (item['id'] == params['id']) ) { - items_to_remove.add(item); - } - } - ctx._source.references.removeAll(items_to_remove); + script: { + source: ` + if (ctx._source.containsKey('references')) { + def items_to_remove = []; + for (item in ctx._source.references) { + if ( (item['type'] == params['type']) && (item['id'] == params['id']) ) { + items_to_remove.add(item); } - `, - params: { - type, - id, - }, - lang: 'painless', + } + ctx._source.references.removeAll(items_to_remove); + } + `, + params: { + type, + id, }, - conflicts: 'proceed', - ...getSearchDsl(mappings, registry, { - namespaces: namespace ? [namespace] : undefined, - type: allTypes, - hasReference: { type, id }, - }), + lang: 'painless', }, + conflicts: 'proceed', + ...getSearchDsl(mappings, registry, { + namespaces: namespace ? [namespace] : undefined, + type: allTypes, + hasReference: { type, id }, + }), }, { ignore: [404], meta: true } ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts index 1de72f31b80a0..7881947f58cc1 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.test.ts @@ -190,7 +190,7 @@ describe('#update', () => { expect(client.index).toHaveBeenCalledTimes(1); expect(client.index).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ + document: expect.objectContaining({ globalType: { foo: 'bar', title: 'Testing', @@ -219,7 +219,7 @@ describe('#update', () => { expect(client.index).toHaveBeenCalledTimes(1); expect(client.index).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ + document: expect.objectContaining({ globalType: { foo: 'bar', }, @@ -385,7 +385,7 @@ describe('#update', () => { index: '.kibana-test_8.0.0-testing', refresh: 'wait_for', require_alias: true, - body: expect.objectContaining({ + document: expect.objectContaining({ multiNamespaceIsolatedType: { title: 'Testing' }, namespaces: ['default'], references: [], diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.ts index 2fdad31c2936d..552885bfd51b9 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/update.ts @@ -22,6 +22,7 @@ import type { SavedObjectsUpdateResponse, } from '@kbn/core-saved-objects-api-server'; import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal'; +import type { CreateRequest, IndexRequest } from '@elastic/elasticsearch/lib/api/types'; import { DEFAULT_REFRESH_SETTING, DEFAULT_RETRY_COUNT } from '../constants'; import { isValidRequest } from '../utils'; import { getCurrentTime, getSavedObjectFromSource, mergeForUpdate } from './utils'; @@ -187,12 +188,13 @@ export const executeUpdate = async ( validationHelper.validateObjectForCreate(type, migratedUpsert); const rawUpsert = serializer.savedObjectToRaw(migratedUpsert); - const createRequestParams = { + const createRequestParams: CreateRequest = { id: rawUpsert._id, index: commonHelper.getIndexForType(type), refresh, - body: rawUpsert._source, + document: rawUpsert._source, ...(version ? decodeRequestVersion(version) : {}), + // @ts-expect-error require_alias: true, }; @@ -289,11 +291,11 @@ export const executeUpdate = async ( ); // implement creating the call params - const indexRequestParams = { + const indexRequestParams: IndexRequest = { id: docToSend._id, index: commonHelper.getIndexForType(type), refresh, - body: docToSend._source, + document: docToSend._source, // using version from the source doc if not provided as option to avoid erasing changes in case of concurrent calls ...decodeRequestVersion(version || migrated!.version), require_alias: true, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts index a02c20b2db9a4..5c1a9ecfce2a6 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.encryption_extension.test.ts @@ -440,14 +440,12 @@ describe('SavedObjectsRepository Encryption Extension', () => { ) => { expect(client.mget).toHaveBeenCalledWith( expect.objectContaining({ - body: { - docs: objects.map(({ type, id }) => - expect.objectContaining({ - _index, - _id: getId(type, id), - }) - ), - }, + docs: objects.map(({ type, id }) => + expect.objectContaining({ + _index, + _id: getId(type, id), + }) + ), }), expect.anything() ); diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts index 73e663133007a..c880baadb5eed 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts @@ -234,7 +234,7 @@ describe('SavedObjectsRepository Spaces Extension', () => { id: `${ currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : '' }${type}:${id}`, - body: expect.objectContaining( + document: expect.objectContaining( currentSpace.expectedNamespace ? { namespace: currentSpace.expectedNamespace, @@ -274,7 +274,7 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.create).toHaveBeenCalledWith( expect.objectContaining({ id: expect.stringMatching(regex), - body: expect.objectContaining( + document: expect.objectContaining( currentSpace.expectedNamespace ? { namespace: currentSpace.expectedNamespace, @@ -379,18 +379,16 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.mget).toHaveBeenCalledTimes(1); expect(client.mget).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - docs: expect.arrayContaining([ - expect.objectContaining({ - _id: `${ - currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : '' - }${obj1.type}:${obj1.id}`, - }), - expect.objectContaining({ - _id: `${obj2.type}:${obj2.id}`, - }), - ]), - }), + docs: expect.arrayContaining([ + expect.objectContaining({ + _id: `${ + currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : '' + }${obj1.type}:${obj1.id}`, + }), + expect.objectContaining({ + _id: `${obj2.type}:${obj2.id}`, + }), + ]), }), { ignore: [404], meta: true } ); @@ -570,18 +568,16 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.mget).toHaveBeenCalledTimes(1); expect(client.mget).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.objectContaining({ - docs: expect.arrayContaining([ - expect.objectContaining({ - _id: `${ - currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : '' - }${obj1.type}:${obj1.id}`, - }), - expect.objectContaining({ - _id: `${obj2.type}:${obj2.id}`, - }), - ]), - }), + docs: expect.arrayContaining([ + expect.objectContaining({ + _id: `${ + currentSpace.expectedNamespace ? `${currentSpace.expectedNamespace}:` : '' + }${obj1.type}:${obj1.id}`, + }), + expect.objectContaining({ + _id: `${obj2.type}:${obj2.id}`, + }), + ]), }), { ignore: [404], meta: true } ); @@ -638,7 +634,7 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.arrayContaining([ + operations: expect.arrayContaining([ expect.objectContaining({ create: expect.objectContaining({ _id: `${ @@ -696,7 +692,7 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.arrayContaining([ + operations: expect.arrayContaining([ expect.objectContaining({ index: expect.objectContaining({ _id: `${ @@ -855,7 +851,7 @@ describe('SavedObjectsRepository Spaces Extension', () => { expect(client.bulk).toHaveBeenCalledTimes(1); expect(client.bulk).toHaveBeenCalledWith( expect.objectContaining({ - body: expect.arrayContaining([ + operations: expect.arrayContaining([ expect.objectContaining({ delete: expect.objectContaining({ _id: `${ diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts index b2b8de1b4192a..926a36a3bc207 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts @@ -537,9 +537,7 @@ export class SavedObjectsRepository implements ISavedObjectsRepository { this.extensions.securityExtension.auditClosePointInTime(); } - return await this.client.closePointInTime({ - body: { id }, - }); + return await this.client.closePointInTime({ id }); } /** diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository_es_client.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository_es_client.test.ts index b8f2ee6e41e3d..d271777f52294 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository_es_client.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository_es_client.test.ts @@ -25,19 +25,19 @@ describe('RepositoryEsClient', () => { it('delegates call to ES client method', async () => { expect(repositoryClient.bulk).toStrictEqual(expect.any(Function)); - await repositoryClient.bulk({ body: [] }); + await repositoryClient.bulk({ operations: [] }); expect(client.bulk).toHaveBeenCalledTimes(1); }); it('wraps a method call in retryCallCluster', async () => { - await repositoryClient.bulk({ body: [] }); + await repositoryClient.bulk({ operations: [] }); expect(retryCallClusterMock).toHaveBeenCalledTimes(1); }); it('keeps call options unchanged', async () => { expect(repositoryClient.bulk).toStrictEqual(expect.any(Function)); const options = { maxRetries: 12 }; - await repositoryClient.bulk({ body: [] }, options); + await repositoryClient.bulk({ operations: [] }, options); expect(client.bulk).toHaveBeenCalledWith(expect.any(Object), options); }); @@ -45,7 +45,7 @@ describe('RepositoryEsClient', () => { expect.assertions(1); client.bulk.mockRejectedValue(new Error('reason')); try { - await repositoryClient.bulk({ body: [] }); + await repositoryClient.bulk({ operations: [] }); } catch (e) { expect(SavedObjectsErrorHelpers.isSavedObjectsClientError(e)).toBe(true); } From bdea091f0f347707afc3dc4371dff20f51ab12c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2024 18:05:26 +0100 Subject: [PATCH 5/6] Address CI issues --- .../src/lib/apis/find.ts | 3 --- .../src/lib/apis/internals/preflight_check_for_create.test.ts | 1 + 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts index c333642dd206a..ee3f98eade3d5 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/find.ts @@ -191,10 +191,7 @@ export const performFind = async ( preference, rest_total_hits_as_int: true, size: perPage, - size: perPage, seq_no_primary_term: true, - from: perPage * (page - 1), - _source: includedFields(allowedTypes, fields), ...(aggsObject ? { aggs: aggsObject } : {}), ...getSearchDsl(mappings, registry, { search, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts index 2b2ddd5d41592..e16ef3aacacf0 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/internals/preflight_check_for_create.test.ts @@ -65,6 +65,7 @@ describe('preflightCheckForCreate', () => { docs: results.map(({ found, disabled }, i) => { return found ? { + // @ts-expect-error _id: params!.docs![i]._id, // needed for mockRawDocExistsInNamespaces mock implementation and existingDocument assertions _index: 'doesnt-matter', _source: { From 8941931c48539d0033e246ebf44a6d14fec4e27a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Fri, 20 Dec 2024 18:17:49 +0100 Subject: [PATCH 6/6] Address CI issues --- .../src/lib/apis/remove_references_to.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts index e279643da041a..0deb2db4a9df4 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/remove_references_to.ts @@ -62,11 +62,11 @@ export const performRemoveReferencesTo = async ( lang: 'painless', }, conflicts: 'proceed', - ...getSearchDsl(mappings, registry, { + ...(getSearchDsl(mappings, registry, { namespaces: namespace ? [namespace] : undefined, type: allTypes, hasReference: { type, id }, - }), + }) as Omit, 'sort'>), // TS is complaining and it's unlikely that we sort here }, { ignore: [404], meta: true } );