From 82f915b8851829ef6fa1132bd4ed671568c5f0dd Mon Sep 17 00:00:00 2001 From: Lukas Olson Date: Tue, 3 Apr 2018 14:19:27 -0700 Subject: [PATCH] Fix value suggestions API when the field and/or docs are not present (#17507) --- .../routes/api/suggestions/register_value_suggestions.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js b/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js index 2948a0ed0755..1083983e2f6e 100644 --- a/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js +++ b/src/core_plugins/kibana/server/routes/api/suggestions/register_value_suggestions.js @@ -1,3 +1,4 @@ +import { get, map } from 'lodash'; import handleESError from '../../../lib/handle_es_error'; export function registerValueSuggestions(server) { @@ -11,7 +12,8 @@ export function registerValueSuggestions(server) { const body = getBody({ field, query }); try { const response = await callWithRequest(req, 'search', { index, body }); - const suggestions = response.aggregations.suggestions.buckets.map(bucket => bucket.key); + const buckets = get(response, 'aggregations.suggestions.buckets') || []; + const suggestions = map(buckets, 'key'); reply(suggestions); } catch (error) { reply(handleESError(error));