Skip to content

Commit

Permalink
resolves elastic#64132
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Apr 22, 2020
1 parent ffc8741 commit ba1dbbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ export const asyncSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_S

return search(request, options).pipe(
expand(response => {
// If the response indicates of an error, stop polling and complete the observable
if (!response || (response.is_partial && !response.is_running)) {
return throwError(new AbortError());
}

// If the response indicates it is complete, stop polling and complete the observable
if ((response.loaded ?? 0) >= (response.total ?? 0)) return EMPTY;
if (!response.is_partial && !response.is_running) return EMPTY;

id = response.id;

Expand Down
12 changes: 10 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 @@ -23,6 +23,8 @@ import { shimHitsTotal } from './shim_hits_total';

export interface AsyncSearchResponse<T> {
id: string;
is_partial: boolean;
is_running: boolean;
response: SearchResponse<T>;
}

Expand Down Expand Up @@ -71,13 +73,19 @@ async function asyncSearch(
// Wait up to 1s for the response to return
const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...queryParams });

const { response, id } = (await caller(
const { id, response, is_partial, is_running } = (await caller(
'transport.request',
{ method, path, body, query },
options
)) as AsyncSearchResponse<any>;

return { id, rawResponse: shimHitsTotal(response), ...getTotalLoaded(response._shards) };
return {
id,
is_partial,
is_running,
rawResponse: shimHitsTotal(response),
...getTotalLoaded(response._shards),
};
}

async function rollupSearch(
Expand Down

0 comments on commit ba1dbbf

Please sign in to comment.