diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md index dc83cfb930d7..a5453c7c51d5 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md @@ -156,8 +156,6 @@ | [RangeFilterMeta](./kibana-plugin-plugins-data-public.rangefiltermeta.md) | | | [SavedQueryTimeFilter](./kibana-plugin-plugins-data-public.savedquerytimefilter.md) | | | [SearchBarProps](./kibana-plugin-plugins-data-public.searchbarprops.md) | | -| [SearchRequest](./kibana-plugin-plugins-data-public.searchrequest.md) | | -| [SearchResponse](./kibana-plugin-plugins-data-public.searchresponse.md) | | | [StatefulSearchBarProps](./kibana-plugin-plugins-data-public.statefulsearchbarprops.md) | | | [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* | | [TimefilterContract](./kibana-plugin-plugins-data-public.timefiltercontract.md) | | diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchrequest.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchrequest.md deleted file mode 100644 index dbb465839e52..000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchrequest.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchRequest](./kibana-plugin-plugins-data-public.searchrequest.md) - -## SearchRequest type - -Signature: - -```typescript -export declare type SearchRequest = any; -``` diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchresponse.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchresponse.md deleted file mode 100644 index 6da31c8bced7..000000000000 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchresponse.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchResponse](./kibana-plugin-plugins-data-public.searchresponse.md) - -## SearchResponse type - -Signature: - -```typescript -export declare type SearchResponse = any; -``` diff --git a/src/plugins/data/common/search/es_search/types.ts b/src/plugins/data/common/search/es_search/types.ts index 654ed3899656..3184fbe34170 100644 --- a/src/plugins/data/common/search/es_search/types.ts +++ b/src/plugins/data/common/search/es_search/types.ts @@ -22,9 +22,9 @@ import { IKibanaSearchRequest, IKibanaSearchResponse } from '../types'; export const ES_SEARCH_STRATEGY = 'es'; -export type ISearchRequestParams = { +export type ISearchRequestParams> = { trackTotalHits?: boolean; -} & Search; +} & Search; export interface IEsSearchRequest extends IKibanaSearchRequest { params?: ISearchRequestParams; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index ecf076aa517f..eb5703f1c63c 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -360,7 +360,6 @@ export { SearchInterceptor, SearchInterceptorDeps, SearchRequest, - SearchResponse, SearchSourceFields, SortDirection, // expression functions and types diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 35ee1789b2fd..f8a108a5a4c5 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -61,7 +61,7 @@ import { SavedObject } from 'src/core/server'; import { SavedObject as SavedObject_3 } from 'src/core/public'; import { SavedObjectsClientContract } from 'src/core/public'; import { Search } from '@elastic/elasticsearch/api/requestParams'; -import { SearchResponse as SearchResponse_2 } from 'elasticsearch'; +import { SearchResponse } from 'elasticsearch'; import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/common'; import { Subscription } from 'rxjs'; import { Toast } from 'kibana/public'; @@ -727,6 +727,7 @@ export function getEsPreference(uiSettings: IUiSettingsClient_2, sessionId?: str export const getKbnTypeNames: () => string[]; // Warning: (ae-forgotten-export) The symbol "ISearchRequestParams" needs to be exported by the entry point index.d.ts +// Warning: (ae-incompatible-release-tags) The symbol "getSearchParamsFromRequest" is marked as @public, but its signature references "SearchRequest" which is marked as @internal // // @public (undocumented) export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: { @@ -795,7 +796,7 @@ export interface IEsSearchResponse extends IKibanaSearchResponse { isPartial?: boolean; isRunning?: boolean; // (undocumented) - rawResponse: SearchResponse_2; + rawResponse: SearchResponse; } // Warning: (ae-missing-release-tag) "IFieldFormat" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -1783,15 +1784,8 @@ export interface SearchInterceptorDeps { usageCollector?: SearchUsageCollector; } -// Warning: (ae-missing-release-tag) "SearchRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type SearchRequest = any; - -// Warning: (ae-missing-release-tag) "SearchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// -// @public (undocumented) -export type SearchResponse = any; +// @internal +export type SearchRequest = Record; // Warning: (ae-missing-release-tag) "SearchSourceFields" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // @@ -1991,21 +1985,21 @@ export const UI_SETTINGS: { // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "getFromSavedObject" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts // src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:372:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:372:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:372:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:372:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:374:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:375:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:384:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:385:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:386:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:392:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:396:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts -// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:371:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:371:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:371:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:371:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:373:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:374:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:383:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:384:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:385:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:386:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:394:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:395:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts +// src/plugins/data/public/index.ts:398:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/public/query/state_sync/connect_to_query_state.ts:45:5 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:62:5 - (ae-forgotten-export) The symbol "createFiltersFromValueClickAction" needs to be exported by the entry point index.d.ts // src/plugins/data/public/types.ts:63:5 - (ae-forgotten-export) The symbol "createFiltersFromRangeSelectAction" needs to be exported by the entry point index.d.ts diff --git a/src/plugins/data/public/search/fetch/handle_response.test.ts b/src/plugins/data/public/search/fetch/handle_response.test.ts index 10e6eda3de3d..9a9d806bc9cf 100644 --- a/src/plugins/data/public/search/fetch/handle_response.test.ts +++ b/src/plugins/data/public/search/fetch/handle_response.test.ts @@ -23,6 +23,7 @@ import { handleResponse } from './handle_response'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock'; import { setNotifications } from '../../services'; +import { SearchResponse } from 'elasticsearch'; jest.mock('@kbn/i18n', () => { return { @@ -44,7 +45,7 @@ describe('handleResponse', () => { const request = { body: {} }; const response = { timed_out: true, - }; + } as SearchResponse; const result = handleResponse(request, response); expect(result).toBe(response); expect(notifications.toasts.addWarning).toBeCalled(); @@ -57,9 +58,12 @@ describe('handleResponse', () => { const request = { body: {} }; const response = { _shards: { - failed: true, + failed: 1, + total: 2, + successful: 1, + skipped: 1, }, - }; + } as SearchResponse; const result = handleResponse(request, response); expect(result).toBe(response); expect(notifications.toasts.addWarning).toBeCalled(); @@ -70,7 +74,7 @@ describe('handleResponse', () => { test('returns the response', () => { const request = {}; - const response = {}; + const response = {} as SearchResponse; const result = handleResponse(request, response); expect(result).toBe(response); }); diff --git a/src/plugins/data/public/search/fetch/handle_response.tsx b/src/plugins/data/public/search/fetch/handle_response.tsx index 7905468f91c5..14e9b59f49bf 100644 --- a/src/plugins/data/public/search/fetch/handle_response.tsx +++ b/src/plugins/data/public/search/fetch/handle_response.tsx @@ -20,12 +20,13 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiSpacer } from '@elastic/eui'; -import { ShardFailureOpenModalButton, ShardFailureRequest, ShardFailureResponse } from '../../ui'; +import { SearchResponse } from 'elasticsearch'; +import { ShardFailureOpenModalButton } from '../../ui'; import { toMountPoint } from '../../../../kibana_react/public'; import { getNotifications } from '../../services'; -import { SearchRequest, SearchResponse } from '..'; +import { SearchRequest } from '..'; -export function handleResponse(request: SearchRequest, response: SearchResponse) { +export function handleResponse(request: SearchRequest, response: SearchResponse) { if (response.timed_out) { getNotifications().toasts.addWarning({ title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', { @@ -53,11 +54,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse) <> {description} - + ); diff --git a/src/plugins/data/public/search/fetch/request_error.ts b/src/plugins/data/public/search/fetch/request_error.ts index 5e42a6fcf5b6..efaaafadf404 100644 --- a/src/plugins/data/public/search/fetch/request_error.ts +++ b/src/plugins/data/public/search/fetch/request_error.ts @@ -17,8 +17,9 @@ * under the License. */ +import { SearchResponse } from 'elasticsearch'; import { KbnError } from '../../../../kibana_utils/common'; -import { SearchError, SearchResponse } from './types'; +import { SearchError } from './types'; /** * Request Failure - When an entire multi request fails @@ -26,8 +27,8 @@ import { SearchError, SearchResponse } from './types'; * @param {Object} resp - optional HTTP response */ export class RequestFailure extends KbnError { - public resp: SearchResponse; - constructor(err: SearchError | null = null, resp?: SearchResponse) { + public resp?: SearchResponse; + constructor(err: SearchError | null = null, resp?: SearchResponse) { super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err?.message)}`); this.resp = resp; diff --git a/src/plugins/data/public/search/fetch/types.ts b/src/plugins/data/public/search/fetch/types.ts index 18d277204815..670c4f731971 100644 --- a/src/plugins/data/public/search/fetch/types.ts +++ b/src/plugins/data/public/search/fetch/types.ts @@ -20,8 +20,14 @@ import { GetConfigFn } from '../../../common'; import { ISearchStartLegacy } from '../types'; -export type SearchRequest = any; -export type SearchResponse = any; +/** + * @internal + * + * This type is used when flattenning a SearchSource and passing it down to legacy search. + * Once legacy search is removed, this type should become internal to `SearchSource`, + * where `ISearchRequestParams` is used externally instead. + */ +export type SearchRequest = Record; export interface FetchOptions { abortSignal?: AbortSignal; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index 32bcd8a27903..14eff13b378e 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -34,13 +34,7 @@ export { getEsPreference } from './es_search'; export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search'; -export { - SearchError, - FetchOptions, - SearchRequest, - SearchResponse, - getSearchParamsFromRequest, -} from './fetch'; +export { SearchError, FetchOptions, getSearchParamsFromRequest, SearchRequest } from './fetch'; export { ISearchSource, diff --git a/src/plugins/data/public/search/legacy/call_client.ts b/src/plugins/data/public/search/legacy/call_client.ts index 4b12f517daf7..3dcf11f72a74 100644 --- a/src/plugins/data/public/search/legacy/call_client.ts +++ b/src/plugins/data/public/search/legacy/call_client.ts @@ -17,6 +17,7 @@ * under the License. */ +import { SearchResponse } from 'elasticsearch'; import { FetchOptions, FetchHandlers, handleResponse } from '../fetch'; import { defaultSearchStrategy } from './default_search_strategy'; import { SearchRequest } from '../index'; @@ -32,7 +33,7 @@ export function callClient( FetchOptions ]> = searchRequests.map((request, i) => [request, requestsOptions[i]]); const requestOptionsMap = new Map(requestOptionEntries); - const requestResponseMap = new Map(); + const requestResponseMap = new Map>>(); const { searching, abort } = defaultSearchStrategy.search({ searchRequests, @@ -45,5 +46,5 @@ export function callClient( if (abortSignal) abortSignal.addEventListener('abort', abort); requestResponseMap.set(request, response); }); - return searchRequests.map((request) => requestResponseMap.get(request)); + return searchRequests.map((request) => requestResponseMap.get(request)!); } diff --git a/src/plugins/data/public/search/legacy/es_client/types.ts b/src/plugins/data/public/search/legacy/es_client/types.ts index 7a56b9b0cb00..2d35188322a4 100644 --- a/src/plugins/data/public/search/legacy/es_client/types.ts +++ b/src/plugins/data/public/search/legacy/es_client/types.ts @@ -17,13 +17,14 @@ * under the License. */ -import { SearchRequest, SearchResponse } from '../../fetch'; +import { SearchResponse } from 'elasticsearch'; +import { SearchRequest } from '../../fetch'; export interface LegacyApiCaller { search: (searchRequest: SearchRequest) => LegacyApiCallerResponse; msearch: (searchRequest: SearchRequest) => LegacyApiCallerResponse; } -interface LegacyApiCallerResponse extends Promise { +interface LegacyApiCallerResponse extends Promise> { abort: () => void; } diff --git a/src/plugins/data/public/search/legacy/fetch_soon.test.ts b/src/plugins/data/public/search/legacy/fetch_soon.test.ts index d375398af1ad..d7a85e65b475 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.test.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.test.ts @@ -20,17 +20,27 @@ import { fetchSoon } from './fetch_soon'; import { callClient } from './call_client'; import { FetchHandlers, FetchOptions } from '../fetch/types'; -import { SearchRequest, SearchResponse } from '../index'; +import { SearchRequest } from '../index'; +import { SearchResponse } from 'elasticsearch'; import { GetConfigFn, UI_SETTINGS } from '../../../common'; function getConfigStub(config: any = {}): GetConfigFn { return (key) => config[key]; } -const mockResponses: Record = { - foo: {}, - bar: {}, - baz: {}, +const mockResponses: Record> = { + foo: { + took: 1, + timed_out: false, + } as SearchResponse, + bar: { + took: 2, + timed_out: false, + } as SearchResponse, + baz: { + took: 3, + timed_out: false, + } as SearchResponse, }; jest.useFakeTimers(); diff --git a/src/plugins/data/public/search/legacy/fetch_soon.ts b/src/plugins/data/public/search/legacy/fetch_soon.ts index 252682c7c8e5..16920a8a4dd9 100644 --- a/src/plugins/data/public/search/legacy/fetch_soon.ts +++ b/src/plugins/data/public/search/legacy/fetch_soon.ts @@ -17,9 +17,10 @@ * under the License. */ +import { SearchResponse } from 'elasticsearch'; import { callClient } from './call_client'; import { FetchHandlers, FetchOptions } from '../fetch/types'; -import { SearchRequest, SearchResponse } from '../index'; +import { SearchRequest } from '../index'; import { UI_SETTINGS } from '../../../common'; /** @@ -53,7 +54,7 @@ let requestsToFetch: SearchRequest[] = []; let requestOptions: FetchOptions[] = []; // The in-progress fetch (if there is one) -let fetchInProgress: Promise | null = null; +let fetchInProgress: any = null; /** * Delay fetching for a given amount of time, while batching up the requests to be fetched. @@ -67,7 +68,7 @@ async function delayedFetch( options: FetchOptions, fetchHandlers: FetchHandlers, ms: number -) { +): Promise> { if (ms === 0) { return callClient([request], [options], fetchHandlers)[0]; } @@ -75,7 +76,10 @@ async function delayedFetch( const i = requestsToFetch.length; requestsToFetch = [...requestsToFetch, request]; requestOptions = [...requestOptions, options]; - const responses: SearchResponse[] = await (fetchInProgress = + + // Note: the typescript here only worked because `SearchResponse` was `any` + // Since this code is legacy, I'm leaving the any here. + const responses: any[] = await (fetchInProgress = fetchInProgress || delay(() => { const response = callClient(requestsToFetch, requestOptions, fetchHandlers); diff --git a/src/plugins/data/public/search/legacy/types.ts b/src/plugins/data/public/search/legacy/types.ts index 3812cec7a2aa..ed17db464fef 100644 --- a/src/plugins/data/public/search/legacy/types.ts +++ b/src/plugins/data/public/search/legacy/types.ts @@ -17,8 +17,9 @@ * under the License. */ +import { SearchResponse } from 'elasticsearch'; import { FetchHandlers } from '../fetch'; -import { SearchRequest, SearchResponse } from '..'; +import { SearchRequest } from '..'; export interface SearchStrategySearchParams extends FetchHandlers { searchRequests: SearchRequest[]; @@ -30,7 +31,7 @@ export interface SearchStrategyProvider { search: (params: SearchStrategySearchParams) => SearchStrategyResponse; } -export interface SearchStrategyResponse { - searching: Promise; +export interface SearchStrategyResponse { + searching: Promise>>; abort: () => void; } diff --git a/src/plugins/data/public/search/search_source/search_source.ts b/src/plugins/data/public/search/search_source/search_source.ts index 06ad13bfcfdf..d2e337076205 100644 --- a/src/plugins/data/public/search/search_source/search_source.ts +++ b/src/plugins/data/public/search/search_source/search_source.ts @@ -75,9 +75,15 @@ import { map } from 'rxjs/operators'; import { normalizeSortRequest } from './normalize_sort_request'; import { filterDocvalueFields } from './filter_docvalue_fields'; import { fieldWildcardFilter } from '../../../../kibana_utils/common'; -import { IIndexPattern, ISearchGeneric, SearchRequest } from '../..'; +import { IIndexPattern, ISearchGeneric } from '../..'; import { SearchSourceOptions, SearchSourceFields } from './types'; -import { FetchOptions, RequestFailure, handleResponse, getSearchParamsFromRequest } from '../fetch'; +import { + FetchOptions, + RequestFailure, + handleResponse, + getSearchParamsFromRequest, + SearchRequest, +} from '../fetch'; import { getEsQueryConfig, buildEsQuery, Filter, UI_SETTINGS } from '../../../common'; import { getHighlightRequest } from '../../../common/field_formats'; @@ -268,10 +274,11 @@ export class SearchSource { if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) { response = await this.legacyFetch(searchRequest, options); } else { - response = this.fetch$(searchRequest, options.abortSignal).toPromise(); + response = await this.fetch$(searchRequest, options.abortSignal).toPromise(); } - if (response.error) { + // TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved + if ((response as any).error) { throw new RequestFailure(null, response); } @@ -403,7 +410,7 @@ export class SearchSource { return searchRequest; } - private getIndexType(index: IIndexPattern) { + private getIndexType(index?: IIndexPattern) { if (this.searchStrategyId) { return this.searchStrategyId === 'default' ? undefined : this.searchStrategyId; } else { diff --git a/src/plugins/data/public/ui/index.ts b/src/plugins/data/public/ui/index.ts index cb46a838a8c3..35b1bc50ddb1 100644 --- a/src/plugins/data/public/ui/index.ts +++ b/src/plugins/data/public/ui/index.ts @@ -24,11 +24,7 @@ export { QueryStringInput } from './query_string_input/query_string_input'; export { SearchBar, SearchBarProps, StatefulSearchBarProps } from './search_bar'; // @internal -export { - ShardFailureOpenModalButton, - ShardFailureRequest, - ShardFailureResponse, -} from './shard_failure_modal'; +export { ShardFailureOpenModalButton, ShardFailureRequest } from './shard_failure_modal'; // @internal export { SavedQueryManagementComponent } from './saved_query_management'; diff --git a/src/plugins/data/public/ui/shard_failure_modal/__mocks__/shard_failure_response.ts b/src/plugins/data/public/ui/shard_failure_modal/__mocks__/shard_failure_response.ts index 573aeefcdf46..6178fcf92a79 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/__mocks__/shard_failure_response.ts +++ b/src/plugins/data/public/ui/shard_failure_modal/__mocks__/shard_failure_response.ts @@ -16,9 +16,10 @@ * specific language governing permissions and limitations * under the License. */ -import { ShardFailureResponse } from '../shard_failure_types'; -export const shardFailureResponse = { +import { SearchResponse } from 'elasticsearch'; + +export const shardFailureResponse: SearchResponse = { _shards: { total: 2, successful: 1, @@ -43,4 +44,4 @@ export const shardFailureResponse = { }, ], }, -} as ShardFailureResponse; +} as any; diff --git a/src/plugins/data/public/ui/shard_failure_modal/index.ts b/src/plugins/data/public/ui/shard_failure_modal/index.ts index f4c2e26a756e..e5af9633e73b 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/index.ts +++ b/src/plugins/data/public/ui/shard_failure_modal/index.ts @@ -17,5 +17,5 @@ * under the License. */ -export { ShardFailureRequest, ShardFailureResponse } from './shard_failure_types'; +export { ShardFailureRequest } from './shard_failure_types'; export { ShardFailureOpenModalButton } from './shard_failure_open_modal_button'; diff --git a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_description.test.tsx b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_description.test.tsx index 49983c992638..d40770fb74ef 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_description.test.tsx +++ b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_description.test.tsx @@ -24,7 +24,8 @@ import { ShardFailure } from './shard_failure_types'; describe('ShardFailureDescription', () => { it('renders matching snapshot given valid properties', () => { - const failure = shardFailureResponse._shards.failures[0] as ShardFailure; + // TODO: remove cast once https://github.com/elastic/elasticsearch-js/issues/1286 is resolved + const failure = (shardFailureResponse._shards as any).failures[0] as ShardFailure; const component = shallowWithIntl(); expect(component).toMatchSnapshot(); }); diff --git a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_modal.tsx b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_modal.tsx index 535f63161966..52f3cf702c2f 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_modal.tsx +++ b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_modal.tsx @@ -32,18 +32,24 @@ import { EuiButtonEmpty, EuiCallOut, } from '@elastic/eui'; +import { SearchResponse } from 'elasticsearch'; import { ShardFailureTable } from './shard_failure_table'; -import { ShardFailureResponse, ShardFailureRequest } from './shard_failure_types'; +import { ShardFailureRequest } from './shard_failure_types'; export interface Props { onClose: () => void; request: ShardFailureRequest; - response: ShardFailureResponse; + response: SearchResponse; title: string; } export function ShardFailureModal({ request, response, title, onClose }: Props) { - if (!response || !response._shards || !Array.isArray(response._shards.failures) || !request) { + if ( + !response || + !response._shards || + !Array.isArray((response._shards as any).failures) || + !request + ) { // this should never ever happen, but just in case return ( @@ -51,10 +57,9 @@ export function ShardFailureModal({ request, response, title, onClose }: Props) ); } - + const failures = (response._shards as any).failures; const requestJSON = JSON.stringify(request, null, 2); const responseJSON = JSON.stringify(response, null, 2); - const failures = response._shards.failures; const tabs = [ { diff --git a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_open_modal_button.tsx b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_open_modal_button.tsx index fa42745da2e4..9d89dc4cb1a2 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_open_modal_button.tsx +++ b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_open_modal_button.tsx @@ -20,14 +20,15 @@ import React from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButton, EuiTextAlign } from '@elastic/eui'; +import { SearchResponse } from 'elasticsearch'; import { getOverlays } from '../../services'; import { toMountPoint } from '../../../../kibana_react/public'; import { ShardFailureModal } from './shard_failure_modal'; -import { ShardFailureResponse, ShardFailureRequest } from './shard_failure_types'; +import { ShardFailureRequest } from './shard_failure_types'; interface Props { request: ShardFailureRequest; - response: ShardFailureResponse; + response: SearchResponse; title: string; } diff --git a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_table.test.tsx b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_table.test.tsx index 9d00233d37f8..22478ebd5739 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_table.test.tsx +++ b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_table.test.tsx @@ -24,7 +24,7 @@ import { ShardFailure } from './shard_failure_types'; describe('ShardFailureTable', () => { it('renders matching snapshot given valid properties', () => { - const failures = shardFailureResponse._shards.failures as ShardFailure[]; + const failures = (shardFailureResponse._shards as any).failures as ShardFailure[]; const component = shallowWithIntl(); expect(component).toMatchSnapshot(); }); diff --git a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_types.ts b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_types.ts index b1ce3f30c427..a7a56d2de962 100644 --- a/src/plugins/data/public/ui/shard_failure_modal/shard_failure_types.ts +++ b/src/plugins/data/public/ui/shard_failure_modal/shard_failure_types.ts @@ -25,16 +25,6 @@ export interface ShardFailureRequest { stored_fields: string[]; } -export interface ShardFailureResponse { - _shards: { - failed: number; - failures: ShardFailure[]; - skipped: number; - successful: number; - total: number; - }; -} - export interface ShardFailure { index: string; node: string; diff --git a/src/plugins/discover/public/application/angular/context/api/utils/fetch_hits_in_interval.ts b/src/plugins/discover/public/application/angular/context/api/utils/fetch_hits_in_interval.ts index 437898201863..9a199ea4a62f 100644 --- a/src/plugins/discover/public/application/angular/context/api/utils/fetch_hits_in_interval.ts +++ b/src/plugins/discover/public/application/angular/context/api/utils/fetch_hits_in_interval.ts @@ -18,7 +18,7 @@ */ import { ISearchSource, EsQuerySortValue, SortDirection } from '../../../../../../../data/public'; import { convertTimeValueToIso } from './date_conversion'; -import { EsHitRecordList } from '../context'; +import { EsHitRecordList, EsHitRecord } from '../context'; import { IntervalValue } from './generate_intervals'; import { EsQuerySearchAfter } from './get_es_query_search_after'; @@ -76,5 +76,6 @@ export async function fetchHitsInInterval( .setField('version', true) .fetch(); - return response.hits ? response.hits.hits : []; + // TODO: There's a difference in the definition of SearchResponse and EsHitRecord + return ((response.hits?.hits as unknown) as EsHitRecord[]) || []; } diff --git a/src/plugins/input_control_vis/public/control/list_control_factory.ts b/src/plugins/input_control_vis/public/control/list_control_factory.ts index acbbf08c7d00..325eb471d510 100644 --- a/src/plugins/input_control_vis/public/control/list_control_factory.ts +++ b/src/plugins/input_control_vis/public/control/list_control_factory.ts @@ -190,7 +190,9 @@ export class ListControl extends Control { return; } - this.partialResults = resp.terminated_early || resp.timed_out; + // TODO: terminated_early is missing from response definition. + // https://github.com/elastic/elasticsearch-js/issues/1289 + this.partialResults = (resp as any).terminated_early || resp.timed_out; this.selectOptions = selectOptions; this.enable = true; this.disabledReason = ''; diff --git a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts index 02d5a415eec2..9ca6db40a305 100644 --- a/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts +++ b/x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts @@ -5,7 +5,7 @@ */ import { encode } from 'rison-node'; -import { SearchResponse } from 'src/plugins/data/public'; +import { SearchResponse } from 'elasticsearch'; import { FetchData, FetchDataParams, @@ -87,7 +87,7 @@ async function fetchLogsOverview( dataPlugin: InfraClientStartDeps['data'] ): Promise { return new Promise((resolve, reject) => { - let esResponse: SearchResponse = {}; + let esResponse: SearchResponse | undefined; dataPlugin.search .search({ @@ -104,8 +104,8 @@ async function fetchLogsOverview( (response) => (esResponse = response.rawResponse), (error) => reject(error), () => { - if (esResponse.aggregations) { - resolve(processLogsOverviewAggregations(esResponse.aggregations)); + if (esResponse?.aggregations) { + resolve(processLogsOverviewAggregations(esResponse!.aggregations)); } else { resolve({ stats: {}, series: {} }); }