Skip to content

Commit

Permalink
adjust request params
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Jul 20, 2021
1 parent d75bdff commit a5bea2a
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ export async function getDefaultAsyncSubmitParams(
| 'keep_on_completion'
>
> {
const useSearchSessions = searchSessionsConfig?.enabled && !!options.sessionId;

// TODO: searchSessionsConfig could be "null" if we are running without x-pack which happens only in tests.
// This can be cleaned up when we completely stop separating basic and oss
const keepAlive = searchSessionsConfig?.enabled
? `${searchSessionsConfig.defaultExpiration.asMilliseconds()}ms`
const keepAlive = useSearchSessions
? `${searchSessionsConfig!.defaultExpiration.asMilliseconds()}ms`
: '1m';

// Always return an ID for search sessions, even if the request completes quickly
const keepOnCompletion = searchSessionsConfig?.enabled && !!options.sessionId;
return {
// TODO: adjust for partial results
batched_reduce_size: 64,
keep_on_completion: keepOnCompletion,
...getDefaultAsyncGetParams(searchSessionsConfig, options),
// Wait up to 100ms for the response to return
wait_for_completion_timeout: '100ms',
// If search sessions are used, store and get an async ID even for short running requests.
keep_on_completion: useSearchSessions,
// The initial keepalive is as defined in defaultExpiration if search sessions are used or 1m otherwise.
keep_alive: keepAlive,
...(await getIgnoreThrottled(uiSettingsClient)),
...(await getDefaultSearchParams(uiSettingsClient)),
...(options.sessionId ? { keep_alive: keepAlive } : {}),
// If search sessions are used, set the initial expiration time.
};
}

Expand All @@ -71,13 +76,17 @@ export function getDefaultAsyncGetParams(
searchSessionsConfig: SearchSessionsConfigSchema | null,
options: ISearchOptions
): Pick<AsyncSearchGet, 'keep_alive' | 'wait_for_completion_timeout'> {
const useSearchSessions = searchSessionsConfig?.enabled && !!options.sessionId;

return {
wait_for_completion_timeout: '100ms', // Wait up to 100ms for the response to return
...(searchSessionsConfig?.enabled && options.sessionId
? undefined
// Wait up to 100ms for the response to return
wait_for_completion_timeout: '100ms',
...(useSearchSessions
? // Don't change the expiration of search requests that are tracked in a search session
undefined
: {
keep_alive: '1m',
// We still need to do polling for searches not within the context of a search session or when search session disabled
keep_alive: '1m',
}),
};
}

0 comments on commit a5bea2a

Please sign in to comment.