Skip to content

Commit

Permalink
do not import types from the legacy elasticsearch package
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Jul 28, 2021
1 parent 63bedaa commit 702b2b5
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/plugins/data/common/search/search_source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import type { estypes } from '@elastic/elasticsearch';
import { NameList } from 'elasticsearch';
import { IAggConfigs } from 'src/plugins/data/public';
import { Query } from '../..';
import { Filter } from '../../es_query';
Expand Down Expand Up @@ -90,7 +89,7 @@ export interface SearchSourceFields {
aggs?: object | IAggConfigs | (() => object);
from?: number;
size?: number;
source?: NameList;
source?: boolean | estypes.Fields;
version?: boolean;
/**
* Retrieve fields via the search Fields API
Expand All @@ -101,7 +100,7 @@ export interface SearchSourceFields {
*
* @deprecated It is recommended to use `fields` wherever possible.
*/
fieldsFromSource?: NameList;
fieldsFromSource?: estypes.Fields;
/**
* {@link IndexPatternService}
*/
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/common/search/tabify/tabify_docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { tabifyDocs } from './tabify_docs';
import { IndexPattern } from '../../index_patterns/index_patterns';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';

describe('tabifyDocs', () => {
const fieldFormats = {
Expand All @@ -33,6 +33,7 @@ describe('tabifyDocs', () => {
fieldFormats: fieldFormats as any,
});

// @ts-expect-error not full inteface
const response = {
hits: {
hits: [
Expand All @@ -46,7 +47,7 @@ describe('tabifyDocs', () => {
},
],
},
} as SearchResponse<unknown>;
} as estypes.SearchResponse<unknown>;

it('converts fields by default', () => {
const table = tabifyDocs(response, index);
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/data/common/search/tabify/tabify_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { isPlainObject } from 'lodash';
import { IndexPattern } from '../../index_patterns/index_patterns';
import { Datatable, DatatableColumn, DatatableColumnType } from '../../../../expressions/common';
Expand All @@ -18,7 +18,7 @@ export interface TabifyDocsOptions {
}

export function flattenHit(
hit: SearchResponse<unknown>['hits']['hits'][0],
hit: estypes.SearchHit,
indexPattern?: IndexPattern,
params?: TabifyDocsOptions
) {
Expand Down Expand Up @@ -58,7 +58,7 @@ export function flattenHit(
}
}

flatten(hit.fields);
flatten(hit.fields || {});
if (params?.source !== false && hit._source) {
flatten(hit._source as Record<string, any>);
}
Expand All @@ -72,7 +72,7 @@ export function flattenHit(
}

export const tabifyDocs = (
esResponse: SearchResponse<unknown>,
esResponse: estypes.SearchResponse<unknown>,
index?: IndexPattern,
params: TabifyDocsOptions = {}
): Datatable => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Side Public License, v 1.
*/

import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';

export const shardFailureResponse: SearchResponse<any> = {
export const shardFailureResponse: estypes.SearchResponse<any> = {
_shards: {
total: 2,
successful: 1,
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/data/server/autocomplete/terms_agg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ConfigSchema } from '../../config';
import type { DeeplyMockedKeys } from '@kbn/utility-types/jest';
import type { ApiResponse } from '@elastic/elasticsearch';
import { termsAggSuggestions } from './terms_agg';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { duration } from 'moment';

let savedObjectsClientMock: jest.Mocked<SavedObjectsClientContract>;
Expand All @@ -22,6 +22,8 @@ const configMock = ({
valueSuggestions: { timeout: duration(4513), terminateAfter: duration(98430) },
},
} as unknown) as ConfigSchema;

// @ts-expect-error not full interface
const mockResponse = {
body: {
aggregations: {
Expand All @@ -30,7 +32,7 @@ const mockResponse = {
},
},
},
} as ApiResponse<SearchResponse<any>>;
} as ApiResponse<estypes.SearchResponse<any>>;

jest.mock('../index_patterns');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { getTotalLoaded, toKibanaSearchResponse, shimHitsTotal } from './response_utils';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';

describe('response utils', () => {
describe('getTotalLoaded', () => {
Expand All @@ -19,7 +19,7 @@ describe('response utils', () => {
skipped: 5,
total: 100,
},
} as unknown) as SearchResponse<unknown>);
} as unknown) as estypes.SearchResponse<unknown>);

expect(result).toEqual({
total: 100,
Expand All @@ -37,7 +37,7 @@ describe('response utils', () => {
skipped: 5,
total: 100,
},
} as unknown) as SearchResponse<unknown>);
} as unknown) as estypes.SearchResponse<unknown>);

expect(result).toEqual({
rawResponse: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import type { Observable } from 'rxjs';
import type { IScopedClusterClient, Logger, SharedGlobalConfig } from 'kibana/server';
import { catchError, first, tap } from 'rxjs/operators';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { from } from 'rxjs';
import type { ISearchStrategy, SearchStrategyDependencies } from '../../types';
import type {
Expand Down Expand Up @@ -121,7 +121,7 @@ export const enhancedEsSearchStrategyProvider = (
});

const esResponse = await shimAbortSignal(promise, options?.abortSignal);
const response = esResponse.body as SearchResponse<any>;
const response = esResponse.body as estypes.SearchResponse<any>;
return {
rawResponse: shimHitsTotal(response, options),
...getTotalLoaded(response),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import type { estypes } from '@elastic/elasticsearch';
import { ShardsResponse } from 'elasticsearch';

export interface AsyncSearchResponse<T = unknown> {
id?: string;
Expand All @@ -19,5 +18,5 @@ export interface AsyncSearchResponse<T = unknown> {
}
export interface AsyncSearchStatusResponse extends Omit<AsyncSearchResponse, 'response'> {
completion_status: number;
_shards: ShardsResponse;
_shards: estypes.ShardStatistics;
}

0 comments on commit 702b2b5

Please sign in to comment.