diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md
deleted file mode 100644
index 8b7b025d80181..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [DataApiRequestHandlerContext](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md)
-
-## DataApiRequestHandlerContext interface
-
-Signature:
-
-```typescript
-export interface DataApiRequestHandlerContext extends ISearchClient
-```
-
-## Properties
-
-| Property | Type | Description |
-| --- | --- | --- |
-| [session](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.session.md) | IScopedSessionService
| |
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.session.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.session.md
deleted file mode 100644
index 9a6e3f55d3929..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.dataapirequesthandlercontext.session.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [DataApiRequestHandlerContext](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md) > [session](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.session.md)
-
-## DataApiRequestHandlerContext.session property
-
-Signature:
-
-```typescript
-session: IScopedSessionService;
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.md
deleted file mode 100644
index eaac671b9a182..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.md
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IScopedSessionService](./kibana-plugin-plugins-data-server.iscopedsessionservice.md)
-
-## IScopedSessionService interface
-
-Signature:
-
-```typescript
-export interface IScopedSessionService
-```
-
-## Properties
-
-| Property | Type | Description |
-| --- | --- | --- |
-| [search](./kibana-plugin-plugins-data-server.iscopedsessionservice.search.md) | <Request extends IKibanaSearchRequest, Response extends IKibanaSearchResponse>(strategy: ISearchStrategy<Request, Response>, ...args: Parameters<ISearchStrategy<Request, Response>['search']>) => Observable<Response>
| |
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.search.md
deleted file mode 100644
index d58a9fd9f3761..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.iscopedsessionservice.search.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [IScopedSessionService](./kibana-plugin-plugins-data-server.iscopedsessionservice.md) > [search](./kibana-plugin-plugins-data-server.iscopedsessionservice.search.md)
-
-## IScopedSessionService.search property
-
-Signature:
-
-```typescript
-search: (strategy: ISearchStrategy, ...args: Parameters['search']>) => Observable;
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md
new file mode 100644
index 0000000000000..3f3d1a2429933
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md) > [asScopedProvider](./kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md)
+
+## ISearchSessionService.asScopedProvider property
+
+Signature:
+
+```typescript
+asScopedProvider: (core: CoreStart) => (request: KibanaRequest) => IScopedSearchSessionsClient;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.md
new file mode 100644
index 0000000000000..e7a92497308b9
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchsessionservice.md
@@ -0,0 +1,18 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md)
+
+## ISearchSessionService interface
+
+Signature:
+
+```typescript
+export interface ISearchSessionService
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [asScopedProvider](./kibana-plugin-plugins-data-server.isearchsessionservice.asscopedprovider.md) | (core: CoreStart) => (request: KibanaRequest) => IScopedSearchSessionsClient<T>
| |
+
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.asscoped.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.asscoped.md
index f97cc22a53001..1c65aeb8f137f 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.asscoped.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.asscoped.md
@@ -7,5 +7,5 @@
Signature:
```typescript
-asScoped: (request: KibanaRequest) => ISearchClient;
+asScoped: (request: KibanaRequest) => IScopedSearchClient;
```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
index 771b529f23824..52579a0a14b4d 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isearchstart.md
@@ -15,7 +15,7 @@ export interface ISearchStartAggsStart | |
-| [asScoped](./kibana-plugin-plugins-data-server.isearchstart.asscoped.md) | (request: KibanaRequest) => ISearchClient
| |
+| [asScoped](./kibana-plugin-plugins-data-server.isearchstart.asscoped.md) | (request: KibanaRequest) => IScopedSearchClient
| |
| [getSearchStrategy](./kibana-plugin-plugins-data-server.isearchstart.getsearchstrategy.md) | (name?: string) => ISearchStrategy<SearchStrategyRequest, SearchStrategyResponse>
| Get other registered search strategies by name (or, by default, the Elasticsearch strategy). For example, if a new strategy needs to use the already-registered ES search strategy, it can use this function to accomplish that. |
| [searchSource](./kibana-plugin-plugins-data-server.isearchstart.searchsource.md) | {
asScoped: (request: KibanaRequest) => Promise<ISearchStartSearchSource>;
}
| |
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md
deleted file mode 100644
index d52b9b783919b..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md) > [asScopedProvider](./kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md)
-
-## ISessionService.asScopedProvider property
-
-Signature:
-
-```typescript
-asScopedProvider: (core: CoreStart) => (request: KibanaRequest) => IScopedSessionService;
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.md
deleted file mode 100644
index dcc7dfc8bb946..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.isessionservice.md
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md)
-
-## ISessionService interface
-
-Signature:
-
-```typescript
-export interface ISessionService
-```
-
-## Properties
-
-| Property | Type | Description |
-| --- | --- | --- |
-| [asScopedProvider](./kibana-plugin-plugins-data-server.isessionservice.asscopedprovider.md) | (core: CoreStart) => (request: KibanaRequest) => IScopedSessionService
| |
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
index 6847808d51bdb..4739de481e020 100644
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md
@@ -14,7 +14,6 @@
| [IndexPatternsService](./kibana-plugin-plugins-data-server.indexpatternsservice.md) | |
| [OptionedParamType](./kibana-plugin-plugins-data-server.optionedparamtype.md) | |
| [Plugin](./kibana-plugin-plugins-data-server.plugin.md) | |
-| [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) | The OSS session service. See data\_enhanced in X-Pack for the search session service. |
## Enumerations
@@ -45,7 +44,6 @@
| --- | --- |
| [AggFunctionsMapping](./kibana-plugin-plugins-data-server.aggfunctionsmapping.md) | A global list of the expression function definitions for each agg type function. |
| [AggParamOption](./kibana-plugin-plugins-data-server.aggparamoption.md) | |
-| [DataApiRequestHandlerContext](./kibana-plugin-plugins-data-server.dataapirequesthandlercontext.md) | |
| [EsQueryConfig](./kibana-plugin-plugins-data-server.esqueryconfig.md) | |
| [FieldDescriptor](./kibana-plugin-plugins-data-server.fielddescriptor.md) | |
| [FieldFormatConfig](./kibana-plugin-plugins-data-server.fieldformatconfig.md) | |
@@ -53,12 +51,11 @@
| [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 |
-| [IScopedSessionService](./kibana-plugin-plugins-data-server.iscopedsessionservice.md) | |
| [ISearchOptions](./kibana-plugin-plugins-data-server.isearchoptions.md) | |
+| [ISearchSessionService](./kibana-plugin-plugins-data-server.isearchsessionservice.md) | |
| [ISearchSetup](./kibana-plugin-plugins-data-server.isearchsetup.md) | |
| [ISearchStart](./kibana-plugin-plugins-data-server.isearchstart.md) | |
| [ISearchStrategy](./kibana-plugin-plugins-data-server.isearchstrategy.md) | Search strategy interface contains a search method that takes in a request and returns a promise that resolves to a response. |
-| [ISessionService](./kibana-plugin-plugins-data-server.isessionservice.md) | |
| [KueryNode](./kibana-plugin-plugins-data-server.kuerynode.md) | |
| [OptionedValueProp](./kibana-plugin-plugins-data-server.optionedvalueprop.md) | |
| [PluginSetup](./kibana-plugin-plugins-data-server.pluginsetup.md) | |
@@ -110,5 +107,6 @@
| [KibanaContext](./kibana-plugin-plugins-data-server.kibanacontext.md) | |
| [ParsedInterval](./kibana-plugin-plugins-data-server.parsedinterval.md) | |
| [Query](./kibana-plugin-plugins-data-server.query.md) | |
+| [SearchRequestHandlerContext](./kibana-plugin-plugins-data-server.searchrequesthandlercontext.md) | |
| [TimeRange](./kibana-plugin-plugins-data-server.timerange.md) | |
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchrequesthandlercontext.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchrequesthandlercontext.md
new file mode 100644
index 0000000000000..f031ddfbd09af
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchrequesthandlercontext.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchRequestHandlerContext](./kibana-plugin-plugins-data-server.searchrequesthandlercontext.md)
+
+## SearchRequestHandlerContext type
+
+Signature:
+
+```typescript
+export declare type SearchRequestHandlerContext = IScopedSearchClient;
+```
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 be95fb04a2c4f..b47e00542da97 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
@@ -16,5 +16,6 @@ export interface SearchStrategyDependencies
| --- | --- | --- |
| [esClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.esclient.md) | IScopedClusterClient
| |
| [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/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md
new file mode 100644
index 0000000000000..5340ed9673c02
--- /dev/null
+++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md
@@ -0,0 +1,11 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SearchStrategyDependencies](./kibana-plugin-plugins-data-server.searchstrategydependencies.md) > [searchSessionsClient](./kibana-plugin-plugins-data-server.searchstrategydependencies.searchsessionsclient.md)
+
+## SearchStrategyDependencies.searchSessionsClient property
+
+Signature:
+
+```typescript
+searchSessionsClient: IScopedSearchSessionsClient;
+```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice._constructor_.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice._constructor_.md
deleted file mode 100644
index 73d658455a66f..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice._constructor_.md
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) > [(constructor)](./kibana-plugin-plugins-data-server.sessionservice._constructor_.md)
-
-## SessionService.(constructor)
-
-Constructs a new instance of the `SessionService` class
-
-Signature:
-
-```typescript
-constructor();
-```
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md
deleted file mode 100644
index f3af7fb0f61d9..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) > [asScopedProvider](./kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md)
-
-## SessionService.asScopedProvider() method
-
-Signature:
-
-```typescript
-asScopedProvider(core: CoreStart): (request: KibanaRequest) => {
- search: , Response_1 extends IKibanaSearchResponse>(strategy: ISearchStrategy, request: Request_1, options: import("../../../common").ISearchOptions, deps: import("../types").SearchStrategyDependencies) => import("rxjs").Observable;
- };
-```
-
-## Parameters
-
-| Parameter | Type | Description |
-| --- | --- | --- |
-| core | CoreStart
| |
-
-Returns:
-
-`(request: KibanaRequest) => {
- search: , Response_1 extends IKibanaSearchResponse>(strategy: ISearchStrategy, request: Request_1, options: import("../../../common").ISearchOptions, deps: import("../types").SearchStrategyDependencies) => import("rxjs").Observable;
- }`
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.md
deleted file mode 100644
index 2457f7103d8fa..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.md
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md)
-
-## SessionService class
-
-The OSS session service. See data\_enhanced in X-Pack for the search session service.
-
-Signature:
-
-```typescript
-export declare class SessionService implements ISessionService
-```
-
-## Constructors
-
-| Constructor | Modifiers | Description |
-| --- | --- | --- |
-| [(constructor)()](./kibana-plugin-plugins-data-server.sessionservice._constructor_.md) | | Constructs a new instance of the SessionService
class |
-
-## Methods
-
-| Method | Modifiers | Description |
-| --- | --- | --- |
-| [asScopedProvider(core)](./kibana-plugin-plugins-data-server.sessionservice.asscopedprovider.md) | | |
-| [search(strategy, args)](./kibana-plugin-plugins-data-server.sessionservice.search.md) | | |
-
diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.search.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.search.md
deleted file mode 100644
index 8f8620a6ed5ee..0000000000000
--- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.sessionservice.search.md
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-[Home](./index.md) > [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) > [SessionService](./kibana-plugin-plugins-data-server.sessionservice.md) > [search](./kibana-plugin-plugins-data-server.sessionservice.search.md)
-
-## SessionService.search() method
-
-Signature:
-
-```typescript
-search(strategy: ISearchStrategy, ...args: Parameters['search']>): import("rxjs").Observable;
-```
-
-## Parameters
-
-| Parameter | Type | Description |
-| --- | --- | --- |
-| strategy | ISearchStrategy<Request, Response>
| |
-| args | Parameters<ISearchStrategy<Request, Response>['search']>
| |
-
-Returns:
-
-`import("rxjs").Observable`
-
diff --git a/examples/search_examples/server/plugin.ts b/examples/search_examples/server/plugin.ts
index e7ee311c8d652..595af844b0997 100644
--- a/examples/search_examples/server/plugin.ts
+++ b/examples/search_examples/server/plugin.ts
@@ -12,10 +12,9 @@ import type {
CoreStart,
Plugin,
Logger,
- RequestHandlerContext,
} from 'src/core/server';
-import type { DataApiRequestHandlerContext } from 'src/plugins/data/server';
+import type { DataRequestHandlerContext } from 'src/plugins/data/server';
import {
SearchExamplesPluginSetup,
@@ -45,9 +44,7 @@ export class SearchExamplesPlugin
deps: SearchExamplesPluginSetupDeps
) {
this.logger.debug('search_examples: Setup');
- const router = core.http.createRouter<
- RequestHandlerContext & { search: DataApiRequestHandlerContext }
- >();
+ const router = core.http.createRouter();
core.getStartServices().then(([_, depsStart]) => {
const myStrategy = mySearchStrategyProvider(depsStart.data);
diff --git a/examples/search_examples/server/routes/register_routes.ts b/examples/search_examples/server/routes/register_routes.ts
index d7a18509b9a79..1159864bed31a 100644
--- a/examples/search_examples/server/routes/register_routes.ts
+++ b/examples/search_examples/server/routes/register_routes.ts
@@ -6,12 +6,10 @@
* Public License, v 1.
*/
-import type { IRouter, RequestHandlerContext } from 'kibana/server';
-import { DataApiRequestHandlerContext } from 'src/plugins/data/server';
+import type { IRouter } from 'kibana/server';
+import { DataRequestHandlerContext } from 'src/plugins/data/server';
import { registerServerSearchRoute } from './server_search_route';
-export function registerRoutes(
- router: IRouter
-) {
+export function registerRoutes(router: IRouter) {
registerServerSearchRoute(router);
}
diff --git a/examples/search_examples/server/routes/server_search_route.ts b/examples/search_examples/server/routes/server_search_route.ts
index 99a1aba99d8ec..b4805a8de0d3c 100644
--- a/examples/search_examples/server/routes/server_search_route.ts
+++ b/examples/search_examples/server/routes/server_search_route.ts
@@ -9,13 +9,11 @@
import { IEsSearchRequest } from 'src/plugins/data/server';
import { schema } from '@kbn/config-schema';
import { IEsSearchResponse } from 'src/plugins/data/common';
-import type { DataApiRequestHandlerContext } from 'src/plugins/data/server';
-import type { IRouter, RequestHandlerContext } from 'src/core/server';
+import type { DataRequestHandlerContext } from 'src/plugins/data/server';
+import type { IRouter } from 'src/core/server';
import { SERVER_SEARCH_ROUTE_PATH } from '../../common';
-export function registerServerSearchRoute(
- router: IRouter
-) {
+export function registerServerSearchRoute(router: IRouter) {
router.get(
{
path: SERVER_SEARCH_ROUTE_PATH,
diff --git a/src/plugins/data/public/search/session/mocks.ts b/src/plugins/data/public/search/session/mocks.ts
index 679898e3e51dd..66cc8cd86f2b6 100644
--- a/src/plugins/data/public/search/session/mocks.ts
+++ b/src/plugins/data/public/search/session/mocks.ts
@@ -17,6 +17,7 @@ export function getSessionsClientMock(): jest.Mocked {
create: jest.fn(),
find: jest.fn(),
update: jest.fn(),
+ extend: jest.fn(),
delete: jest.fn(),
};
}
diff --git a/src/plugins/data/public/search/session/sessions_client.ts b/src/plugins/data/public/search/session/sessions_client.ts
index 5b0ba51c2f344..91db4e4fb9f1d 100644
--- a/src/plugins/data/public/search/session/sessions_client.ts
+++ b/src/plugins/data/public/search/session/sessions_client.ts
@@ -68,6 +68,12 @@ export class SessionsClient {
});
}
+ public extend(sessionId: string, keepAlive: string): Promise {
+ return this.http!.post(`/internal/session/${encodeURIComponent(sessionId)}/_extend`, {
+ body: JSON.stringify({ keepAlive }),
+ });
+ }
+
public delete(sessionId: string): Promise {
return this.http!.delete(`/internal/session/${encodeURIComponent(sessionId)}`);
}
diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts
index 8853f1fc34f9f..6e8bef49c6ad5 100644
--- a/src/plugins/data/server/index.ts
+++ b/src/plugins/data/server/index.ts
@@ -229,10 +229,9 @@ export {
searchUsageObserver,
shimAbortSignal,
SearchUsage,
- SessionService,
- ISessionService,
- IScopedSessionService,
- DataApiRequestHandlerContext,
+ SearchSessionService,
+ ISearchSessionService,
+ SearchRequestHandlerContext,
DataRequestHandlerContext,
} from './search';
diff --git a/src/plugins/data/server/mocks.ts b/src/plugins/data/server/mocks.ts
index 6d8e085554760..933e831b8c029 100644
--- a/src/plugins/data/server/mocks.ts
+++ b/src/plugins/data/server/mocks.ts
@@ -6,9 +6,14 @@
* Public License, v 1.
*/
-import { createSearchSetupMock, createSearchStartMock } from './search/mocks';
+import {
+ createSearchSetupMock,
+ createSearchStartMock,
+ createSearchRequestHandlerContext,
+} from './search/mocks';
import { createFieldFormatsSetupMock, createFieldFormatsStartMock } from './field_formats/mocks';
import { createIndexPatternsStartMock } from './index_patterns/mocks';
+import { DataRequestHandlerContext } from './search';
function createSetupContract() {
return {
@@ -25,7 +30,14 @@ function createStartContract() {
};
}
+function createRequestHandlerContext() {
+ return ({
+ search: createSearchRequestHandlerContext(),
+ } as unknown) as jest.Mocked;
+}
+
export const dataPluginMock = {
createSetupContract,
createStartContract,
+ createRequestHandlerContext,
};
diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts
index 2d2c546ffa4cf..63917ebc0fbab 100644
--- a/src/plugins/data/server/search/mocks.ts
+++ b/src/plugins/data/server/search/mocks.ts
@@ -10,6 +10,8 @@ import { ISearchSetup, ISearchStart } from './types';
import { searchAggsSetupMock, searchAggsStartMock } from './aggs/mocks';
import { searchSourceMock } from './search_source/mocks';
+export { createSearchSessionsClientMock } from './session/mocks';
+
export function createSearchSetupMock(): jest.Mocked {
return {
aggs: searchAggsSetupMock(),
@@ -22,10 +24,21 @@ export function createSearchStartMock(): jest.Mocked {
return {
aggs: searchAggsStartMock(),
getSearchStrategy: jest.fn(),
- asScoped: jest.fn().mockReturnValue({
- search: jest.fn(),
- cancel: jest.fn(),
- }),
+ asScoped: jest.fn().mockReturnValue(createSearchRequestHandlerContext()),
searchSource: searchSourceMock.createStartContract(),
};
}
+
+export function createSearchRequestHandlerContext() {
+ return {
+ search: jest.fn(),
+ cancel: jest.fn(),
+ extend: jest.fn(),
+ saveSession: jest.fn(),
+ getSession: jest.fn(),
+ findSessions: jest.fn(),
+ updateSession: jest.fn(),
+ extendSession: jest.fn(),
+ cancelSession: jest.fn(),
+ };
+}
diff --git a/src/plugins/data/server/search/routes/bsearch.ts b/src/plugins/data/server/search/routes/bsearch.ts
index ba96726b787c0..58424939fcd44 100644
--- a/src/plugins/data/server/search/routes/bsearch.ts
+++ b/src/plugins/data/server/search/routes/bsearch.ts
@@ -7,21 +7,17 @@
*/
import { catchError, first } from 'rxjs/operators';
-import { CoreStart, KibanaRequest } from 'src/core/server';
import { BfetchServerSetup } from 'src/plugins/bfetch/server';
import {
IKibanaSearchRequest,
IKibanaSearchResponse,
- ISearchClient,
ISearchOptions,
} from '../../../common/search';
-
-type GetScopedProider = (coreStart: CoreStart) => (request: KibanaRequest) => ISearchClient;
+import { ISearchStart } from '../types';
export function registerBsearchRoute(
bfetch: BfetchServerSetup,
- coreStartPromise: Promise<[CoreStart, {}, {}]>,
- getScopedProvider: GetScopedProider
+ getScoped: ISearchStart['asScoped']
): void {
bfetch.addBatchProcessingRoute<
{ request: IKibanaSearchRequest; options?: ISearchOptions },
@@ -33,8 +29,7 @@ export function registerBsearchRoute(
* @throws `KibanaServerError`
*/
onBatchItem: async ({ request: requestData, options }) => {
- const coreStart = await coreStartPromise;
- const search = getScopedProvider(coreStart[0])(request);
+ const search = getScoped(request);
return search
.search(requestData, options)
.pipe(
diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts
index e9f0edbd4d6c4..34aefe33e4402 100644
--- a/src/plugins/data/server/search/search_service.ts
+++ b/src/plugins/data/server/search/search_service.ts
@@ -6,8 +6,9 @@
* Public License, v 1.
*/
-import { BehaviorSubject, Observable, throwError } from 'rxjs';
+import { BehaviorSubject, from, Observable, throwError } from 'rxjs';
import { pick } from 'lodash';
+import moment from 'moment';
import {
CoreSetup,
CoreStart,
@@ -18,10 +19,11 @@ import {
SharedGlobalConfig,
StartServicesAccessor,
} from 'src/core/server';
-import { first } from 'rxjs/operators';
+import { first, switchMap } from 'rxjs/operators';
import { BfetchServerSetup } from 'src/plugins/bfetch/server';
import { ExpressionsServerSetup } from 'src/plugins/expressions/server';
import type {
+ IScopedSearchClient,
ISearchSetup,
ISearchStart,
ISearchStrategy,
@@ -46,7 +48,6 @@ import {
IEsSearchResponse,
IKibanaSearchRequest,
IKibanaSearchResponse,
- ISearchClient,
ISearchOptions,
kibana,
kibanaContext,
@@ -62,8 +63,9 @@ import {
} from '../../common/search/aggs/buckets/shard_delay';
import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';
import { ConfigSchema } from '../../config';
-import { IScopedSessionService, ISessionService, SessionService } from './session';
+import { ISearchSessionService, SearchSessionService } from './session';
import { KbnServerError } from '../../../kibana_utils/server';
+import { tapFirst } from '../../common';
import { registerBsearchRoute } from './routes/bsearch';
type StrategyMap = Record>;
@@ -92,14 +94,14 @@ export class SearchService implements Plugin {
private readonly searchSourceService = new SearchSourceService();
private defaultSearchStrategyName: string = ES_SEARCH_STRATEGY;
private searchStrategies: StrategyMap = {};
- private sessionService: ISessionService;
- private coreStart?: CoreStart;
+ private sessionService: ISearchSessionService;
+ private asScoped!: ISearchStart['asScoped'];
constructor(
private initializerContext: PluginInitializerContext,
private readonly logger: Logger
) {
- this.sessionService = new SessionService();
+ this.sessionService = new SearchSessionService();
}
public setup(
@@ -116,16 +118,10 @@ export class SearchService implements Plugin {
registerSearchRoute(router);
registerMsearchRoute(router, routeDependencies);
- core.getStartServices().then(([coreStart]) => {
- this.coreStart = coreStart;
- });
-
core.http.registerRouteHandlerContext(
'search',
async (context, request) => {
- const search = this.asScopedProvider(this.coreStart!)(request);
- const session = this.sessionService.asScopedProvider(this.coreStart!)(request);
- return { ...search, session };
+ return this.asScoped(request);
}
);
@@ -138,7 +134,7 @@ export class SearchService implements Plugin {
)
);
- registerBsearchRoute(bfetch, core.getStartServices(), this.asScopedProvider);
+ registerBsearchRoute(bfetch, (request: KibanaRequest) => this.asScoped(request));
core.savedObjects.registerType(searchTelemetry);
if (usageCollection) {
@@ -181,7 +177,7 @@ export class SearchService implements Plugin {
{ fieldFormats, indexPatterns }: SearchServiceStartDependencies
): ISearchStart {
const { elasticsearch, savedObjects, uiSettings } = core;
- const asScoped = this.asScopedProvider(core);
+ this.asScoped = this.asScopedProvider(core);
return {
aggs: this.aggsService.start({
fieldFormats,
@@ -189,7 +185,7 @@ export class SearchService implements Plugin {
indexPatterns,
}),
getSearchStrategy: this.getSearchStrategy,
- asScoped,
+ asScoped: this.asScoped,
searchSource: {
asScoped: async (request: KibanaRequest) => {
const esClient = elasticsearch.client.asScoped(request);
@@ -208,7 +204,7 @@ export class SearchService implements Plugin {
const searchSourceDependencies: SearchSourceDependencies = {
getConfig: (key: string): T => uiSettingsCache[key],
- search: asScoped(request).search,
+ search: this.asScoped(request).search,
onResponse: (req, res) => res,
legacy: {
callMsearch: getCallMsearch({
@@ -241,26 +237,54 @@ export class SearchService implements Plugin {
this.searchStrategies[name] = strategy;
};
- private search = <
+ private getSearchStrategy = <
SearchStrategyRequest extends IKibanaSearchRequest = IEsSearchRequest,
SearchStrategyResponse extends IKibanaSearchResponse = IEsSearchResponse
>(
- session: IScopedSessionService,
+ name: string = this.defaultSearchStrategyName
+ ): ISearchStrategy => {
+ this.logger.debug(`Get strategy ${name}`);
+ const strategy = this.searchStrategies[name];
+ if (!strategy) {
+ throw new KbnServerError(`Search strategy ${name} not found`, 404);
+ }
+ return strategy;
+ };
+
+ private search = <
+ SearchStrategyRequest extends IKibanaSearchRequest,
+ SearchStrategyResponse extends IKibanaSearchResponse
+ >(
+ deps: SearchStrategyDependencies,
request: SearchStrategyRequest,
- options: ISearchOptions,
- deps: SearchStrategyDependencies
+ options: ISearchOptions
) => {
try {
const strategy = this.getSearchStrategy(
options.strategy
);
- return session.search(strategy, request, options, deps);
+
+ const getSearchRequest = async () =>
+ !options.sessionId || !options.isRestore || request.id
+ ? request
+ : {
+ ...request,
+ id: await deps.searchSessionsClient.getId(request, options),
+ };
+
+ return from(getSearchRequest()).pipe(
+ switchMap((searchRequest) => strategy.search(searchRequest, options, deps)),
+ tapFirst((response) => {
+ if (request.id || !options.sessionId || !response.id || options.isRestore) return;
+ deps.searchSessionsClient.trackId(request, response.id, options);
+ })
+ );
} catch (e) {
return throwError(e);
}
};
- private cancel = (id: string, options: ISearchOptions, deps: SearchStrategyDependencies) => {
+ private cancel = (deps: SearchStrategyDependencies, id: string, options: ISearchOptions = {}) => {
const strategy = this.getSearchStrategy(options.strategy);
if (!strategy.cancel) {
throw new KbnServerError(
@@ -272,10 +296,10 @@ export class SearchService implements Plugin {
};
private extend = (
+ deps: SearchStrategyDependencies,
id: string,
keepAlive: string,
- options: ISearchOptions,
- deps: SearchStrategyDependencies
+ options: ISearchOptions = {}
) => {
const strategy = this.getSearchStrategy(options.strategy);
if (!strategy.extend) {
@@ -284,36 +308,71 @@ export class SearchService implements Plugin {
return strategy.extend(id, keepAlive, options, deps);
};
- private getSearchStrategy = <
- SearchStrategyRequest extends IKibanaSearchRequest = IEsSearchRequest,
- SearchStrategyResponse extends IKibanaSearchResponse = IEsSearchResponse
- >(
- name: string = this.defaultSearchStrategyName
- ): ISearchStrategy => {
- this.logger.debug(`Get strategy ${name}`);
- const strategy = this.searchStrategies[name];
- if (!strategy) {
- throw new KbnServerError(`Search strategy ${name} not found`, 404);
+ private cancelSession = async (deps: SearchStrategyDependencies, sessionId: string) => {
+ const searchIdMapping = await deps.searchSessionsClient.getSearchIdMapping(sessionId);
+ const response = await deps.searchSessionsClient.cancel(sessionId);
+
+ for (const [searchId, strategyName] of searchIdMapping.entries()) {
+ const searchOptions = {
+ sessionId,
+ strategy: strategyName,
+ isStored: true,
+ };
+ this.cancel(deps, searchId, searchOptions);
}
- return strategy;
+
+ return response;
+ };
+
+ private extendSession = async (
+ deps: SearchStrategyDependencies,
+ sessionId: string,
+ expires: Date
+ ) => {
+ const searchIdMapping = await deps.searchSessionsClient.getSearchIdMapping(sessionId);
+ const keepAlive = `${moment(expires).diff(moment())}ms`;
+
+ for (const [searchId, strategyName] of searchIdMapping.entries()) {
+ const searchOptions = {
+ sessionId,
+ strategy: strategyName,
+ isStored: true,
+ };
+ await this.extend(deps, searchId, keepAlive, searchOptions);
+ }
+
+ return deps.searchSessionsClient.extend(sessionId, expires);
};
private asScopedProvider = (core: CoreStart) => {
const { elasticsearch, savedObjects, uiSettings } = core;
const getSessionAsScoped = this.sessionService.asScopedProvider(core);
- return (request: KibanaRequest): ISearchClient => {
- const scopedSession = getSessionAsScoped(request);
+ return (request: KibanaRequest): IScopedSearchClient => {
const savedObjectsClient = savedObjects.getScopedClient(request);
+ const searchSessionsClient = getSessionAsScoped(request);
const deps = {
+ searchSessionsClient,
savedObjectsClient,
esClient: elasticsearch.client.asScoped(request),
uiSettingsClient: uiSettings.asScopedToClient(savedObjectsClient),
};
return {
- search: (searchRequest, options = {}) =>
- this.search(scopedSession, searchRequest, options, deps),
- cancel: (id, options = {}) => this.cancel(id, options, deps),
- extend: (id, keepAlive, options = {}) => this.extend(id, keepAlive, options, deps),
+ search: <
+ SearchStrategyRequest extends IKibanaSearchRequest = IEsSearchRequest,
+ SearchStrategyResponse extends IKibanaSearchResponse = IEsSearchResponse
+ >(
+ searchRequest: SearchStrategyRequest,
+ options: ISearchOptions = {}
+ ) =>
+ this.search(deps, searchRequest, options),
+ cancel: this.cancel.bind(this, deps),
+ extend: this.extend.bind(this, deps),
+ saveSession: searchSessionsClient.save,
+ getSession: searchSessionsClient.get,
+ findSessions: searchSessionsClient.find,
+ updateSession: searchSessionsClient.update,
+ extendSession: this.extendSession.bind(this, deps),
+ cancelSession: this.cancelSession.bind(this, deps),
};
};
};
diff --git a/src/plugins/data/server/search/session/mocks.ts b/src/plugins/data/server/search/session/mocks.ts
new file mode 100644
index 0000000000000..f75ba6fcc6620
--- /dev/null
+++ b/src/plugins/data/server/search/session/mocks.ts
@@ -0,0 +1,25 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { IScopedSearchSessionsClient } from './types';
+
+export function createSearchSessionsClientMock(): jest.Mocked<
+ IScopedSearchSessionsClient
+> {
+ return {
+ getId: jest.fn(),
+ trackId: jest.fn(),
+ getSearchIdMapping: jest.fn(),
+ save: jest.fn(),
+ get: jest.fn(),
+ find: jest.fn(),
+ update: jest.fn(),
+ cancel: jest.fn(),
+ extend: jest.fn(),
+ };
+}
diff --git a/src/plugins/data/server/search/session/session_service.test.ts b/src/plugins/data/server/search/session/session_service.test.ts
deleted file mode 100644
index 2b981e3050947..0000000000000
--- a/src/plugins/data/server/search/session/session_service.test.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License
- * and the Server Side Public License, v 1; you may not use this file except in
- * compliance with, at your election, the Elastic License or the Server Side
- * Public License, v 1.
- */
-
-import { of } from 'rxjs';
-import { SearchStrategyDependencies } from '../types';
-import { SessionService } from './session_service';
-
-describe('SessionService', () => {
- it('search invokes `strategy.search`', async () => {
- const service = new SessionService();
- const mockSearch = jest.fn().mockReturnValue(of({}));
- const mockStrategy = { search: mockSearch };
- const mockRequest = { id: 'bar' };
- const mockOptions = { sessionId: '1234' };
- const mockDeps = { savedObjectsClient: {} } as SearchStrategyDependencies;
-
- await service.search(mockStrategy, mockRequest, mockOptions, mockDeps);
-
- expect(mockSearch).toHaveBeenCalled();
- expect(mockSearch).toHaveBeenCalledWith(mockRequest, mockOptions, mockDeps);
- });
-});
diff --git a/src/plugins/data/server/search/session/session_service.ts b/src/plugins/data/server/search/session/session_service.ts
index d6b7a582fe764..dc4f19f126882 100644
--- a/src/plugins/data/server/search/session/session_service.ts
+++ b/src/plugins/data/server/search/session/session_service.ts
@@ -6,27 +6,41 @@
* Public License, v 1.
*/
-import { CoreStart, KibanaRequest } from 'kibana/server';
-import { IKibanaSearchRequest, IKibanaSearchResponse } from '../../../common';
-import { ISearchStrategy } from '../types';
-import { ISessionService } from './types';
+import { ISearchSessionService } from './types';
/**
- * The OSS session service. See data_enhanced in X-Pack for the search session service.
+ * The OSS session service, which leaves most search session-related logic unimplemented.
+ * @see x-pack/plugins/data_enhanced/server/search/session/session_service.ts
+ * @internal
*/
-export class SessionService implements ISessionService {
+export class SearchSessionService implements ISearchSessionService {
constructor() {}
- public search(
- strategy: ISearchStrategy,
- ...args: Parameters['search']>
- ) {
- return strategy.search(...args);
- }
-
- public asScopedProvider(core: CoreStart) {
- return (request: KibanaRequest) => ({
- search: this.search,
+ public asScopedProvider() {
+ return () => ({
+ getId: () => {
+ throw new Error('getId not implemented in OSS search session service');
+ },
+ trackId: async () => {},
+ getSearchIdMapping: async () => new Map(),
+ save: async () => {
+ throw new Error('save not implemented in OSS search session service');
+ },
+ get: async () => {
+ throw new Error('get not implemented in OSS search session service');
+ },
+ find: async () => {
+ throw new Error('find not implemented in OSS search session service');
+ },
+ update: async () => {
+ throw new Error('update not implemented in OSS search session service');
+ },
+ extend: async () => {
+ throw new Error('extend not implemented in OSS search session service');
+ },
+ cancel: async () => {
+ throw new Error('cancel not implemented in OSS search session service');
+ },
});
}
}
diff --git a/src/plugins/data/server/search/session/types.ts b/src/plugins/data/server/search/session/types.ts
index 97ef7aa8e61c3..3c074955a108e 100644
--- a/src/plugins/data/server/search/session/types.ts
+++ b/src/plugins/data/server/search/session/types.ts
@@ -6,19 +6,32 @@
* Public License, v 1.
*/
-import { Observable } from 'rxjs';
-import { CoreStart, KibanaRequest } from 'kibana/server';
-import { ISearchStrategy } from '../types';
-import { IKibanaSearchRequest, IKibanaSearchResponse } from '../../../common/search';
+import {
+ CoreStart,
+ KibanaRequest,
+ SavedObject,
+ SavedObjectsFindOptions,
+ SavedObjectsFindResponse,
+ SavedObjectsUpdateResponse,
+} from 'kibana/server';
+import { IKibanaSearchRequest, ISearchOptions } from '../../../common/search';
-export interface IScopedSessionService {
- search: (
- strategy: ISearchStrategy,
- ...args: Parameters['search']>
- ) => Observable;
- [prop: string]: any;
+export interface IScopedSearchSessionsClient {
+ getId: (request: IKibanaSearchRequest, options: ISearchOptions) => Promise;
+ trackId: (
+ request: IKibanaSearchRequest,
+ searchId: string,
+ options: ISearchOptions
+ ) => Promise;
+ getSearchIdMapping: (sessionId: string) => Promise