[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) | |
|
| [RangeFilterMeta](./kibana-plugin-plugins-data-public.rangefiltermeta.md) | |
|
||||||
| [SavedQueryTimeFilter](./kibana-plugin-plugins-data-public.savedquerytimefilter.md) | |
|
| [SavedQueryTimeFilter](./kibana-plugin-plugins-data-public.savedquerytimefilter.md) | |
|
||||||
| [SearchBarProps](./kibana-plugin-plugins-data-public.searchbarprops.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) | |
|
| [StatefulSearchBarProps](./kibana-plugin-plugins-data-public.statefulsearchbarprops.md) | |
|
||||||
| [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* |
|
| [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* |
|
||||||
| [TimefilterContract](./kibana-plugin-plugins-data-public.timefiltercontract.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 const ES_SEARCH_STRATEGY = 'es';
|
||||||
|
|
||||||
export type ISearchRequestParams = {
|
export type ISearchRequestParams<T = Record<string, any>> = {
|
||||||
trackTotalHits?: boolean;
|
trackTotalHits?: boolean;
|
||||||
} & Search;
|
} & Search<T>;
|
||||||
|
|
||||||
export interface IEsSearchRequest extends IKibanaSearchRequest {
|
export interface IEsSearchRequest extends IKibanaSearchRequest {
|
||||||
params?: ISearchRequestParams;
|
params?: ISearchRequestParams;
|
||||||
|
|
|
@ -360,7 +360,6 @@ export {
|
||||||
SearchInterceptor,
|
SearchInterceptor,
|
||||||
SearchInterceptorDeps,
|
SearchInterceptorDeps,
|
||||||
SearchRequest,
|
SearchRequest,
|
||||||
SearchResponse,
|
|
||||||
SearchSourceFields,
|
SearchSourceFields,
|
||||||
SortDirection,
|
SortDirection,
|
||||||
// expression functions and types
|
// expression functions and types
|
||||||
|
|
|
@ -61,7 +61,7 @@ import { SavedObject } from 'src/core/server';
|
||||||
import { SavedObject as SavedObject_3 } from 'src/core/public';
|
import { SavedObject as SavedObject_3 } from 'src/core/public';
|
||||||
import { SavedObjectsClientContract } from 'src/core/public';
|
import { SavedObjectsClientContract } from 'src/core/public';
|
||||||
import { Search } from '@elastic/elasticsearch/api/requestParams';
|
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 { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/common';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { Toast } from 'kibana/public';
|
import { Toast } from 'kibana/public';
|
||||||
|
@ -727,6 +727,7 @@ export function getEsPreference(uiSettings: IUiSettingsClient_2, sessionId?: str
|
||||||
export const getKbnTypeNames: () => string[];
|
export const getKbnTypeNames: () => string[];
|
||||||
|
|
||||||
// Warning: (ae-forgotten-export) The symbol "ISearchRequestParams" needs to be exported by the entry point index.d.ts
|
// 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)
|
// @public (undocumented)
|
||||||
export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
|
export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
|
||||||
|
@ -795,7 +796,7 @@ export interface IEsSearchResponse<Source = any> extends IKibanaSearchResponse {
|
||||||
isPartial?: boolean;
|
isPartial?: boolean;
|
||||||
isRunning?: boolean;
|
isRunning?: boolean;
|
||||||
// (undocumented)
|
// (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)
|
// 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;
|
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)
|
// @internal
|
||||||
//
|
export type SearchRequest = Record<string, any>;
|
||||||
// @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;
|
|
||||||
|
|
||||||
// Warning: (ae-missing-release-tag) "SearchSourceFields" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
// 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 "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 "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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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: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/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: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
|
// 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
|
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||||
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
|
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
|
||||||
import { setNotifications } from '../../services';
|
import { setNotifications } from '../../services';
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
|
|
||||||
jest.mock('@kbn/i18n', () => {
|
jest.mock('@kbn/i18n', () => {
|
||||||
return {
|
return {
|
||||||
|
@ -44,7 +45,7 @@ describe('handleResponse', () => {
|
||||||
const request = { body: {} };
|
const request = { body: {} };
|
||||||
const response = {
|
const response = {
|
||||||
timed_out: true,
|
timed_out: true,
|
||||||
};
|
} as SearchResponse<any>;
|
||||||
const result = handleResponse(request, response);
|
const result = handleResponse(request, response);
|
||||||
expect(result).toBe(response);
|
expect(result).toBe(response);
|
||||||
expect(notifications.toasts.addWarning).toBeCalled();
|
expect(notifications.toasts.addWarning).toBeCalled();
|
||||||
|
@ -57,9 +58,12 @@ describe('handleResponse', () => {
|
||||||
const request = { body: {} };
|
const request = { body: {} };
|
||||||
const response = {
|
const response = {
|
||||||
_shards: {
|
_shards: {
|
||||||
failed: true,
|
failed: 1,
|
||||||
|
total: 2,
|
||||||
|
successful: 1,
|
||||||
|
skipped: 1,
|
||||||
},
|
},
|
||||||
};
|
} as SearchResponse<any>;
|
||||||
const result = handleResponse(request, response);
|
const result = handleResponse(request, response);
|
||||||
expect(result).toBe(response);
|
expect(result).toBe(response);
|
||||||
expect(notifications.toasts.addWarning).toBeCalled();
|
expect(notifications.toasts.addWarning).toBeCalled();
|
||||||
|
@ -70,7 +74,7 @@ describe('handleResponse', () => {
|
||||||
|
|
||||||
test('returns the response', () => {
|
test('returns the response', () => {
|
||||||
const request = {};
|
const request = {};
|
||||||
const response = {};
|
const response = {} as SearchResponse<any>;
|
||||||
const result = handleResponse(request, response);
|
const result = handleResponse(request, response);
|
||||||
expect(result).toBe(response);
|
expect(result).toBe(response);
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,12 +20,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { i18n } from '@kbn/i18n';
|
import { i18n } from '@kbn/i18n';
|
||||||
import { EuiSpacer } from '@elastic/eui';
|
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 { toMountPoint } from '../../../../kibana_react/public';
|
||||||
import { getNotifications } from '../../services';
|
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) {
|
if (response.timed_out) {
|
||||||
getNotifications().toasts.addWarning({
|
getNotifications().toasts.addWarning({
|
||||||
title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', {
|
title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', {
|
||||||
|
@ -53,11 +54,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse)
|
||||||
<>
|
<>
|
||||||
{description}
|
{description}
|
||||||
<EuiSpacer size="s" />
|
<EuiSpacer size="s" />
|
||||||
<ShardFailureOpenModalButton
|
<ShardFailureOpenModalButton request={request.body} response={response} title={title} />
|
||||||
request={request.body as ShardFailureRequest}
|
|
||||||
response={response as ShardFailureResponse}
|
|
||||||
title={title}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { KbnError } from '../../../../kibana_utils/common';
|
import { KbnError } from '../../../../kibana_utils/common';
|
||||||
import { SearchError, SearchResponse } from './types';
|
import { SearchError } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request Failure - When an entire multi request fails
|
* Request Failure - When an entire multi request fails
|
||||||
|
@ -26,8 +27,8 @@ import { SearchError, SearchResponse } from './types';
|
||||||
* @param {Object} resp - optional HTTP response
|
* @param {Object} resp - optional HTTP response
|
||||||
*/
|
*/
|
||||||
export class RequestFailure extends KbnError {
|
export class RequestFailure extends KbnError {
|
||||||
public resp: SearchResponse;
|
public resp?: SearchResponse<any>;
|
||||||
constructor(err: SearchError | null = null, resp?: SearchResponse) {
|
constructor(err: SearchError | null = null, resp?: SearchResponse<any>) {
|
||||||
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err?.message)}`);
|
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err?.message)}`);
|
||||||
|
|
||||||
this.resp = resp;
|
this.resp = resp;
|
||||||
|
|
|
@ -20,8 +20,14 @@
|
||||||
import { GetConfigFn } from '../../../common';
|
import { GetConfigFn } from '../../../common';
|
||||||
import { ISearchStartLegacy } from '../types';
|
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 {
|
export interface FetchOptions {
|
||||||
abortSignal?: AbortSignal;
|
abortSignal?: AbortSignal;
|
||||||
|
|
|
@ -34,13 +34,7 @@ export { getEsPreference } from './es_search';
|
||||||
|
|
||||||
export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search';
|
export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search';
|
||||||
|
|
||||||
export {
|
export { SearchError, FetchOptions, getSearchParamsFromRequest, SearchRequest } from './fetch';
|
||||||
SearchError,
|
|
||||||
FetchOptions,
|
|
||||||
SearchRequest,
|
|
||||||
SearchResponse,
|
|
||||||
getSearchParamsFromRequest,
|
|
||||||
} from './fetch';
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ISearchSource,
|
ISearchSource,
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { FetchOptions, FetchHandlers, handleResponse } from '../fetch';
|
import { FetchOptions, FetchHandlers, handleResponse } from '../fetch';
|
||||||
import { defaultSearchStrategy } from './default_search_strategy';
|
import { defaultSearchStrategy } from './default_search_strategy';
|
||||||
import { SearchRequest } from '../index';
|
import { SearchRequest } from '../index';
|
||||||
|
@ -32,7 +33,7 @@ export function callClient(
|
||||||
FetchOptions
|
FetchOptions
|
||||||
]> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
|
]> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
|
||||||
const requestOptionsMap = new Map<SearchRequest, FetchOptions>(requestOptionEntries);
|
const requestOptionsMap = new Map<SearchRequest, FetchOptions>(requestOptionEntries);
|
||||||
const requestResponseMap = new Map();
|
const requestResponseMap = new Map<SearchRequest, Promise<SearchResponse<any>>>();
|
||||||
|
|
||||||
const { searching, abort } = defaultSearchStrategy.search({
|
const { searching, abort } = defaultSearchStrategy.search({
|
||||||
searchRequests,
|
searchRequests,
|
||||||
|
@ -45,5 +46,5 @@ export function callClient(
|
||||||
if (abortSignal) abortSignal.addEventListener('abort', abort);
|
if (abortSignal) abortSignal.addEventListener('abort', abort);
|
||||||
requestResponseMap.set(request, response);
|
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.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { SearchRequest, SearchResponse } from '../../fetch';
|
import { SearchResponse } from 'elasticsearch';
|
||||||
|
import { SearchRequest } from '../../fetch';
|
||||||
|
|
||||||
export interface LegacyApiCaller {
|
export interface LegacyApiCaller {
|
||||||
search: (searchRequest: SearchRequest) => LegacyApiCallerResponse;
|
search: (searchRequest: SearchRequest) => LegacyApiCallerResponse;
|
||||||
msearch: (searchRequest: SearchRequest) => LegacyApiCallerResponse;
|
msearch: (searchRequest: SearchRequest) => LegacyApiCallerResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LegacyApiCallerResponse extends Promise<SearchResponse> {
|
interface LegacyApiCallerResponse extends Promise<SearchResponse<any>> {
|
||||||
abort: () => void;
|
abort: () => void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,17 +20,27 @@
|
||||||
import { fetchSoon } from './fetch_soon';
|
import { fetchSoon } from './fetch_soon';
|
||||||
import { callClient } from './call_client';
|
import { callClient } from './call_client';
|
||||||
import { FetchHandlers, FetchOptions } from '../fetch/types';
|
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';
|
import { GetConfigFn, UI_SETTINGS } from '../../../common';
|
||||||
|
|
||||||
function getConfigStub(config: any = {}): GetConfigFn {
|
function getConfigStub(config: any = {}): GetConfigFn {
|
||||||
return (key) => config[key];
|
return (key) => config[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockResponses: Record<string, SearchResponse> = {
|
const mockResponses: Record<string, SearchResponse<any>> = {
|
||||||
foo: {},
|
foo: {
|
||||||
bar: {},
|
took: 1,
|
||||||
baz: {},
|
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();
|
jest.useFakeTimers();
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { callClient } from './call_client';
|
import { callClient } from './call_client';
|
||||||
import { FetchHandlers, FetchOptions } from '../fetch/types';
|
import { FetchHandlers, FetchOptions } from '../fetch/types';
|
||||||
import { SearchRequest, SearchResponse } from '../index';
|
import { SearchRequest } from '../index';
|
||||||
import { UI_SETTINGS } from '../../../common';
|
import { UI_SETTINGS } from '../../../common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +54,7 @@ let requestsToFetch: SearchRequest[] = [];
|
||||||
let requestOptions: FetchOptions[] = [];
|
let requestOptions: FetchOptions[] = [];
|
||||||
|
|
||||||
// The in-progress fetch (if there is one)
|
// 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.
|
* 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,
|
options: FetchOptions,
|
||||||
fetchHandlers: FetchHandlers,
|
fetchHandlers: FetchHandlers,
|
||||||
ms: number
|
ms: number
|
||||||
) {
|
): Promise<SearchResponse<any>> {
|
||||||
if (ms === 0) {
|
if (ms === 0) {
|
||||||
return callClient([request], [options], fetchHandlers)[0];
|
return callClient([request], [options], fetchHandlers)[0];
|
||||||
}
|
}
|
||||||
|
@ -75,7 +76,10 @@ async function delayedFetch(
|
||||||
const i = requestsToFetch.length;
|
const i = requestsToFetch.length;
|
||||||
requestsToFetch = [...requestsToFetch, request];
|
requestsToFetch = [...requestsToFetch, request];
|
||||||
requestOptions = [...requestOptions, options];
|
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 ||
|
fetchInProgress ||
|
||||||
delay(() => {
|
delay(() => {
|
||||||
const response = callClient(requestsToFetch, requestOptions, fetchHandlers);
|
const response = callClient(requestsToFetch, requestOptions, fetchHandlers);
|
||||||
|
|
|
@ -17,8 +17,9 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { FetchHandlers } from '../fetch';
|
import { FetchHandlers } from '../fetch';
|
||||||
import { SearchRequest, SearchResponse } from '..';
|
import { SearchRequest } from '..';
|
||||||
|
|
||||||
export interface SearchStrategySearchParams extends FetchHandlers {
|
export interface SearchStrategySearchParams extends FetchHandlers {
|
||||||
searchRequests: SearchRequest[];
|
searchRequests: SearchRequest[];
|
||||||
|
@ -30,7 +31,7 @@ export interface SearchStrategyProvider {
|
||||||
search: (params: SearchStrategySearchParams) => SearchStrategyResponse;
|
search: (params: SearchStrategySearchParams) => SearchStrategyResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SearchStrategyResponse {
|
export interface SearchStrategyResponse<T = any> {
|
||||||
searching: Promise<SearchResponse[]>;
|
searching: Promise<Array<SearchResponse<T>>>;
|
||||||
abort: () => void;
|
abort: () => void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,15 @@ import { map } from 'rxjs/operators';
|
||||||
import { normalizeSortRequest } from './normalize_sort_request';
|
import { normalizeSortRequest } from './normalize_sort_request';
|
||||||
import { filterDocvalueFields } from './filter_docvalue_fields';
|
import { filterDocvalueFields } from './filter_docvalue_fields';
|
||||||
import { fieldWildcardFilter } from '../../../../kibana_utils/common';
|
import { fieldWildcardFilter } from '../../../../kibana_utils/common';
|
||||||
import { IIndexPattern, ISearchGeneric, SearchRequest } from '../..';
|
import { IIndexPattern, ISearchGeneric } from '../..';
|
||||||
import { SearchSourceOptions, SearchSourceFields } from './types';
|
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 { getEsQueryConfig, buildEsQuery, Filter, UI_SETTINGS } from '../../../common';
|
||||||
import { getHighlightRequest } from '../../../common/field_formats';
|
import { getHighlightRequest } from '../../../common/field_formats';
|
||||||
|
@ -268,10 +274,11 @@ export class SearchSource {
|
||||||
if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) {
|
if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) {
|
||||||
response = await this.legacyFetch(searchRequest, options);
|
response = await this.legacyFetch(searchRequest, options);
|
||||||
} else {
|
} 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);
|
throw new RequestFailure(null, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +410,7 @@ export class SearchSource {
|
||||||
return searchRequest;
|
return searchRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getIndexType(index: IIndexPattern) {
|
private getIndexType(index?: IIndexPattern) {
|
||||||
if (this.searchStrategyId) {
|
if (this.searchStrategyId) {
|
||||||
return this.searchStrategyId === 'default' ? undefined : this.searchStrategyId;
|
return this.searchStrategyId === 'default' ? undefined : this.searchStrategyId;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -24,11 +24,7 @@ export { QueryStringInput } from './query_string_input/query_string_input';
|
||||||
export { SearchBar, SearchBarProps, StatefulSearchBarProps } from './search_bar';
|
export { SearchBar, SearchBarProps, StatefulSearchBarProps } from './search_bar';
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export {
|
export { ShardFailureOpenModalButton, ShardFailureRequest } from './shard_failure_modal';
|
||||||
ShardFailureOpenModalButton,
|
|
||||||
ShardFailureRequest,
|
|
||||||
ShardFailureResponse,
|
|
||||||
} from './shard_failure_modal';
|
|
||||||
|
|
||||||
// @internal
|
// @internal
|
||||||
export { SavedQueryManagementComponent } from './saved_query_management';
|
export { SavedQueryManagementComponent } from './saved_query_management';
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { ShardFailureResponse } from '../shard_failure_types';
|
|
||||||
|
|
||||||
export const shardFailureResponse = {
|
import { SearchResponse } from 'elasticsearch';
|
||||||
|
|
||||||
|
export const shardFailureResponse: SearchResponse<any> = {
|
||||||
_shards: {
|
_shards: {
|
||||||
total: 2,
|
total: 2,
|
||||||
successful: 1,
|
successful: 1,
|
||||||
|
@ -43,4 +44,4 @@ export const shardFailureResponse = {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
} as ShardFailureResponse;
|
} as any;
|
||||||
|
|
|
@ -17,5 +17,5 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { ShardFailureRequest, ShardFailureResponse } from './shard_failure_types';
|
export { ShardFailureRequest } from './shard_failure_types';
|
||||||
export { ShardFailureOpenModalButton } from './shard_failure_open_modal_button';
|
export { ShardFailureOpenModalButton } from './shard_failure_open_modal_button';
|
||||||
|
|
|
@ -24,7 +24,8 @@ import { ShardFailure } from './shard_failure_types';
|
||||||
|
|
||||||
describe('ShardFailureDescription', () => {
|
describe('ShardFailureDescription', () => {
|
||||||
it('renders matching snapshot given valid properties', () => {
|
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} />);
|
const component = shallowWithIntl(<ShardFailureDescription {...failure} />);
|
||||||
expect(component).toMatchSnapshot();
|
expect(component).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,18 +32,24 @@ import {
|
||||||
EuiButtonEmpty,
|
EuiButtonEmpty,
|
||||||
EuiCallOut,
|
EuiCallOut,
|
||||||
} from '@elastic/eui';
|
} from '@elastic/eui';
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { ShardFailureTable } from './shard_failure_table';
|
import { ShardFailureTable } from './shard_failure_table';
|
||||||
import { ShardFailureResponse, ShardFailureRequest } from './shard_failure_types';
|
import { ShardFailureRequest } from './shard_failure_types';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
request: ShardFailureRequest;
|
request: ShardFailureRequest;
|
||||||
response: ShardFailureResponse;
|
response: SearchResponse<any>;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ShardFailureModal({ request, response, title, onClose }: Props) {
|
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
|
// this should never ever happen, but just in case
|
||||||
return (
|
return (
|
||||||
<EuiCallOut title="Sorry, there was an error" color="danger" iconType="alert">
|
<EuiCallOut title="Sorry, there was an error" color="danger" iconType="alert">
|
||||||
|
@ -51,10 +57,9 @@ export function ShardFailureModal({ request, response, title, onClose }: Props)
|
||||||
</EuiCallOut>
|
</EuiCallOut>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const failures = (response._shards as any).failures;
|
||||||
const requestJSON = JSON.stringify(request, null, 2);
|
const requestJSON = JSON.stringify(request, null, 2);
|
||||||
const responseJSON = JSON.stringify(response, null, 2);
|
const responseJSON = JSON.stringify(response, null, 2);
|
||||||
const failures = response._shards.failures;
|
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,14 +20,15 @@ import React from 'react';
|
||||||
import { FormattedMessage } from '@kbn/i18n/react';
|
import { FormattedMessage } from '@kbn/i18n/react';
|
||||||
import { EuiButton, EuiTextAlign } from '@elastic/eui';
|
import { EuiButton, EuiTextAlign } from '@elastic/eui';
|
||||||
|
|
||||||
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import { getOverlays } from '../../services';
|
import { getOverlays } from '../../services';
|
||||||
import { toMountPoint } from '../../../../kibana_react/public';
|
import { toMountPoint } from '../../../../kibana_react/public';
|
||||||
import { ShardFailureModal } from './shard_failure_modal';
|
import { ShardFailureModal } from './shard_failure_modal';
|
||||||
import { ShardFailureResponse, ShardFailureRequest } from './shard_failure_types';
|
import { ShardFailureRequest } from './shard_failure_types';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
request: ShardFailureRequest;
|
request: ShardFailureRequest;
|
||||||
response: ShardFailureResponse;
|
response: SearchResponse<any>;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { ShardFailure } from './shard_failure_types';
|
||||||
|
|
||||||
describe('ShardFailureTable', () => {
|
describe('ShardFailureTable', () => {
|
||||||
it('renders matching snapshot given valid properties', () => {
|
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} />);
|
const component = shallowWithIntl(<ShardFailureTable failures={failures} />);
|
||||||
expect(component).toMatchSnapshot();
|
expect(component).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,16 +25,6 @@ export interface ShardFailureRequest {
|
||||||
stored_fields: string[];
|
stored_fields: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ShardFailureResponse {
|
|
||||||
_shards: {
|
|
||||||
failed: number;
|
|
||||||
failures: ShardFailure[];
|
|
||||||
skipped: number;
|
|
||||||
successful: number;
|
|
||||||
total: number;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ShardFailure {
|
export interface ShardFailure {
|
||||||
index: string;
|
index: string;
|
||||||
node: string;
|
node: string;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
import { ISearchSource, EsQuerySortValue, SortDirection } from '../../../../../../../data/public';
|
import { ISearchSource, EsQuerySortValue, SortDirection } from '../../../../../../../data/public';
|
||||||
import { convertTimeValueToIso } from './date_conversion';
|
import { convertTimeValueToIso } from './date_conversion';
|
||||||
import { EsHitRecordList } from '../context';
|
import { EsHitRecordList, EsHitRecord } from '../context';
|
||||||
import { IntervalValue } from './generate_intervals';
|
import { IntervalValue } from './generate_intervals';
|
||||||
import { EsQuerySearchAfter } from './get_es_query_search_after';
|
import { EsQuerySearchAfter } from './get_es_query_search_after';
|
||||||
|
|
||||||
|
@ -76,5 +76,6 @@ export async function fetchHitsInInterval(
|
||||||
.setField('version', true)
|
.setField('version', true)
|
||||||
.fetch();
|
.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;
|
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.selectOptions = selectOptions;
|
||||||
this.enable = true;
|
this.enable = true;
|
||||||
this.disabledReason = '';
|
this.disabledReason = '';
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { encode } from 'rison-node';
|
import { encode } from 'rison-node';
|
||||||
import { SearchResponse } from 'src/plugins/data/public';
|
import { SearchResponse } from 'elasticsearch';
|
||||||
import {
|
import {
|
||||||
FetchData,
|
FetchData,
|
||||||
FetchDataParams,
|
FetchDataParams,
|
||||||
|
@ -87,7 +87,7 @@ async function fetchLogsOverview(
|
||||||
dataPlugin: InfraClientStartDeps['data']
|
dataPlugin: InfraClientStartDeps['data']
|
||||||
): Promise<StatsAndSeries> {
|
): Promise<StatsAndSeries> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let esResponse: SearchResponse = {};
|
let esResponse: SearchResponse<any> | undefined;
|
||||||
|
|
||||||
dataPlugin.search
|
dataPlugin.search
|
||||||
.search({
|
.search({
|
||||||
|
@ -104,8 +104,8 @@ async function fetchLogsOverview(
|
||||||
(response) => (esResponse = response.rawResponse),
|
(response) => (esResponse = response.rawResponse),
|
||||||
(error) => reject(error),
|
(error) => reject(error),
|
||||||
() => {
|
() => {
|
||||||
if (esResponse.aggregations) {
|
if (esResponse?.aggregations) {
|
||||||
resolve(processLogsOverviewAggregations(esResponse.aggregations));
|
resolve(processLogsOverviewAggregations(esResponse!.aggregations));
|
||||||
} else {
|
} else {
|
||||||
resolve({ stats: {}, series: {} });
|
resolve({ stats: {}, series: {} });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue