Skip to content

Commit 4a69b51

Browse files
committed
[Search] Re-add support for aborting when a connection is closed
1 parent b5faf41 commit 4a69b51

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/plugins/data/server/search/es_search/es_search_strategy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export const esSearchStrategyProvider = (
4747
};
4848

4949
try {
50-
const esResponse = (await context.core.elasticsearch.client.asCurrentUser.search(
51-
params
52-
)) as ApiResponse<SearchResponse<any>>;
53-
const rawResponse = esResponse.body;
50+
// Temporary workaround until https://github.com/elastic/elasticsearch-js/issues/1297
51+
const promise = context.core.elasticsearch.client.asCurrentUser.search(params);
52+
if (options?.signal) options.signal.addEventListener('abort', () => promise.abort());
53+
const { body: rawResponse } = (await promise) as ApiResponse<SearchResponse<any>>;
5454

5555
if (usage) usage.trackSuccess(rawResponse.took);
5656

x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ async function asyncSearch(
112112
});
113113

114114
// TODO: replace with async endpoints once https://github.com/elastic/elasticsearch-js/issues/1280 is resolved
115-
const esResponse = await client.transport.request({
115+
const promise = client.transport.request({
116116
method,
117117
path,
118118
body,
119119
querystring,
120120
});
121121

122+
// Temporary workaround until https://github.com/elastic/elasticsearch-js/issues/1297
123+
if (options?.signal) options.signal.addEventListener('abort', () => promise.abort());
124+
const esResponse = await promise;
122125
const { id, response, is_partial: isPartial, is_running: isRunning } = esResponse.body;
126+
123127
return {
124128
id,
125129
isPartial,
@@ -139,14 +143,18 @@ async function rollupSearch(
139143
const path = encodeURI(`/${index}/_rollup_search`);
140144
const querystring = toSnakeCase(params);
141145

142-
const esResponse = await client.transport.request({
146+
const promise = client.transport.request({
143147
method,
144148
path,
145149
body,
146150
querystring,
147151
});
148152

153+
// Temporary workaround until https://github.com/elastic/elasticsearch-js/issues/1297
154+
if (options?.signal) options.signal.addEventListener('abort', () => promise.abort());
155+
const esResponse = await promise;
149156
const response = esResponse.body as SearchResponse<any>;
157+
150158
return {
151159
rawResponse: shimHitsTotal(response),
152160
...getTotalLoaded(response._shards),

0 commit comments

Comments
 (0)