[Search] Cleanup SearchRequest and SearchResponse types (#75471)
* improve test stability
* Replace SearchRequest = any with Record<string, any>
* Remove SearchResponse = any from data plugin
* docs
* logs
* Revert "Replace SearchRequest = any with Record<string, any>"
This reverts commit 9914ab5a01
.
* code review
* list control
* null check
* null null null
* Jest fix
This commit is contained in:
parent
6dbc4be8f7
commit
bdb73b55ef
|
@ -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) | |
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchRequest](./kibana-plugin-plugins-data-public.searchrequest.md)
|
||||
|
||||
## SearchRequest type
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type SearchRequest = any;
|
||||
```
|
|
@ -1,11 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchResponse](./kibana-plugin-plugins-data-public.searchresponse.md)
|
||||
|
||||
## SearchResponse type
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type SearchResponse = any;
|
||||
```
|
|
@ -22,9 +22,9 @@ import { IKibanaSearchRequest, IKibanaSearchResponse } from '../types';
|
|||
|
||||
export const ES_SEARCH_STRATEGY = 'es';
|
||||
|
||||
export type ISearchRequestParams = {
|
||||
export type ISearchRequestParams<T = Record<string, any>> = {
|
||||
trackTotalHits?: boolean;
|
||||
} & Search;
|
||||
} & Search<T>;
|
||||
|
||||
export interface IEsSearchRequest extends IKibanaSearchRequest {
|
||||
params?: ISearchRequestParams;
|
||||
|
|
|
@ -360,7 +360,6 @@ export {
|
|||
SearchInterceptor,
|
||||
SearchInterceptorDeps,
|
||||
SearchRequest,
|
||||
SearchResponse,
|
||||
SearchSourceFields,
|
||||
SortDirection,
|
||||
// expression functions and types
|
||||
|
|
|
@ -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<Source = any> extends IKibanaSearchResponse {
|
|||
isPartial?: boolean;
|
||||
isRunning?: boolean;
|
||||
// (undocumented)
|
||||
rawResponse: SearchResponse_2<Source>;
|
||||
rawResponse: SearchResponse<Source>;
|
||||
}
|
||||
|
||||
// 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<string, any>;
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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<any>;
|
||||
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<any>;
|
||||
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<any>;
|
||||
const result = handleResponse(request, response);
|
||||
expect(result).toBe(response);
|
||||
});
|
||||
|
|
|
@ -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<any>) {
|
||||
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}
|
||||
<EuiSpacer size="s" />
|
||||
<ShardFailureOpenModalButton
|
||||
request={request.body as ShardFailureRequest}
|
||||
response={response as ShardFailureResponse}
|
||||
title={title}
|
||||
/>
|
||||
<ShardFailureOpenModalButton request={request.body} response={response} title={title} />
|
||||
</>
|
||||
);
|
||||
|
||||
|
|
|
@ -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<any>;
|
||||
constructor(err: SearchError | null = null, resp?: SearchResponse<any>) {
|
||||
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err?.message)}`);
|
||||
|
||||
this.resp = resp;
|
||||
|
|
|
@ -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<string, any>;
|
||||
|
||||
export interface FetchOptions {
|
||||
abortSignal?: AbortSignal;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<SearchRequest, FetchOptions>(requestOptionEntries);
|
||||
const requestResponseMap = new Map();
|
||||
const requestResponseMap = new Map<SearchRequest, Promise<SearchResponse<any>>>();
|
||||
|
||||
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)!);
|
||||
}
|
||||
|
|
|
@ -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<SearchResponse> {
|
||||
interface LegacyApiCallerResponse extends Promise<SearchResponse<any>> {
|
||||
abort: () => void;
|
||||
}
|
||||
|
|
|
@ -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<string, SearchResponse> = {
|
||||
foo: {},
|
||||
bar: {},
|
||||
baz: {},
|
||||
const mockResponses: Record<string, SearchResponse<any>> = {
|
||||
foo: {
|
||||
took: 1,
|
||||
timed_out: false,
|
||||
} as SearchResponse<any>,
|
||||
bar: {
|
||||
took: 2,
|
||||
timed_out: false,
|
||||
} as SearchResponse<any>,
|
||||
baz: {
|
||||
took: 3,
|
||||
timed_out: false,
|
||||
} as SearchResponse<any>,
|
||||
};
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
|
|
@ -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<SearchResponse> | 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<SearchResponse<any>> {
|
||||
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);
|
||||
|
|
|
@ -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<SearchResponse[]>;
|
||||
export interface SearchStrategyResponse<T = any> {
|
||||
searching: Promise<Array<SearchResponse<T>>>;
|
||||
abort: () => void;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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<any> = {
|
||||
_shards: {
|
||||
total: 2,
|
||||
successful: 1,
|
||||
|
@ -43,4 +44,4 @@ export const shardFailureResponse = {
|
|||
},
|
||||
],
|
||||
},
|
||||
} as ShardFailureResponse;
|
||||
} as any;
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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(<ShardFailureDescription {...failure} />);
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -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<any>;
|
||||
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 (
|
||||
<EuiCallOut title="Sorry, there was an error" color="danger" iconType="alert">
|
||||
|
@ -51,10 +57,9 @@ export function ShardFailureModal({ request, response, title, onClose }: Props)
|
|||
</EuiCallOut>
|
||||
);
|
||||
}
|
||||
|
||||
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 = [
|
||||
{
|
||||
|
|
|
@ -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<any>;
|
||||
title: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(<ShardFailureTable failures={failures} />);
|
||||
expect(component).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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[]) || [];
|
||||
}
|
||||
|
|
|
@ -190,7 +190,9 @@ export class ListControl extends Control<PhraseFilterManager> {
|
|||
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 = '';
|
||||
|
|
|
@ -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<StatsAndSeries> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let esResponse: SearchResponse = {};
|
||||
let esResponse: SearchResponse<any> | 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: {} });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue