Skip to content

Commit

Permalink
Common async options
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Sep 7, 2020
1 parent 94f0786 commit 1c822f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
10 changes: 8 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 @@ -84,20 +84,26 @@ async function asyncSearch(
options?: ISearchOptions
): Promise<IEsSearchResponse> {
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,
});

esResponse = await client.asyncSearch.submit(submitOptions);
} else {
esResponse = await client.asyncSearch.get({
id: request.id,
...toSnakeCase(asyncOptions),
});
}

Expand Down

0 comments on commit 1c822f6

Please sign in to comment.