From 4bae1ff164205c73085ffdd084e55cfc26ba6e3d Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 31 Jul 2021 03:52:18 -0400 Subject: [PATCH] remove elasticsearch package imports from reporting (#107126) (#107297) * remove elasticsearch package imports from reporting * remove dead code Co-authored-by: Mikhail Shustov --- .../generate_csv/generate_csv.ts | 10 ++++----- .../reporting/server/routes/generation.ts | 21 ------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts b/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts index 254bc0ae21f6ca..a38e0d58abf89a 100644 --- a/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts +++ b/x-pack/plugins/reporting/server/export_types/csv_searchsource/generate_csv/generate_csv.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import { SearchResponse } from 'elasticsearch'; +import type { estypes } from '@elastic/elasticsearch'; import { IScopedClusterClient, IUiSettingsClient } from 'src/core/server'; import { IScopedSearchClient } from 'src/plugins/data/server'; import { Datatable } from 'src/plugins/expressions/server'; @@ -93,7 +93,7 @@ export class CsvGenerator { }; const results = ( await this.clients.data.search(searchParams, { strategy: ES_SEARCH_STRATEGY }).toPromise() - ).rawResponse as SearchResponse; + ).rawResponse as estypes.SearchResponse; return results; } @@ -107,7 +107,7 @@ export class CsvGenerator { scroll_id: scrollId, }, }) - ).body as SearchResponse; + ).body; return results; } @@ -321,13 +321,13 @@ export class CsvGenerator { if (this.cancellationToken.isCancelled()) { break; } - let results: SearchResponse | undefined; + let results: estypes.SearchResponse | undefined; if (scrollId == null) { // open a scroll cursor in Elasticsearch results = await this.scan(index, searchSource, scrollSettings); scrollId = results?._scroll_id; if (results.hits?.total != null) { - totalRecords = results.hits.total; + totalRecords = results.hits.total as number; this.logger.debug(`Total search results: ${totalRecords}`); } } else { diff --git a/x-pack/plugins/reporting/server/routes/generation.ts b/x-pack/plugins/reporting/server/routes/generation.ts index e90e059c11c67b..0047afa4d9d7bd 100644 --- a/x-pack/plugins/reporting/server/routes/generation.ts +++ b/x-pack/plugins/reporting/server/routes/generation.ts @@ -6,7 +6,6 @@ */ import Boom from '@hapi/boom'; -import { errors as elasticsearchErrors } from 'elasticsearch'; import { kibanaResponseFactory } from 'src/core/server'; import { ReportingCore } from '../'; import { API_BASE_URL } from '../../common/constants'; @@ -17,8 +16,6 @@ import { registerLegacy } from './legacy'; import { registerGenerateCsvFromSavedObjectImmediate } from './csv_searchsource_immediate'; import { HandlerFunction } from './types'; -const esErrors = elasticsearchErrors as Record; - const getDownloadBaseUrl = (reporting: ReportingCore) => { const config = reporting.getConfig(); return config.kbnConfig.get('server', 'basePath') + `${API_BASE_URL}/jobs/download`; @@ -78,24 +75,6 @@ export function registerJobGenerationRoutes(reporting: ReportingCore, logger: Lo }); } - if (err instanceof esErrors['401']) { - return res.unauthorized({ - body: `Sorry, you aren't authenticated`, - }); - } - - if (err instanceof esErrors['403']) { - return res.forbidden({ - body: `Sorry, you are not authorized`, - }); - } - - if (err instanceof esErrors['404']) { - return res.notFound({ - body: err.message, - }); - } - // unknown error, can't convert to 4xx throw err; }