mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[indexPattern] added support for per-field formatting to help discover performance
This commit is contained in:
parent
f1ff251c46
commit
9e8eb3aecb
6 changed files with 70 additions and 36 deletions
|
@ -162,7 +162,7 @@ define(function (require) {
|
|||
* Fill an element with the value of a field
|
||||
*/
|
||||
function _displayField(row, field, breakWords) {
|
||||
var text = $scope.indexPattern.formatHit(row)[field];
|
||||
var text = $scope.indexPattern.formatField(row, field);
|
||||
text = highlightFilter(text, row.highlight && row.highlight[field]);
|
||||
|
||||
if (breakWords) {
|
||||
|
|
|
@ -41,7 +41,9 @@ define(function (require) {
|
|||
return flat;
|
||||
}
|
||||
|
||||
return function cachedFlatten(indexPattern, hit) {
|
||||
return hit.$$_flattened || (hit.$$_flattened = flattenHit(indexPattern, hit));
|
||||
return function (indexPattern) {
|
||||
return function cachedFlatten(hit) {
|
||||
return hit.$$_flattened || (hit.$$_flattened = flattenHit(indexPattern, hit));
|
||||
};
|
||||
};
|
||||
});
|
||||
|
|
|
@ -2,18 +2,42 @@
|
|||
// returns a formated version
|
||||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var flatten = require('components/index_patterns/_flatten_hit');
|
||||
|
||||
function formatHit(indexPattern, hit) {
|
||||
var fields = indexPattern.fields.byName;
|
||||
return _.transform(flatten(indexPattern, hit), function (formatted, val, name) {
|
||||
var field = fields[name];
|
||||
formatted[name] = field ? field.format.convert(val) : _.asPrettyString(val);
|
||||
}, {});
|
||||
}
|
||||
return function (indexPattern, defaultFormat) {
|
||||
|
||||
return function cachedFormat(indexPattern, hit) {
|
||||
return hit.$$_formatted || (hit.$$_formatted = formatHit(indexPattern, hit));
|
||||
function transformField(memo, val, name) {
|
||||
var field = indexPattern.fields.byName[name];
|
||||
return memo[name] = field ? field.format.convert(val, 'html') : defaultFormat.convert(val, 'html');
|
||||
}
|
||||
|
||||
function formatHit(hit) {
|
||||
if (hit.$$_formatted) return hit.$$_formatted;
|
||||
var cache = hit.$$_partialFormatted = hit.$$_formatted = {};
|
||||
|
||||
_.forOwn(indexPattern.flattenHit(hit), function (val, fieldName) {
|
||||
transformField(cache, val, fieldName);
|
||||
});
|
||||
|
||||
return hit.$$_formatted;
|
||||
}
|
||||
|
||||
formatHit.formatField = function (hit, fieldName) {
|
||||
// formatHit was previously called
|
||||
if (hit.$$_formatted) return hit.$$_formatted[fieldName];
|
||||
|
||||
var partial = hit.$$_partialFormatted;
|
||||
if (partial && _.has(partial, fieldName)) {
|
||||
return partial[fieldName];
|
||||
}
|
||||
|
||||
if (!partial) {
|
||||
partial = hit.$$_partialFormatted = {};
|
||||
}
|
||||
|
||||
return transformField(partial, indexPattern.flattenHit(hit)[fieldName], fieldName);
|
||||
};
|
||||
|
||||
return formatHit;
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -10,13 +10,14 @@ define(function (require) {
|
|||
var mapper = Private(require('components/index_patterns/_mapper'));
|
||||
var intervals = Private(require('components/index_patterns/_intervals'));
|
||||
var Field = Private(require('components/index_patterns/_field'));
|
||||
var flattenHit = require('components/index_patterns/_flatten_hit');
|
||||
var formatHit = require('components/index_patterns/_format_hit');
|
||||
var getComputedFields = require('components/index_patterns/_get_computed_fields');
|
||||
var DocSource = Private(require('components/courier/data_source/doc_source'));
|
||||
var mappingSetup = Private(require('utils/mapping_setup'));
|
||||
var IndexedArray = require('utils/indexed_array/index');
|
||||
|
||||
var flattenHit = require('components/index_patterns/_flatten_hit');
|
||||
var formatHit = require('components/index_patterns/_format_hit');
|
||||
|
||||
var type = 'index-pattern';
|
||||
|
||||
var notify = new Notifier();
|
||||
|
@ -264,9 +265,11 @@ define(function (require) {
|
|||
};
|
||||
|
||||
self.metaFields = config.get('metaFields');
|
||||
self.flattenHit = _.partial(flattenHit, self);
|
||||
self.formatHit = _.partial(formatHit, self);
|
||||
self.getComputedFields = getComputedFields.bind(self);
|
||||
|
||||
self.flattenHit = flattenHit(self);
|
||||
self.formatHit = formatHit(self, fieldformats.getDefaultInstance('string'));
|
||||
self.formatField = self.formatHit.formatField;
|
||||
}
|
||||
return IndexPattern;
|
||||
};
|
||||
|
|
|
@ -355,26 +355,30 @@ define(function (require) {
|
|||
rows = $scope.rows = rows.concat(resp.hits.hits);
|
||||
|
||||
if (sortFn) {
|
||||
rows.sort(sortFn);
|
||||
rows = $scope.rows = rows.slice(0, totalSize);
|
||||
counts = rows.fieldCounts = {};
|
||||
notify.event('resort rows', function () {
|
||||
rows.sort(sortFn);
|
||||
rows = $scope.rows = rows.slice(0, totalSize);
|
||||
counts = rows.fieldCounts = {};
|
||||
});
|
||||
}
|
||||
|
||||
$scope.rows.forEach(function (hit) {
|
||||
// skip this work if we have already done it and we are NOT sorting.
|
||||
// ---
|
||||
// when we are sorting results, we need to redo the counts each time because the
|
||||
// "top 500" may change with each response
|
||||
if (hit.$$_counted && !sortFn) return;
|
||||
hit.$$_counted = true;
|
||||
notify.event('flatten hit and count fields', function () {
|
||||
$scope.rows.forEach(function (hit) {
|
||||
// skip this work if we have already done it and we are NOT sorting.
|
||||
// ---
|
||||
// when we are sorting results, we need to redo the counts each time because the
|
||||
// "top 500" may change with each response
|
||||
if (hit.$$_counted && !sortFn) return;
|
||||
hit.$$_counted = true;
|
||||
|
||||
var fields = _.keys(indexPattern.formatHit(hit));
|
||||
var n = fields.length;
|
||||
var field;
|
||||
while (field = fields[--n]) {
|
||||
if (counts[field]) counts[field] += 1;
|
||||
else counts[field] = 1;
|
||||
}
|
||||
var fields = _.keys(indexPattern.flattenHit(hit));
|
||||
var n = fields.length;
|
||||
var field;
|
||||
while (field = fields[--n]) {
|
||||
if (counts[field]) counts[field] += 1;
|
||||
else counts[field] = 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}));
|
||||
|
|
|
@ -21,8 +21,9 @@ define(function (require) {
|
|||
var indexPattern = new StubIndexPattern('logstash-*', 'time', fields);
|
||||
|
||||
indexPattern.getComputedFields = _.bind(getComputedFields, indexPattern);
|
||||
indexPattern.flattenHit = _.partial(flattenHit, indexPattern);
|
||||
indexPattern.formatHit = _.partial(formatHit, indexPattern);
|
||||
indexPattern.flattenHit = flattenHit(indexPattern);
|
||||
indexPattern.formatHit = formatHit(indexPattern);
|
||||
indexPattern.formatField = indexPattern.formatHit.formatField;
|
||||
indexPattern.metaFields = ['_id', '_type', '_source'];
|
||||
indexPattern.id = 'logstash-*';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue