From e1b2d2856ef5d7103aa6acaa7d813f2ce5a6dec7 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 29 Jul 2020 09:44:53 -0700 Subject: [PATCH 1/3] [Search] Set keep_alive parameter in async search --- .../server/search/es_search_strategy.test.ts | 15 +++++++++++++++ .../server/search/es_search_strategy.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) 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 faa4f2ee499e5..4fd1e889ba1a5 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 @@ -113,4 +113,19 @@ describe('ES search strategy', () => { expect(method).toBe('POST'); expect(path).toBe('/foo-%E7%A8%8B/_rollup_search'); }); + + it('sets wait_for_completion_timeout and keep_alive in the request', async () => { + mockApiCaller.mockResolvedValueOnce(mockAsyncResponse); + + const params = { index: 'foo-*', body: {} }; + const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger); + + await esSearch.search((mockContext as unknown) as RequestHandlerContext, { params }); + + expect(mockApiCaller).toBeCalled(); + expect(mockApiCaller.mock.calls[0][0]).toBe('transport.request'); + const { query } = mockApiCaller.mock.calls[0][1]; + expect(query).toHaveProperty('wait_for_completion_timeout'); + expect(query).toHaveProperty('keep_alive'); + }); }); 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 358335a2a4d60..fca6e0394e9ef 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 @@ -81,7 +81,7 @@ async function asyncSearch( const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`); // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '100ms', ...queryParams }); + const query = toSnakeCase({ waitForCompletionTimeout: '1ms', keepAlive: '1m', ...queryParams }); const { id, response, is_partial, is_running } = (await caller( 'transport.request', From f03cb0671539cf38f50efa4f81fd6b145b86f69a Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Wed, 29 Jul 2020 11:25:11 -0700 Subject: [PATCH 2/3] Revert accidental change --- .../plugins/data_enhanced/server/search/es_search_strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fca6e0394e9ef..5599830a8ea7a 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 @@ -81,7 +81,7 @@ async function asyncSearch( const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`); // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '1ms', keepAlive: '1m', ...queryParams }); + const query = toSnakeCase({ waitForCompletionTimeout: '100ms', keepAlive: '1m', ...queryParams }); const { id, response, is_partial, is_running } = (await caller( 'transport.request', From a9496c88068d2663349fb909fdb4b358348d0945 Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Thu, 30 Jul 2020 16:03:26 -0700 Subject: [PATCH 3/3] Add batched_reduce_size --- .../data_enhanced/server/search/es_search_strategy.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 5599830a8ea7a..1f7b6a5f9aace 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 @@ -80,8 +80,15 @@ async function asyncSearch( const method = request.id ? 'GET' : 'POST'; const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`); - // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '100ms', keepAlive: '1m', ...queryParams }); + // Only report partial results every 64 shards; this should be reduced when we actually display partial results + const batchedReduceSize = request.id ? undefined : 64; + + const query = toSnakeCase({ + waitForCompletionTimeout: '100ms', // Wait up to 100ms for the response to return + keepAlive: '1m', // Extend the TTL for this search request by one minute + ...(batchedReduceSize && { batchedReduceSize }), + ...queryParams, + }); const { id, response, is_partial, is_running } = (await caller( 'transport.request',