Commit b160700e by Spencer Alger

adjusted the shared kbn.top_field_values() function to preserve field values,…

adjusted the shared kbn.top_field_values() function to preserve field values, specifically so that arrays are not flattened to strings
parent 1989a307
......@@ -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);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment