Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] Unify search plugin step 3 — Rollup search strategy #98122

Closed
wants to merge 11 commits into from
Closed

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md)

## IEsSearchRequest interface
## IEsSearchRequest type

<b>Signature:</b>

```typescript
export interface IEsSearchRequest extends IKibanaSearchRequest<ISearchRequestParams>
export declare type IEsSearchRequest = IKibanaSearchRequest<ISearchRequestParams>;
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [indexType](./kibana-plugin-plugins-data-public.iessearchrequest.indextype.md) | <code>string</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
| [EsQueryConfig](./kibana-plugin-plugins-data-public.esqueryconfig.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-public.fieldformatconfig.md) | |
| [IDataPluginServices](./kibana-plugin-plugins-data-public.idatapluginservices.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | |
| [IFieldSubType](./kibana-plugin-plugins-data-public.ifieldsubtype.md) | |
| [IFieldType](./kibana-plugin-plugins-data-public.ifieldtype.md) | |
| [IIndexPattern](./kibana-plugin-plugins-data-public.iindexpattern.md) | IIndexPattern allows for an IndexPattern OR an index pattern saved object too ambiguous, should be avoided |
Expand Down Expand Up @@ -164,6 +163,7 @@
| [IAggConfig](./kibana-plugin-plugins-data-public.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. |
| [IAggType](./kibana-plugin-plugins-data-public.iaggtype.md) | |
| [IEsError](./kibana-plugin-plugins-data-public.ieserror.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-public.iessearchrequest.md) | |
| [IEsSearchResponse](./kibana-plugin-plugins-data-public.iessearchresponse.md) | |
| [IFieldFormat](./kibana-plugin-plugins-data-public.ifieldformat.md) | |
| [IFieldFormatsRegistry](./kibana-plugin-plugins-data-public.ifieldformatsregistry.md) | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "isClearable" | "intl" | "refreshInterval" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated"> & ReactIntl.InjectedIntlProps>;
SearchBar: React.ComponentClass<Pick<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "refreshInterval" | "isClearable" | "intl" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "refreshInterval" | "isClearable" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated">, any> & {
WrappedComponent: React.ComponentType<Pick<SearchBarProps, "query" | "placeholder" | "isLoading" | "iconType" | "indexPatterns" | "filters" | "dataTestSubj" | "refreshInterval" | "isClearable" | "intl" | "nonKqlMode" | "nonKqlModeHelpText" | "screenTitle" | "onRefresh" | "onRefreshChange" | "showQueryInput" | "showDatePicker" | "showAutoRefreshOnly" | "dateRangeFrom" | "dateRangeTo" | "isRefreshPaused" | "customSubmitButton" | "timeHistory" | "indicateNoData" | "onFiltersUpdated" | "savedQuery" | "showSaveQuery" | "onClearSavedQuery" | "showQueryBar" | "showFilterBar" | "onQueryChange" | "onQuerySubmit" | "onSaved" | "onSavedQueryUpdated"> & ReactIntl.InjectedIntlProps>;
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<b>Signature:</b>

```typescript
protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions, "strategy" | "sessionId" | "isStored" | "isRestore" | "legacyHitsTotal">;
protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions, "strategy" | "sessionId" | "legacyHitsTotal" | "isStored" | "isRestore">;
```

## Parameters
Expand All @@ -18,5 +18,5 @@ protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions,

<b>Returns:</b>

`Pick<ISearchOptions, "strategy" | "sessionId" | "isStored" | "isRestore" | "legacyHitsTotal">`
`Pick<ISearchOptions, "strategy" | "sessionId" | "legacyHitsTotal" | "isStored" | "isRestore">`

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [IEsSearchRequest](./kibana-plugin-plugins-data-server.iessearchrequest.md)

## IEsSearchRequest interface
## IEsSearchRequest type

<b>Signature:</b>

```typescript
export interface IEsSearchRequest extends IKibanaSearchRequest<ISearchRequestParams>
export declare type IEsSearchRequest = IKibanaSearchRequest<ISearchRequestParams>;
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [indexType](./kibana-plugin-plugins-data-server.iessearchrequest.indextype.md) | <code>string</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
| [EsQueryConfig](./kibana-plugin-plugins-data-server.esqueryconfig.md) | |
| [FieldDescriptor](./kibana-plugin-plugins-data-server.fielddescriptor.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-server.fieldformatconfig.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-server.iessearchrequest.md) | |
| [IFieldSubType](./kibana-plugin-plugins-data-server.ifieldsubtype.md) | |
| [IFieldType](./kibana-plugin-plugins-data-server.ifieldtype.md) | |
| [IndexPatternAttributes](./kibana-plugin-plugins-data-server.indexpatternattributes.md) | Interface for an index pattern saved object |
Expand Down Expand Up @@ -103,6 +102,7 @@
| [Filter](./kibana-plugin-plugins-data-server.filter.md) | |
| [IAggConfig](./kibana-plugin-plugins-data-server.iaggconfig.md) | AggConfig This class represents an aggregation, which is displayed in the left-hand nav of the Visualize app. |
| [IAggType](./kibana-plugin-plugins-data-server.iaggtype.md) | |
| [IEsSearchRequest](./kibana-plugin-plugins-data-server.iessearchrequest.md) | |
| [IEsSearchResponse](./kibana-plugin-plugins-data-server.iessearchresponse.md) | |
| [IFieldFormatsRegistry](./kibana-plugin-plugins-data-server.ifieldformatsregistry.md) | |
| [IFieldParamType](./kibana-plugin-plugins-data-server.ifieldparamtype.md) | |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './poll_search';
export * from './strategies/es_search';
export * from './strategies/eql_search';
export * from './strategies/ese_search';
export * from './strategies/rollup_search';
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
} from '../../../common';
import { getHighlightRequest } from '../../../common/field_formats';
import { extractReferences } from './extract_references';
import { ROLLUP_SEARCH_STRATEGY } from '../strategies/rollup_search';

/** @internal */
export const searchSourceRequiredUiSettings = [
Expand Down Expand Up @@ -439,7 +440,12 @@ export class SearchSource {
getConfig,
});

return search({ params, indexType: searchRequest.indexType }, options).pipe(
// force a rollup strategy in case this is a rollup index
if (!options.strategy && searchRequest.indexType === 'rollup') {
Dosant marked this conversation as resolved.
Show resolved Hide resolved
options.strategy = ROLLUP_SEARCH_STRATEGY;
}

return search({ params }, options).pipe(
switchMap((response) => {
return new Observable<IKibanaSearchResponse<any>>((obs) => {
if (isErrorResponse(response)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export type ISearchRequestParams = {
trackTotalHits?: boolean;
} & estypes.SearchRequest;

export interface IEsSearchRequest extends IKibanaSearchRequest<ISearchRequestParams> {
indexType?: string;
}
export type IEsSearchRequest = IKibanaSearchRequest<ISearchRequestParams>;

export type IEsSearchResponse<Source = any> = IKibanaSearchResponse<estypes.SearchResponse<Source>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { estypes } from '@elastic/elasticsearch';
import type { Indices } from '@elastic/elasticsearch/api/types';

import { IKibanaSearchRequest, IKibanaSearchResponse } from '../../types';

export const ROLLUP_SEARCH_STRATEGY = 'rollup';

export interface IRollupSearchRequestParams extends estypes.SearchRequest {
index: Indices; // index is required
}

export type IRollupSearchRequest = IKibanaSearchRequest<IRollupSearchRequestParams>;

export type IRollupSearchResponse<Source = any> = IKibanaSearchResponse<
estypes.SearchResponse<Source>
>;
7 changes: 2 additions & 5 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1141,10 +1141,7 @@ export type IEsError = KibanaServerError<IEsErrorAttributes>;
// Warning: (ae-missing-release-tag) "IEsSearchRequest" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface IEsSearchRequest extends IKibanaSearchRequest<ISearchRequestParams> {
// (undocumented)
indexType?: string;
}
export type IEsSearchRequest = IKibanaSearchRequest<ISearchRequestParams>;

// Warning: (ae-missing-release-tag) "IEsSearchResponse" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down Expand Up @@ -2392,7 +2389,7 @@ export class SearchInterceptor {
// (undocumented)
protected readonly deps: SearchInterceptorDeps;
// (undocumented)
protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions, "strategy" | "sessionId" | "isStored" | "isRestore" | "legacyHitsTotal">;
protected getSerializableOptions(options?: ISearchOptions): Pick<ISearchOptions, "strategy" | "sessionId" | "legacyHitsTotal" | "isStored" | "isRestore">;
// (undocumented)
protected getTimeoutMode(): TimeoutErrorMode;
// Warning: (ae-forgotten-export) The symbol "AbortError" needs to be exported by the entry point index.d.ts
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
esRawResponse,
ENHANCED_ES_SEARCH_STRATEGY,
EQL_SEARCH_STRATEGY,
ROLLUP_SEARCH_STRATEGY,
} from '../../common/search';
import { getEsaggs, getEsdsl } from './expressions';
import {
Expand All @@ -80,6 +81,7 @@ import { registerBsearchRoute } from './routes/bsearch';
import { getKibanaContext } from './expressions/kibana_context';
import { enhancedEsSearchStrategyProvider } from './strategies/ese_search';
import { eqlSearchStrategyProvider } from './strategies/eql_search';
import { rollupSearchStrategyProvider } from './strategies/rollup_search';

type StrategyMap = Record<string, ISearchStrategy<any, any>>;

Expand Down Expand Up @@ -156,6 +158,14 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
);

this.registerSearchStrategy(EQL_SEARCH_STRATEGY, eqlSearchStrategyProvider(this.logger));
this.registerSearchStrategy(
ROLLUP_SEARCH_STRATEGY,
rollupSearchStrategyProvider(
this.initializerContext.config.legacy.globalConfig$,
this.logger,
usage
)
);

registerBsearchRoute(bfetch, (request: KibanaRequest) => this.asScoped(request));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,4 @@ describe('ES search strategy', () => {
done();
}
});

it('throws KbnServerError for unknown index type', async (done) => {
const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };

try {
await esSearchStrategyProvider(mockConfig$, mockLogger)
.search({ indexType: 'banana', params }, {}, getMockedDeps())
.toPromise();
} catch (e) {
expect(mockApiCaller).not.toBeCalled();
expect(e).toBeInstanceOf(KbnServerError);
expect(e.message).toBe('Unsupported index pattern type banana');
expect(e.statusCode).toBe(400);
expect(e.errBody).toBe(undefined);
done();
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { SearchUsage } from '../../collectors';
import { getDefaultSearchParams, getShardTimeout, shimAbortSignal } from './request_utils';
import { shimHitsTotal, toKibanaSearchResponse } from './response_utils';
import { searchUsageObserver } from '../../collectors/usage';
import { getKbnServerError, KbnServerError } from '../../../../../kibana_utils/server';
import { getKbnServerError } from '../../../../../kibana_utils/server';

export const esSearchStrategyProvider = (
config$: Observable<SharedGlobalConfig>,
Expand All @@ -29,12 +29,6 @@ export const esSearchStrategyProvider = (
* @returns `Observable<IEsSearchResponse<any>>`
*/
search: (request, { abortSignal, ...options }, { esClient, uiSettingsClient }) => {
// Only default index pattern type is supported here.
// See data_enhanced for other type support.
if (request.indexType) {
throw new KbnServerError(`Unsupported index pattern type ${request.indexType}`, 400);
}

const search = async () => {
try {
const config = await config$.pipe(first()).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ const mockAsyncResponse = {
},
};

const mockRollupResponse = {
body: {
_shards: {
total: 10,
failed: 1,
skipped: 2,
successful: 7,
},
},
};

describe('ES search strategy', () => {
const mockApiCaller = jest.fn();
const mockGetCaller = jest.fn();
Expand Down Expand Up @@ -132,29 +121,6 @@ describe('ES search strategy', () => {
expect(request).toHaveProperty('wait_for_completion_timeout');
expect(request).toHaveProperty('keep_alive');
});

it('calls the rollup API if the index is a rollup type', async () => {
mockApiCaller.mockResolvedValueOnce(mockRollupResponse);

const params = { index: 'foo-程', body: {} };
const esSearch = await enhancedEsSearchStrategyProvider(mockLegacyConfig$, mockLogger);

await esSearch
.search(
{
indexType: 'rollup',
params,
},
{},
mockDeps
)
.toPromise();

expect(mockApiCaller).toBeCalled();
const { method, path } = mockApiCaller.mock.calls[0][0];
Dosant marked this conversation as resolved.
Show resolved Hide resolved
expect(method).toBe('POST');
expect(path).toBe('/foo-%E7%A8%8B/_rollup_search');
});
});

describe('with sessionId', () => {
Expand Down
Loading