diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md index 18fca3d2c8a669..139c5794f01467 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md @@ -8,6 +8,7 @@ ```typescript setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; @@ -25,6 +26,7 @@ setup(core: CoreSetup, { expressio Returns: `{ + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; diff --git a/src/plugins/data/common/search/index.ts b/src/plugins/data/common/search/index.ts index 557ab64079d16f..d8184551b7f3d9 100644 --- a/src/plugins/data/common/search/index.ts +++ b/src/plugins/data/common/search/index.ts @@ -23,9 +23,6 @@ export * from './expressions'; export * from './tabify'; export * from './types'; -import { ES_SEARCH_STRATEGY } from './es_search'; -export const DEFAULT_SEARCH_STRATEGY = ES_SEARCH_STRATEGY; - export { IEsSearchRequest, IEsSearchResponse, diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 5163bfcb17d405..588885391262ec 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -21,7 +21,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from ' import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; import { ConfigSchema } from '../config'; import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns'; -import { ISearchSetup, ISearchStart } from './search'; +import { ISearchSetup, ISearchStart, SearchEnhancements } from './search'; import { SearchService } from './search/search_service'; import { QueryService } from './query/query_service'; import { ScriptsService } from './scripts'; @@ -31,9 +31,17 @@ import { AutocompleteService } from './autocomplete'; import { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats'; import { getUiSettings } from './ui_settings'; +export interface DataEnhancements { + search: SearchEnhancements; +} + export interface DataPluginSetup { search: ISearchSetup; fieldFormats: FieldFormatsSetup; + /** + * @internal + */ + __enhance: (enhancements: DataEnhancements) => void; } export interface DataPluginStart { @@ -87,11 +95,16 @@ export class DataServerPlugin core.uiSettings.register(getUiSettings()); + const searchSetup = this.searchService.setup(core, { + registerFunction: expressions.registerFunction, + usageCollection, + }); + return { - search: this.searchService.setup(core, { - registerFunction: expressions.registerFunction, - usageCollection, - }), + __enhance: (enhancements: DataEnhancements) => { + searchSetup.__enhance(enhancements.search); + }, + search: searchSetup, fieldFormats: this.fieldFormats.setup(), }; } diff --git a/src/plugins/data/server/search/index.ts b/src/plugins/data/server/search/index.ts index 4a3990621ca396..02c21c32546457 100644 --- a/src/plugins/data/server/search/index.ts +++ b/src/plugins/data/server/search/index.ts @@ -17,7 +17,13 @@ * under the License. */ -export { ISearchStrategy, ISearchOptions, ISearchSetup, ISearchStart } from './types'; +export { + ISearchStrategy, + ISearchOptions, + ISearchSetup, + ISearchStart, + SearchEnhancements, +} from './types'; export { getDefaultSearchParams, getTotalLoaded } from './es_search'; diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts index 578a170f468bff..0c74ecb4b2c9df 100644 --- a/src/plugins/data/server/search/mocks.ts +++ b/src/plugins/data/server/search/mocks.ts @@ -24,6 +24,7 @@ export function createSearchSetupMock(): jest.Mocked { return { aggs: searchAggsSetupMock(), registerSearchStrategy: jest.fn(), + __enhance: jest.fn(), }; } diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index cc23c455bed267..edc94961c79d87 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -25,7 +25,7 @@ import { PluginInitializerContext, RequestHandlerContext, } from '../../../../core/server'; -import { ISearchSetup, ISearchStart, ISearchStrategy } from './types'; +import { ISearchSetup, ISearchStart, ISearchStrategy, SearchEnhancements } from './types'; import { AggsService, AggsSetupDependencies } from './aggs'; @@ -57,6 +57,7 @@ export interface SearchServiceStartDependencies { export class SearchService implements Plugin { private readonly aggsService = new AggsService(); + private defaultSearchStrategyName: string = ES_SEARCH_STRATEGY; private searchStrategies: StrategyMap = {}; constructor( @@ -87,6 +88,11 @@ export class SearchService implements Plugin { registerSearchRoute(core); return { + __enhance: (enhancements: SearchEnhancements) => { + if (this.searchStrategies.hasOwnProperty(enhancements.defaultStrategy)) { + this.defaultSearchStrategyName = enhancements.defaultStrategy; + } + }, aggs: this.aggsService.setup({ registerFunction }), registerSearchStrategy: this.registerSearchStrategy, usage, @@ -98,11 +104,9 @@ export class SearchService implements Plugin { searchRequest: IEsSearchRequest, options: Record ) { - return this.getSearchStrategy(options.strategy || ES_SEARCH_STRATEGY).search( - context, - searchRequest, - { signal: options.signal } - ); + return this.getSearchStrategy( + options.strategy || this.defaultSearchStrategyName + ).search(context, searchRequest, { signal: options.signal }); } public start( diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 56f803512aa196..5ce1bb3e6b9f80 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -23,6 +23,10 @@ import { AggsSetup, AggsStart } from './aggs'; import { SearchUsage } from './collectors/usage'; import { IEsSearchRequest, IEsSearchResponse } from './es_search'; +export interface SearchEnhancements { + defaultStrategy: string; +} + export interface ISearchOptions { /** * An `AbortSignal` that allows the caller of `search` to abort a search request. @@ -49,6 +53,11 @@ export interface ISearchSetup { * Used internally for telemetry */ usage?: SearchUsage; + + /** + * @internal + */ + __enhance: (enhancements: SearchEnhancements) => void; } export interface ISearchStart< diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index 89d77eac102b23..66d0dbefbdf9f5 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -687,6 +687,10 @@ export interface ISearchOptions { // // @public (undocumented) export interface ISearchSetup { + // Warning: (ae-forgotten-export) The symbol "SearchEnhancements" needs to be exported by the entry point index.d.ts + // + // @internal (undocumented) + __enhance: (enhancements: SearchEnhancements) => void; // Warning: (ae-forgotten-export) The symbol "AggsSetup" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -857,6 +861,7 @@ export class Plugin implements Plugin_2); // (undocumented) setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; @@ -885,6 +890,8 @@ export function plugin(initializerContext: PluginInitializerContext void; // Warning: (ae-forgotten-export) The symbol "FieldFormatsSetup" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -1092,6 +1099,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/x-pack/plugins/data_enhanced/common/index.ts b/x-pack/plugins/data_enhanced/common/index.ts index 1f1cd938c97d1d..d6a3c73aaf363b 100644 --- a/x-pack/plugins/data_enhanced/common/index.ts +++ b/x-pack/plugins/data_enhanced/common/index.ts @@ -4,4 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './search'; +export { + EnhancedSearchParams, + IEnhancedEsSearchRequest, + IAsyncSearchRequest, + ENHANCED_ES_SEARCH_STRATEGY, +} from './search'; diff --git a/x-pack/plugins/data_enhanced/common/search/index.ts b/x-pack/plugins/data_enhanced/common/search/index.ts index 129e412a47ccf1..2ae422bd6b7d7f 100644 --- a/x-pack/plugins/data_enhanced/common/search/index.ts +++ b/x-pack/plugins/data_enhanced/common/search/index.ts @@ -4,4 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './types'; +export { + EnhancedSearchParams, + IEnhancedEsSearchRequest, + IAsyncSearchRequest, + ENHANCED_ES_SEARCH_STRATEGY, +} from './types'; diff --git a/x-pack/plugins/data_enhanced/common/search/types.ts b/x-pack/plugins/data_enhanced/common/search/types.ts index a5d7d326cecd5b..0d3d3a69e1e571 100644 --- a/x-pack/plugins/data_enhanced/common/search/types.ts +++ b/x-pack/plugins/data_enhanced/common/search/types.ts @@ -6,6 +6,8 @@ import { IEsSearchRequest, ISearchRequestParams } from '../../../../../src/plugins/data/common'; +export const ENHANCED_ES_SEARCH_STRATEGY = 'ese'; + export interface EnhancedSearchParams extends ISearchRequestParams { ignoreThrottled: boolean; } diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts index 47099e32fcc726..6f7899d1188b49 100644 --- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts +++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts @@ -14,7 +14,7 @@ import { } from '../../../../../src/plugins/data/public'; import { AbortError, toPromise } from '../../../../../src/plugins/data/common'; import { IAsyncSearchOptions } from '.'; -import { IAsyncSearchRequest } from '../../common'; +import { IAsyncSearchRequest, ENHANCED_ES_SEARCH_STRATEGY } from '../../common'; export class EnhancedSearchInterceptor extends SearchInterceptor { /** @@ -76,10 +76,11 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { const { combinedSignal, cleanup } = this.setupTimers(options); const aborted$ = from(toPromise(combinedSignal)); + const strategy = options?.strategy || ENHANCED_ES_SEARCH_STRATEGY; this.pendingCount$.next(this.pendingCount$.getValue() + 1); - return this.runSearch(request, combinedSignal, options?.strategy).pipe( + return this.runSearch(request, combinedSignal, strategy).pipe( expand((response) => { // If the response indicates of an error, stop polling and complete the observable if (!response || (!response.isRunning && response.isPartial)) { @@ -96,7 +97,7 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { return timer(pollInterval).pipe( // Send future requests using just the ID from the response mergeMap(() => { - return this.runSearch({ ...request, id }, combinedSignal, options?.strategy); + return this.runSearch({ ...request, id }, combinedSignal, strategy); }) ); }), diff --git a/x-pack/plugins/data_enhanced/server/plugin.ts b/x-pack/plugins/data_enhanced/server/plugin.ts index 0e9731a4141195..f9b6fd4e9ad649 100644 --- a/x-pack/plugins/data_enhanced/server/plugin.ts +++ b/x-pack/plugins/data_enhanced/server/plugin.ts @@ -11,7 +11,6 @@ import { Plugin, Logger, } from '../../../../src/core/server'; -import { ES_SEARCH_STRATEGY } from '../../../../src/plugins/data/common'; import { PluginSetup as DataPluginSetup, PluginStart as DataPluginStart, @@ -19,6 +18,7 @@ import { } from '../../../../src/plugins/data/server'; import { enhancedEsSearchStrategyProvider } from './search'; import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server'; +import { ENHANCED_ES_SEARCH_STRATEGY } from '../common'; interface SetupDependencies { data: DataPluginSetup; @@ -36,13 +36,19 @@ export class EnhancedDataServerPlugin implements Plugin