Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Search] Use async es client endpoints #76872

Merged
merged 5 commits into from
Sep 8, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ async function asyncSearch(

// If we have an ID, then just poll for that ID, otherwise send the entire request body
const { body = undefined, index = undefined, ...queryParams } = request.id ? {} : params;

const method = request.id ? 'GET' : 'POST';
const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`);

// Only report partial results every 64 shards; this should be reduced when we actually display partial results
const batchedReduceSize = request.id ? undefined : 64;

Expand All @@ -104,19 +100,23 @@ async function asyncSearch(
keepAlive: '1m', // Extend the TTL for this search request by one minute
};

const querystring = toSnakeCase({
const queryOptions = toSnakeCase({
...asyncOptions,
...(batchedReduceSize && { batchedReduceSize }),
...queryParams,
});

// TODO: replace with async endpoints once https://github.com/elastic/elasticsearch-js/issues/1280 is resolved
const esResponse = await client.transport.request({
method,
path,
body,
querystring,
});
let esResponse;
if (!request.id) {
esResponse = await client.asyncSearch.submit({
body,
...queryOptions,
});
} else {
esResponse = await client.asyncSearch.get({
id: request.id,
});
}

const { id, response, is_partial: isPartial, is_running: isRunning } = esResponse.body;
return {
Expand Down