From 6db4e688d5ebb46818cc5d792d99bd75b06e45fa Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Thu, 15 Jul 2021 12:57:17 +0200 Subject: [PATCH] [Search Sessions] fix saved object can be created even if courier:batchSearches is enabled (#105407) --- .../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(