From 1c822f6914f765634e2dcf31bc7a6380d45aaae4 Mon Sep 17 00:00:00 2001 From: Liza K Date: Mon, 7 Sep 2020 19:53:53 +0300 Subject: [PATCH] Common async options --- .../server/search/es_search_strategy.test.ts | 6 +++--- .../data_enhanced/server/search/es_search_strategy.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts index 46aa7074fc696..a287f72ca9161 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts @@ -91,9 +91,9 @@ describe('ES search strategy', () => { expect(mockGetCaller).toBeCalled(); const request = mockGetCaller.mock.calls[0][0]; - expect(request).toEqual({ - id: 'foo', - }); + expect(request.id).toEqual('foo'); + expect(request).toHaveProperty('wait_for_completion_timeout'); + expect(request).toHaveProperty('keep_alive'); }); it('calls the rollup API if the index is a rollup type', async () => { diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 81e1549118277..4ace1c4c5385b 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -84,13 +84,18 @@ async function asyncSearch( options?: ISearchOptions ): Promise { let esResponse; + + const asyncOptions = { + waitForCompletionTimeout: '100ms', // Wait up to 100ms for the response to return + keepAlive: '1m', // Extend the TTL for this search request by one minute + }; + // If we have an ID, then just poll for that ID, otherwise send the entire request body if (!request.id) { const submitOptions = toSnakeCase({ batchedReduceSize: 64, // Only report partial results every 64 shards; this should be reduced when we actually display partial results trackTotalHits: true, // Get the exact count of hits - waitForCompletionTimeout: '100ms', // Wait up to 100ms for the response to return - keepAlive: '1m', // Extend the TTL for this search request by one minute + ...asyncOptions, ...request.params, }); @@ -98,6 +103,7 @@ async function asyncSearch( } else { esResponse = await client.asyncSearch.get({ id: request.id, + ...toSnakeCase(asyncOptions), }); }