Skip to content

Commit

Permalink
[7.9] [Search] Set keep_alive parameter in async search (#73712) (#74101
Browse files Browse the repository at this point in the history
)

* [Search] Set keep_alive parameter in async search (#73712)

* [Search] Set keep_alive parameter in async search

* Revert accidental change

* Add batched_reduce_size

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

* Fix test

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
lukasolson and elasticmachine authored Aug 3, 2020
1 parent 788bc5b commit d552bfe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,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$);

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');
});
});
11 changes: 9 additions & 2 deletions x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,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', ...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',
Expand Down

0 comments on commit d552bfe

Please sign in to comment.