From 0e44fc88346576d2fc78348c9389fb1d1c5b9b40 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 15 Jul 2021 09:03:54 -0400 Subject: [PATCH] [Search Sessions] fix saved object can be created even if courier:batchSearches is enabled (#105407) (#105733) Co-authored-by: Anton Dosov --- .../common/search/search_source/search_source.test.ts | 10 ++++++++++ .../data/common/search/search_source/search_source.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/plugins/data/common/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts index 7c0473077d182..90f5ff331b971 100644 --- a/src/plugins/data/common/search/search_source/search_source.test.ts +++ b/src/plugins/data/common/search/search_source/search_source.test.ts @@ -909,6 +909,16 @@ describe('SearchSource', () => { expect(callOptions.strategy).toBe(ES_SEARCH_STRATEGY); }); + test('should remove searchSessionId when forcing ES_SEARCH_STRATEGY', async () => { + searchSource = new SearchSource({ index: indexPattern }, searchSourceDependencies); + const options = { sessionId: 'test' }; + await searchSource.fetch$(options).toPromise(); + + const [, callOptions] = mockSearchMethod.mock.calls[0]; + expect(callOptions.strategy).toBe(ES_SEARCH_STRATEGY); + expect(callOptions.sessionId).toBeUndefined(); + }); + test('should not override strategy if set ', async () => { searchSource = new SearchSource({ index: indexPattern }, searchSourceDependencies); const options = { strategy: 'banana' }; diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index 19e80c7a487dc..e60e6fa00b270 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -287,6 +287,8 @@ export class SearchSource { // This still uses bfetch for batching. if (!options?.strategy && syncSearchByDefault) { options.strategy = ES_SEARCH_STRATEGY; + // `ES_SEARCH_STRATEGY` doesn't support search sessions, hence remove sessionId + options.sessionId = undefined; } const s$ = defer(() => this.requestIsStarting(options)).pipe(