Skip to content

Commit

Permalink
remove elasticsearch package imports from reporting (#107126) (#107297)
Browse files Browse the repository at this point in the history
* remove elasticsearch package imports from reporting

* remove dead code

Co-authored-by: Mikhail Shustov <[email protected]>
  • Loading branch information
kibanamachine and mshustov authored Jul 31, 2021
1 parent 17d7976 commit 4bae1ff
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -93,7 +93,7 @@ export class CsvGenerator {
};
const results = (
await this.clients.data.search(searchParams, { strategy: ES_SEARCH_STRATEGY }).toPromise()
).rawResponse as SearchResponse<unknown>;
).rawResponse as estypes.SearchResponse<unknown>;

return results;
}
Expand All @@ -107,7 +107,7 @@ export class CsvGenerator {
scroll_id: scrollId,
},
})
).body as SearchResponse<unknown>;
).body;
return results;
}

Expand Down Expand Up @@ -321,13 +321,13 @@ export class CsvGenerator {
if (this.cancellationToken.isCancelled()) {
break;
}
let results: SearchResponse<unknown> | undefined;
let results: estypes.SearchResponse<unknown> | 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 {
Expand Down
21 changes: 0 additions & 21 deletions x-pack/plugins/reporting/server/routes/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,8 +16,6 @@ import { registerLegacy } from './legacy';
import { registerGenerateCsvFromSavedObjectImmediate } from './csv_searchsource_immediate';
import { HandlerFunction } from './types';

const esErrors = elasticsearchErrors as Record<string, any>;

const getDownloadBaseUrl = (reporting: ReportingCore) => {
const config = reporting.getConfig();
return config.kbnConfig.get('server', 'basePath') + `${API_BASE_URL}/jobs/download`;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4bae1ff

Please sign in to comment.