Skip to content

Commit bdb73b5

Browse files
authored
[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 9914ab5. * code review * list control * null check * null null null * Jest fix
1 parent 6dbc4be commit bdb73b5

File tree

28 files changed

+125
-133
lines changed

28 files changed

+125
-133
lines changed

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@
156156
| [RangeFilterMeta](./kibana-plugin-plugins-data-public.rangefiltermeta.md) | |
157157
| [SavedQueryTimeFilter](./kibana-plugin-plugins-data-public.savedquerytimefilter.md) | |
158158
| [SearchBarProps](./kibana-plugin-plugins-data-public.searchbarprops.md) | |
159-
| [SearchRequest](./kibana-plugin-plugins-data-public.searchrequest.md) | |
160-
| [SearchResponse](./kibana-plugin-plugins-data-public.searchresponse.md) | |
161159
| [StatefulSearchBarProps](./kibana-plugin-plugins-data-public.statefulsearchbarprops.md) | |
162160
| [TabbedAggRow](./kibana-plugin-plugins-data-public.tabbedaggrow.md) | \* |
163161
| [TimefilterContract](./kibana-plugin-plugins-data-public.timefiltercontract.md) | |

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchrequest.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchresponse.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/plugins/data/common/search/es_search/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import { IKibanaSearchRequest, IKibanaSearchResponse } from '../types';
2222

2323
export const ES_SEARCH_STRATEGY = 'es';
2424

25-
export type ISearchRequestParams = {
25+
export type ISearchRequestParams<T = Record<string, any>> = {
2626
trackTotalHits?: boolean;
27-
} & Search;
27+
} & Search<T>;
2828

2929
export interface IEsSearchRequest extends IKibanaSearchRequest {
3030
params?: ISearchRequestParams;

src/plugins/data/public/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ export {
360360
SearchInterceptor,
361361
SearchInterceptorDeps,
362362
SearchRequest,
363-
SearchResponse,
364363
SearchSourceFields,
365364
SortDirection,
366365
// expression functions and types

src/plugins/data/public/public.api.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { SavedObject } from 'src/core/server';
6161
import { SavedObject as SavedObject_3 } from 'src/core/public';
6262
import { SavedObjectsClientContract } from 'src/core/public';
6363
import { Search } from '@elastic/elasticsearch/api/requestParams';
64-
import { SearchResponse as SearchResponse_2 } from 'elasticsearch';
64+
import { SearchResponse } from 'elasticsearch';
6565
import { SerializedFieldFormat as SerializedFieldFormat_2 } from 'src/plugins/expressions/common';
6666
import { Subscription } from 'rxjs';
6767
import { Toast } from 'kibana/public';
@@ -727,6 +727,7 @@ export function getEsPreference(uiSettings: IUiSettingsClient_2, sessionId?: str
727727
export const getKbnTypeNames: () => string[];
728728

729729
// Warning: (ae-forgotten-export) The symbol "ISearchRequestParams" needs to be exported by the entry point index.d.ts
730+
// Warning: (ae-incompatible-release-tags) The symbol "getSearchParamsFromRequest" is marked as @public, but its signature references "SearchRequest" which is marked as @internal
730731
//
731732
// @public (undocumented)
732733
export function getSearchParamsFromRequest(searchRequest: SearchRequest, dependencies: {
@@ -795,7 +796,7 @@ export interface IEsSearchResponse<Source = any> extends IKibanaSearchResponse {
795796
isPartial?: boolean;
796797
isRunning?: boolean;
797798
// (undocumented)
798-
rawResponse: SearchResponse_2<Source>;
799+
rawResponse: SearchResponse<Source>;
799800
}
800801

801802
// 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 {
17831784
usageCollector?: SearchUsageCollector;
17841785
}
17851786

1786-
// Warning: (ae-missing-release-tag) "SearchRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
1787-
//
1788-
// @public (undocumented)
1789-
export type SearchRequest = any;
1790-
1791-
// Warning: (ae-missing-release-tag) "SearchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
1792-
//
1793-
// @public (undocumented)
1794-
export type SearchResponse = any;
1787+
// @internal
1788+
export type SearchRequest = Record<string, any>;
17951789

17961790
// Warning: (ae-missing-release-tag) "SearchSourceFields" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
17971791
//
@@ -1991,21 +1985,21 @@ export const UI_SETTINGS: {
19911985
// 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
19921986
// 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
19931987
// 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
1994-
// 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
1995-
// 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
1996-
// 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
1997-
// 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
1998-
// 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
1999-
// 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
2000-
// 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
2001-
// 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
2002-
// 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
2003-
// 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
2004-
// 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
2005-
// 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
2006-
// 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
2007-
// 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
2008-
// 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
1988+
// 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
1989+
// 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
1990+
// 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
1991+
// 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
1992+
// 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
1993+
// 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
1994+
// 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
1995+
// 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
1996+
// 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
1997+
// 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
1998+
// 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
1999+
// 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
2000+
// 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
2001+
// 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
2002+
// 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
20092003
// 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
20102004
// 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
20112005
// 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/search/fetch/handle_response.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { handleResponse } from './handle_response';
2323
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2424
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
2525
import { setNotifications } from '../../services';
26+
import { SearchResponse } from 'elasticsearch';
2627

2728
jest.mock('@kbn/i18n', () => {
2829
return {
@@ -44,7 +45,7 @@ describe('handleResponse', () => {
4445
const request = { body: {} };
4546
const response = {
4647
timed_out: true,
47-
};
48+
} as SearchResponse<any>;
4849
const result = handleResponse(request, response);
4950
expect(result).toBe(response);
5051
expect(notifications.toasts.addWarning).toBeCalled();
@@ -57,9 +58,12 @@ describe('handleResponse', () => {
5758
const request = { body: {} };
5859
const response = {
5960
_shards: {
60-
failed: true,
61+
failed: 1,
62+
total: 2,
63+
successful: 1,
64+
skipped: 1,
6165
},
62-
};
66+
} as SearchResponse<any>;
6367
const result = handleResponse(request, response);
6468
expect(result).toBe(response);
6569
expect(notifications.toasts.addWarning).toBeCalled();
@@ -70,7 +74,7 @@ describe('handleResponse', () => {
7074

7175
test('returns the response', () => {
7276
const request = {};
73-
const response = {};
77+
const response = {} as SearchResponse<any>;
7478
const result = handleResponse(request, response);
7579
expect(result).toBe(response);
7680
});

src/plugins/data/public/search/fetch/handle_response.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@
2020
import React from 'react';
2121
import { i18n } from '@kbn/i18n';
2222
import { EuiSpacer } from '@elastic/eui';
23-
import { ShardFailureOpenModalButton, ShardFailureRequest, ShardFailureResponse } from '../../ui';
23+
import { SearchResponse } from 'elasticsearch';
24+
import { ShardFailureOpenModalButton } from '../../ui';
2425
import { toMountPoint } from '../../../../kibana_react/public';
2526
import { getNotifications } from '../../services';
26-
import { SearchRequest, SearchResponse } from '..';
27+
import { SearchRequest } from '..';
2728

28-
export function handleResponse(request: SearchRequest, response: SearchResponse) {
29+
export function handleResponse(request: SearchRequest, response: SearchResponse<any>) {
2930
if (response.timed_out) {
3031
getNotifications().toasts.addWarning({
3132
title: i18n.translate('data.search.searchSource.fetch.requestTimedOutNotificationMessage', {
@@ -53,11 +54,7 @@ export function handleResponse(request: SearchRequest, response: SearchResponse)
5354
<>
5455
{description}
5556
<EuiSpacer size="s" />
56-
<ShardFailureOpenModalButton
57-
request={request.body as ShardFailureRequest}
58-
response={response as ShardFailureResponse}
59-
title={title}
60-
/>
57+
<ShardFailureOpenModalButton request={request.body} response={response} title={title} />
6158
</>
6259
);
6360

src/plugins/data/public/search/fetch/request_error.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
* under the License.
1818
*/
1919

20+
import { SearchResponse } from 'elasticsearch';
2021
import { KbnError } from '../../../../kibana_utils/common';
21-
import { SearchError, SearchResponse } from './types';
22+
import { SearchError } from './types';
2223

2324
/**
2425
* Request Failure - When an entire multi request fails
2526
* @param {Error} err - the Error that came back
2627
* @param {Object} resp - optional HTTP response
2728
*/
2829
export class RequestFailure extends KbnError {
29-
public resp: SearchResponse;
30-
constructor(err: SearchError | null = null, resp?: SearchResponse) {
30+
public resp?: SearchResponse<any>;
31+
constructor(err: SearchError | null = null, resp?: SearchResponse<any>) {
3132
super(`Request to Elasticsearch failed: ${JSON.stringify(resp || err?.message)}`);
3233

3334
this.resp = resp;

src/plugins/data/public/search/fetch/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020
import { GetConfigFn } from '../../../common';
2121
import { ISearchStartLegacy } from '../types';
2222

23-
export type SearchRequest = any;
24-
export type SearchResponse = any;
23+
/**
24+
* @internal
25+
*
26+
* This type is used when flattenning a SearchSource and passing it down to legacy search.
27+
* Once legacy search is removed, this type should become internal to `SearchSource`,
28+
* where `ISearchRequestParams` is used externally instead.
29+
*/
30+
export type SearchRequest = Record<string, any>;
2531

2632
export interface FetchOptions {
2733
abortSignal?: AbortSignal;

0 commit comments

Comments
 (0)