diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.md index b47e00542da972a..d3abc8bcaf44b98 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.md @@ -15,6 +15,7 @@ export interface SearchStrategyDependencies | Property | Type | Description | | --- | --- | --- | | [esClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.esclient.md) | IScopedClusterClient | | +| [request](./kibana-plugin-plugins-data-server.searchstrategydependencies.request.md) | KibanaRequest | | | [savedObjectsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.savedobjectsclient.md) | SavedObjectsClientContract | | | [searchSessionsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md) | IScopedSearchSessionsClient | | | [uiSettingsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.uisettingsclient.md) | IUiSettingsClient | | diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index f52c622c48ed0dd..a651d7b3bf105e5 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -401,6 +401,7 @@ export class SearchService implements Plugin { savedObjectsClient, esClient: elasticsearch.client.asScoped(request), uiSettingsClient: uiSettings.asScopedToClient(savedObjectsClient), + request, }; return { search: < diff --git a/src/plugins/data/server/search/strategies/ese_search/ese_search_strategy.ts b/src/plugins/data/server/search/strategies/ese_search/ese_search_strategy.ts index cec4b9a2dbf9f6f..ab6162f756ea895 100644 --- a/src/plugins/data/server/search/strategies/ese_search/ese_search_strategy.ts +++ b/src/plugins/data/server/search/strategies/ese_search/ese_search_strategy.ts @@ -38,11 +38,13 @@ import { export const enhancedEsSearchStrategyProvider = ( legacyConfig$: Observable, logger: Logger, - usage?: SearchUsage + usage?: SearchUsage, + useInternalUser: boolean = false ): ISearchStrategy => { async function cancelAsyncSearch(id: string, esClient: IScopedClusterClient) { try { - await esClient.asCurrentUser.asyncSearch.delete({ id }); + const client = useInternalUser ? esClient.asInternalUser : esClient.asCurrentUser; + await client.asyncSearch.delete({ id }); } catch (e) { throw getKbnServerError(e); } @@ -53,7 +55,7 @@ export const enhancedEsSearchStrategyProvider = ( options: IAsyncSearchOptions, { esClient, uiSettingsClient, searchSessionsClient }: SearchStrategyDependencies ) { - const client = esClient.asCurrentUser.asyncSearch; + const client = useInternalUser ? esClient.asInternalUser : esClient.asCurrentUser; const search = async () => { const params = id @@ -66,7 +68,9 @@ export const enhancedEsSearchStrategyProvider = ( )), ...request.params, }; - const promise = id ? client.get({ ...params, id }) : client.submit(params); + const promise = id + ? client.asyncSearch.get({ ...params, id }) + : client.asyncSearch.submit(params); const { body } = await shimAbortSignal(promise, options.abortSignal); const response = shimHitsTotal(body.response, options); @@ -96,6 +100,7 @@ export const enhancedEsSearchStrategyProvider = ( options: ISearchOptions, { esClient, uiSettingsClient }: SearchStrategyDependencies ): Promise { + const client = useInternalUser ? esClient.asInternalUser : esClient.asCurrentUser; const legacyConfig = await legacyConfig$.pipe(first()).toPromise(); const { body, index, ...params } = request.params!; const method = 'POST'; @@ -108,7 +113,7 @@ export const enhancedEsSearchStrategyProvider = ( }; try { - const promise = esClient.asCurrentUser.transport.request({ + const promise = client.transport.request({ method, path, body, @@ -169,7 +174,11 @@ export const enhancedEsSearchStrategyProvider = ( extend: async (id, keepAlive, options, { esClient }) => { logger.debug(`extend ${id} by ${keepAlive}`); try { - await esClient.asCurrentUser.asyncSearch.get({ id, body: { keep_alive: keepAlive } }); + const client = useInternalUser ? esClient.asInternalUser : esClient.asCurrentUser; + await client.asyncSearch.get({ + id, + body: { keep_alive: keepAlive }, + }); } catch (e) { throw getKbnServerError(e); } diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 229c581bf09f11e..6192045fa04c74e 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -37,6 +37,7 @@ export interface SearchStrategyDependencies { esClient: IScopedClusterClient; uiSettingsClient: IUiSettingsClient; searchSessionsClient: IScopedSearchSessionsClient; + request: KibanaRequest; } export interface ISearchSetup { diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index ffdff2e33cf9cdb..a8eafd7b14aa983 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -37,8 +37,8 @@ import { ISearchOptions as ISearchOptions_2 } from 'src/plugins/data/public'; import { ISearchSource } from 'src/plugins/data/public'; import { IUiSettingsClient } from 'src/core/server'; import { IUiSettingsClient as IUiSettingsClient_3 } from 'kibana/server'; -import { KibanaRequest } from 'kibana/server'; -import { KibanaRequest as KibanaRequest_2 } from 'src/core/server'; +import { KibanaRequest } from 'src/core/server'; +import { KibanaRequest as KibanaRequest_2 } from 'kibana/server'; import { Logger } from 'src/core/server'; import { Logger as Logger_2 } from 'kibana/server'; import { LoggerFactory } from '@kbn/logging'; @@ -1040,7 +1040,7 @@ export interface ISearchOptions { // @public (undocumented) export interface ISearchSessionService { // (undocumented) - asScopedProvider: (core: CoreStart) => (request: KibanaRequest) => IScopedSearchSessionsClient; + asScopedProvider: (core: CoreStart) => (request: KibanaRequest_2) => IScopedSearchSessionsClient; } // Warning: (ae-missing-release-tag) "ISearchSetup" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -1068,11 +1068,11 @@ export interface ISearchStart IScopedSearchClient; + asScoped: (request: KibanaRequest) => IScopedSearchClient; getSearchStrategy: (name?: string) => ISearchStrategy; // (undocumented) searchSource: { - asScoped: (request: KibanaRequest_2) => Promise; + asScoped: (request: KibanaRequest) => Promise; }; } @@ -1391,6 +1391,8 @@ export interface SearchStrategyDependencies { // (undocumented) esClient: IScopedClusterClient; // (undocumented) + request: KibanaRequest; + // (undocumented) savedObjectsClient: SavedObjectsClientContract; // (undocumented) searchSessionsClient: IScopedSearchSessionsClient; @@ -1551,7 +1553,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:269:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:270:1 - (ae-forgotten-export) The symbol "calcAutoIntervalLessThan" needs to be exported by the entry point index.d.ts // src/plugins/data/server/plugin.ts:81:74 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts -// src/plugins/data/server/search/types.ts:114:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/search/types.ts:115:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts index 3cda019359caf9b..876aad4ef8d0270 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entries_search_strategy.test.ts @@ -9,6 +9,7 @@ import { ResponseError } from '@elastic/elasticsearch/lib/errors'; import { of, throwError } from 'rxjs'; import { elasticsearchServiceMock, + httpServerMock, savedObjectsClientMock, uiSettingsServiceMock, } from 'src/core/server/mocks'; @@ -327,6 +328,7 @@ const createSearchStrategyDependenciesMock = (): SearchStrategyDependencies => ( esClient: elasticsearchServiceMock.createScopedClusterClient(), savedObjectsClient: savedObjectsClientMock.create(), searchSessionsClient: createSearchSessionsClientMock(), + request: httpServerMock.createKibanaRequest(), }); // using the official data mock from within x-pack doesn't type-check successfully, diff --git a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts index f220c8913a2e616..88c9d956dbe0a23 100644 --- a/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts +++ b/x-pack/plugins/infra/server/services/log_entries/log_entry_search_strategy.test.ts @@ -9,6 +9,7 @@ import { ResponseError } from '@elastic/elasticsearch/lib/errors'; import { of, throwError } from 'rxjs'; import { elasticsearchServiceMock, + httpServerMock, savedObjectsClientMock, uiSettingsServiceMock, } from 'src/core/server/mocks'; @@ -282,6 +283,7 @@ const createSearchStrategyDependenciesMock = (): SearchStrategyDependencies => ( esClient: elasticsearchServiceMock.createScopedClusterClient(), savedObjectsClient: savedObjectsClientMock.create(), searchSessionsClient: createSearchSessionsClientMock(), + request: httpServerMock.createKibanaRequest(), }); // using the official data mock from within x-pack doesn't type-check successfully,