diff --git a/package.json b/package.json index 914855a21a699..a365302acab78 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "@elastic/apm-rum-react": "^1.2.5", "@elastic/charts": "28.2.0", "@elastic/datemath": "link:bazel-bin/packages/elastic-datemath/npm_module", - "@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@7.13.0-canary.1", + "@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@7.13.0-canary.4", "@elastic/ems-client": "7.13.0", "@elastic/eui": "32.1.0", "@elastic/filesaver": "1.1.2", diff --git a/packages/kbn-es-archiver/src/lib/indices/delete_index.ts b/packages/kbn-es-archiver/src/lib/indices/delete_index.ts index 2a42d52e2ca80..c9a234da3c17a 100644 --- a/packages/kbn-es-archiver/src/lib/indices/delete_index.ts +++ b/packages/kbn-es-archiver/src/lib/indices/delete_index.ts @@ -120,7 +120,7 @@ export async function waitForSnapshotCompletion( } ); - return inProgressSnapshots; + return inProgressSnapshots ?? []; }; const { body: repositoryMap } = await client.snapshot.getRepository({} as any); diff --git a/src/core/server/saved_objects/migrations/core/elastic_index.test.ts b/src/core/server/saved_objects/migrations/core/elastic_index.test.ts index 1d2ec6abc0dd1..f1f0e2f9559f9 100644 --- a/src/core/server/saved_objects/migrations/core/elastic_index.test.ts +++ b/src/core/server/saved_objects/migrations/core/elastic_index.test.ts @@ -40,7 +40,7 @@ describe('ElasticIndex', () => { return elasticsearchClientMock.createSuccessTransportRequestPromise({ [index]: { aliases: { foo: index }, - mappings: { dynamic: 'strict', properties: { a: 'b' } }, + mappings: { dynamic: 'strict', properties: { a: { type: 'flattened' } } }, settings: {}, }, } as estypes.GetIndexResponse); @@ -49,7 +49,7 @@ describe('ElasticIndex', () => { const info = await Index.fetchInfo(client, '.baz'); expect(info).toEqual({ aliases: { foo: '.baz' }, - mappings: { dynamic: 'strict', properties: { a: 'b' } }, + mappings: { dynamic: 'strict', properties: { a: { type: 'flattened' } } }, exists: true, indexName: '.baz', settings: {}, diff --git a/src/core/server/saved_objects/migrations/core/elastic_index.ts b/src/core/server/saved_objects/migrations/core/elastic_index.ts index 460aabbc77415..e8d083fe2759a 100644 --- a/src/core/server/saved_objects/migrations/core/elastic_index.ts +++ b/src/core/server/saved_objects/migrations/core/elastic_index.ts @@ -261,7 +261,7 @@ export async function createIndex( mappings?: IndexMapping ) { await client.indices.create({ - body: { mappings, settings }, + body: { mappings: mappings as estypes.TypeMapping, settings }, index, }); } @@ -283,7 +283,7 @@ export async function convertToAlias( script?: string ) { await client.indices.create({ - body: { mappings: info.mappings, settings }, + body: { mappings: info.mappings as estypes.TypeMapping, settings }, index: info.indexName, }); @@ -406,7 +406,6 @@ async function reindex( task_id: String(task), }); - // @ts-expect-error @elastic/elasticsearch GetTaskResponse doesn't contain `error` property const e = body.error; if (e) { throw new Error(`Re-index failed [${e.type}] ${e.reason} :: ${JSON.stringify(e)}`); diff --git a/src/core/server/saved_objects/migrations/kibana/kibana_migrator.test.ts b/src/core/server/saved_objects/migrations/kibana/kibana_migrator.test.ts index 221e78e3e12e2..c6d727bc63530 100644 --- a/src/core/server/saved_objects/migrations/kibana/kibana_migrator.test.ts +++ b/src/core/server/saved_objects/migrations/kibana/kibana_migrator.test.ts @@ -15,6 +15,7 @@ import { loggingSystemMock } from '../../../logging/logging_system.mock'; import { SavedObjectTypeRegistry } from '../../saved_objects_type_registry'; import { SavedObjectsType } from '../../types'; import { DocumentMigrator } from '../core/document_migrator'; + jest.mock('../core/document_migrator', () => { return { // Create a mock for spying on the constructor @@ -362,7 +363,11 @@ const mockV2MigrationOptions = () => { ) ); options.client.indices.addBlock.mockReturnValue( - elasticsearchClientMock.createSuccessTransportRequestPromise({ acknowledged: true }) + elasticsearchClientMock.createSuccessTransportRequestPromise({ + acknowledged: true, + shards_acknowledged: true, + indices: [], + }) ); options.client.reindex.mockReturnValue( elasticsearchClientMock.createSuccessTransportRequestPromise({ diff --git a/src/core/server/saved_objects/migrationsv2/actions/index.ts b/src/core/server/saved_objects/migrationsv2/actions/index.ts index 02d3f8e21a510..00ff18a9b430c 100644 --- a/src/core/server/saved_objects/migrationsv2/actions/index.ts +++ b/src/core/server/saved_objects/migrationsv2/actions/index.ts @@ -21,6 +21,7 @@ import { catchRetryableEsClientErrors, RetryableEsClientError, } from './catch_retryable_es_client_errors'; + export type { RetryableEsClientError }; /** @@ -90,6 +91,7 @@ export interface IndexNotFound { type: 'index_not_found_exception'; index: string; } + /** * Sets a write block in place for the given index. If the response includes * `acknowledged: true` all in-progress writes have drained and no further @@ -305,7 +307,7 @@ export const cloneIndex = ( }; interface WaitForTaskResponse { - error: Option.Option<{ type: string; reason: string; index: string }>; + error: Option.Option<{ type: string; reason: string; index?: string }>; completed: boolean; failures: Option.Option; description?: string; @@ -367,7 +369,6 @@ const waitForTask = ( const failures = body.response?.failures ?? []; return Either.right({ completed: body.completed, - // @ts-expect-error @elastic/elasticsearch GetTaskResponse doesn't declare `error` property error: Option.fromNullable(body.error), failures: failures.length > 0 ? Option.some(failures) : Option.none, description: body.task.description, @@ -523,7 +524,7 @@ export const waitForReindexTask = flow( if (res.error.value.type === 'index_not_found_exception') { return TaskEither.left({ type: 'index_not_found_exception' as const, - index: res.error.value.index, + index: res.error.value.index ?? 'unknown', }); } else { throw new Error('Reindex failed with the following error:\n' + JSON.stringify(res.error)); @@ -720,7 +721,7 @@ export const createIndex = ( // started timeout: DEFAULT_TIMEOUT, body: { - mappings, + mappings: mappings as estypes.TypeMapping, aliases: aliasesObject, settings: { index: { @@ -813,7 +814,7 @@ export const updateAndPickupMappings = ( .putMapping({ index, timeout: DEFAULT_TIMEOUT, - body: mappings, + body: mappings as estypes.TypeMapping, }) .then((res) => { // Ignore `acknowledged: false`. When the coordinating node accepts @@ -842,6 +843,7 @@ export const updateAndPickupMappings = ( }) ); }; + export interface SearchResponse { outdatedDocuments: SavedObjectsRawDoc[]; } diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index c0e2cdc333363..ca6479ff0829a 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -665,7 +665,6 @@ export class SavedObjectsRepository { } const deleteDocNotFound = body.result === 'not_found'; - // @ts-expect-error 'error' does not exist on type 'DeleteResponse' const deleteIndexNotFound = body.error && body.error.type === 'index_not_found_exception'; if (deleteDocNotFound || deleteIndexNotFound) { // see "404s from missing index" above @@ -1386,7 +1385,6 @@ export class SavedObjectsRepository { } const deleteDocNotFound = body.result === 'not_found'; - // @ts-expect-error const deleteIndexNotFound = body.error && body.error.type === 'index_not_found_exception'; if (deleteDocNotFound || deleteIndexNotFound) { // see "404s from missing index" above @@ -1920,13 +1918,9 @@ export class SavedObjectsRepository { const { body, statusCode, - } = await this.client.openPointInTime( - // @ts-expect-error @elastic/elasticsearch OpenPointInTimeRequest.index expected to accept string[] - esOptions, - { - ignore: [404], - } - ); + } = await this.client.openPointInTime(esOptions, { + ignore: [404], + }); if (statusCode === 404) { throw SavedObjectsErrorHelpers.createGenericNotFoundError(); } diff --git a/yarn.lock b/yarn.lock index 4e98d54dd4efa..85507c0c1c479 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1389,10 +1389,10 @@ version "0.0.0" uid "" -"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@7.13.0-canary.1": - version "7.13.0-canary.1" - resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-7.13.0-canary.1.tgz#53a8ddbaeaba77dc163aad972e56d6741c98858a" - integrity sha512-RqJxZyouL/lTN4EgBvN9xQKq0zUIzSUAks91q/UvM41XyATTeTa2e9+zxrK07JCi0R6l/xAlHrLglf1/LiJOyg== +"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@7.13.0-canary.4": + version "7.13.0-canary.4" + resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-7.13.0-canary.4.tgz#10c321e6a268ffa2090d5b585fe5bf5e17ac840f" + integrity sha512-EIbT252HbTktRgYnJ06YXz+E6iRudhT6wBckOngAcycyfsjL8T8sVlE4EtyFKsgQUacjIEt2g7ZB43AJc4218Q== dependencies: debug "^4.3.1" hpagent "^0.1.1"