Skip to content

Commit

Permalink
Abort server-side connection to ES
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Nov 27, 2019
1 parent 9916cdf commit 24cee09
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { get, map } from 'lodash';
import { abortableRequestHandler } from '../../../../../elasticsearch/lib/abortable_request_handler';

export function registerValueSuggestions(server) {
const serverConfig = server.config();
Expand All @@ -26,7 +27,7 @@ export function registerValueSuggestions(server) {
server.route({
path: '/api/kibana/suggestions/values/{index}',
method: ['POST'],
handler: async function (req) {
handler: abortableRequestHandler(async function (signal, req) {
const { index } = req.params;
const { field: fieldName, query, boolFilter } = req.payload;
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
Expand All @@ -46,7 +47,7 @@ export function registerValueSuggestions(server) {
);

try {
const response = await callWithRequest(req, 'search', { index, body });
const response = await callWithRequest(req, 'search', { index, body }, { signal });
const buckets = get(response, 'aggregations.suggestions.buckets')
|| get(response, 'aggregations.nestedSuggestions.suggestions.buckets')
|| [];
Expand All @@ -55,7 +56,7 @@ export function registerValueSuggestions(server) {
} catch (error) {
throw server.plugins.elasticsearch.handleESError(error);
}
},
}),
});
}

Expand Down

0 comments on commit 24cee09

Please sign in to comment.