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) | |
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

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 @@ -10,7 +10,12 @@ import { of } from 'rxjs';
import { IndexPattern } from '../../index_patterns';
import { GetConfigFn } from '../../types';
import { SearchSource, SearchSourceDependencies, SortDirection } from './';
import { AggConfigs, AggTypesRegistryStart, ES_SEARCH_STRATEGY } from '../../';
import {
AggConfigs,
AggTypesRegistryStart,
ES_SEARCH_STRATEGY,
ROLLUP_SEARCH_STRATEGY,
} from '../../';
import { mockAggTypesRegistry } from '../aggs/test_helpers';
import { RequestResponder } from 'src/plugins/inspector/common';
import { switchMap } from 'rxjs/operators';
Expand All @@ -32,6 +37,14 @@ const indexPattern = ({
getSourceFiltering: () => mockSource,
} as unknown) as IndexPattern;

const rollupIndexPattern = ({
title: 'foo',
type: 'rollup',
fields: [{ name: 'foo-bar' }, { name: 'field1' }, { name: 'field2' }],
getComputedFields,
getSourceFiltering: () => mockSource,
} as unknown) as IndexPattern;

const indexPattern2 = ({
title: 'foo',
getComputedFields,
Expand Down Expand Up @@ -917,6 +930,44 @@ describe('SearchSource', () => {
const [, callOptions] = mockSearchMethod.mock.calls[0];
expect(callOptions.strategy).toBe('banana');
});

test('should use rollup search if rollup index', async () => {
searchSource = new SearchSource({ index: rollupIndexPattern }, searchSourceDependencies);
const options = {};
await searchSource.fetch$(options).toPromise();

const [, callOptions] = mockSearchMethod.mock.calls[0];
expect(callOptions.strategy).toBe(ROLLUP_SEARCH_STRATEGY);
});

test('should not use rollup search if overriden', async () => {
searchSource = new SearchSource({ index: rollupIndexPattern }, searchSourceDependencies);
const options = { strategy: 'banana' };
await searchSource.fetch$(options).toPromise();

const [, callOptions] = mockSearchMethod.mock.calls[0];
expect(callOptions.strategy).toBe('banana');
});
});

describe('Rollup search', () => {
test('should use rollup search if rollup index', async () => {
searchSource = new SearchSource({ index: rollupIndexPattern }, searchSourceDependencies);
const options = {};
await searchSource.fetch$(options).toPromise();

const [, callOptions] = mockSearchMethod.mock.calls[0];
expect(callOptions.strategy).toBe(ROLLUP_SEARCH_STRATEGY);
});

test('should not use rollup search if overriden', async () => {
searchSource = new SearchSource({ index: rollupIndexPattern }, searchSourceDependencies);
const options = { strategy: 'banana' };
await searchSource.fetch$(options).toPromise();

const [, callOptions] = mockSearchMethod.mock.calls[0];
expect(callOptions.strategy).toBe('banana');
});
});

describe('responses', () => {
Expand Down
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 @@ -276,10 +277,11 @@ export class SearchSource {
): Observable<IKibanaSearchResponse<estypes.SearchResponse<any>>> {
const { getConfig } = this.dependencies;
const syncSearchByDefault = getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES);
const hasExplicitStrategy = !!options.strategy;

// Use the sync search strategy if legacy search is enabled.
// This still uses bfetch for batching.
if (!options?.strategy && syncSearchByDefault) {
if (!hasExplicitStrategy && syncSearchByDefault) {
options.strategy = ES_SEARCH_STRATEGY;
}

Expand All @@ -289,6 +291,9 @@ export class SearchSource {
this.history = [searchRequest];
if (searchRequest.index) {
options.indexPattern = searchRequest.index;
if (searchRequest.indexType === 'rollup' && !hasExplicitStrategy) {
options.strategy = ROLLUP_SEARCH_STRATEGY;
}
}

return this.fetchSearch$(searchRequest, options);
Expand Down Expand Up @@ -445,7 +450,7 @@ export class SearchSource {
getConfig,
});

return search({ params, indexType: searchRequest.indexType }, options).pipe(
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>
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Must specify at least one concrete index."
}
],
"type": "illegal_argument_exception",
"reason": "Must specify at least one concrete index."
},
"status": 400
}
5 changes: 1 addition & 4 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1136,10 +1136,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
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
Loading