Skip to content

Commit

Permalink
Add retrieveResults parameter to get search request results instead o…
Browse files Browse the repository at this point in the history
…f status during polling
  • Loading branch information
lukasolson committed Jul 8, 2024
1 parent 8c4a265 commit d5791cf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/plugins/data/common/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ export interface ISearchOptions {
*/
isRestore?: boolean;

/**
* By default, when polling, we don't retrieve the results of the search request (until it is complete). (For async
* search, this is the difference between calling _async_search/{id} and _async_search/status/{id}.) setting this to
* `true` will request the search results, regardless of whether or not the search is complete.
*/
retrieveResults?: boolean;

/**
* Represents a meta-information about a Kibana entity intitating a saerch request.
*/
Expand Down Expand Up @@ -182,5 +189,6 @@ export type ISearchOptionsSerializable = Pick<
| 'isStored'
| 'isSearchStored'
| 'isRestore'
| 'retrieveResults'
| 'executionContext'
>;
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ export class SearchInterceptor {

if (combined.sessionId !== undefined) serializableOptions.sessionId = combined.sessionId;
if (combined.isRestore !== undefined) serializableOptions.isRestore = combined.isRestore;
if (combined.retrieveResults !== undefined)
serializableOptions.retrieveResults = combined.retrieveResults;
if (combined.legacyHitsTotal !== undefined)
serializableOptions.legacyHitsTotal = combined.legacyHitsTotal;
if (combined.strategy !== undefined) serializableOptions.strategy = combined.strategy;
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/data/server/search/routes/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function registerSearchRoute(router: DataPluginRouter): void {
sessionId: schema.maybe(schema.string()),
isStored: schema.maybe(schema.boolean()),
isRestore: schema.maybe(schema.boolean()),
retrieveResults: schema.maybe(schema.boolean()),
},
{ unknowns: 'allow' }
),
Expand All @@ -48,6 +49,7 @@ export function registerSearchRoute(router: DataPluginRouter): void {
sessionId,
isStored,
isRestore,
retrieveResults,
...searchRequest
} = request.body;
const { strategy, id } = request.params;
Expand All @@ -65,6 +67,7 @@ export function registerSearchRoute(router: DataPluginRouter): void {
sessionId,
isStored,
isRestore,
retrieveResults,
}
)
.pipe(first())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ export const enhancedEsSearchStrategyProvider = (
options: IAsyncSearchOptions,
{ esClient }: SearchStrategyDependencies
) {
// First, request the status of the async search, and return the status if incomplete
const status = await asyncSearchStatus({ id, ...request }, options, { esClient });
if (isRunningResponse(status)) return status;
if (!options.retrieveResults) {
// First, request the status of the async search, and return the status if incomplete
const status = await asyncSearchStatus({ id, ...request }, options, { esClient });
if (isRunningResponse(status)) return status;
}

// Then, if the search is complete, request & return the final results
const client = useInternalUser ? esClient.asInternalUser : esClient.asCurrentUser;
Expand Down

0 comments on commit d5791cf

Please sign in to comment.