Skip to content

Commit

Permalink
Patch for rollup visualizations not rendering (#22784)
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang authored and cjcenizal committed Oct 4, 2018
1 parent fff59f7 commit d2b2184
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion x-pack/plugins/rollup/public/search/rollup_search_strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ function serializeFetchParams(searchRequestsWithFetchParams) {
}));
}

// Rollup search always returns 0 hits, but visualizations expect search responses
// to return hits > 0, otherwise they do not render. We fake the number of hits here
// by counting the number of aggregation buckets/values returned by rollup search.
function shimHitsInFetchResponse(response) {
return response.map(result => {
const buckets = result.aggregations ? Object.keys(result.aggregations).reduce((allBuckets, agg) => {
return allBuckets.concat(result.aggregations[agg].buckets || [result.aggregations[agg].value] || []);
}, []) : [];
return buckets && buckets.length ? {
...result,
hits: {
...result.hits,
total: buckets.length
}
} : result;
});
}

export const rollupSearchStrategy = {
id: 'rollup',

Expand All @@ -106,7 +124,7 @@ export const rollupSearchStrategy = {
return {
searching: new Promise((resolve, reject) => {
fetching.then(result => {
resolve(result);
resolve(shimHitsInFetchResponse(result));
}).catch(error => {
const {
body: { statusText, error: title, message },
Expand Down

0 comments on commit d2b2184

Please sign in to comment.