From b160700e6830002af3b6aa9dd5a17265144d2ee4 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Tue, 27 Aug 2013 14:53:23 -0700 Subject: [PATCH] adjusted the shared kbn.top_field_values() function to preserve field values, specifically so that arrays are not flattened to strings --- js/shared.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/js/shared.js b/js/shared.js index 94c09d3f30d87..7912d89f74dc3 100644 --- a/js/shared.js +++ b/js/shared.js @@ -72,10 +72,20 @@ }; kbn.top_field_values = function(docs,field,count) { - var counts = _.countBy(_.pluck(docs,field),function(field){ - return _.isUndefined(field) ? '' : field; + var all_values = _.pluck(docs,field), + groups = {}; + + // manually grouping into pairs allows us to keep the original value, + _.each(all_values, function (value) { + var key = _.isUndefined(value) ? '' : value.toString(); + if (_.has(groups, key)) { + groups[key][1] ++; + } else { + groups[key] = [value, 1]; + } }); - return _.pairs(counts).sort(function(a, b) { + + return _.values(groups).sort(function(a, b) { return a[1] - b[1]; }).reverse().slice(0,count); };