mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 01:13:23 -04:00
[fieldChooser] hits vs. data
This commit is contained in:
parent
b0493426d3
commit
ceafeff64c
4 changed files with 27 additions and 23 deletions
|
@ -16,7 +16,7 @@ define(function (require) {
|
|||
restrict: 'E',
|
||||
scope: {
|
||||
columns: '=',
|
||||
rows: '=',
|
||||
hits: '=',
|
||||
fieldCounts: '=',
|
||||
state: '=',
|
||||
indexPattern: '=',
|
||||
|
@ -61,14 +61,14 @@ define(function (require) {
|
|||
var matchFilter = (filter.vals.type == null || field.type === filter.vals.type);
|
||||
var isAnalyzed = (filter.vals.analyzed == null || field.analyzed === filter.vals.analyzed);
|
||||
var isIndexed = (filter.vals.indexed == null || field.indexed === filter.vals.indexed);
|
||||
var rowsScritpedOrMissing = (!filter.vals.missing || field.scripted || field.rowCount > 0);
|
||||
var scritpedOrMissing = (!filter.vals.missing || field.scripted || field.rowCount > 0);
|
||||
var matchName = (!filter.vals.name || field.name.indexOf(filter.vals.name) !== -1);
|
||||
|
||||
return !field.display
|
||||
&& matchFilter
|
||||
&& isAnalyzed
|
||||
&& isIndexed
|
||||
&& rowsScritpedOrMissing
|
||||
&& scritpedOrMissing
|
||||
&& matchName
|
||||
;
|
||||
},
|
||||
|
@ -96,7 +96,8 @@ define(function (require) {
|
|||
|
||||
$scope.$watchMulti([
|
||||
'[]fieldCounts',
|
||||
'[]columns'
|
||||
'[]columns',
|
||||
'[]hits'
|
||||
], function () {
|
||||
var fields = getFields($scope.indexPattern, $scope.rows);
|
||||
var columns = $scope.columns;
|
||||
|
@ -192,7 +193,7 @@ define(function (require) {
|
|||
$scope.details = function (field, recompute) {
|
||||
if (_.isUndefined(field.details) || recompute) {
|
||||
field.details = fieldCalculator.getFieldValueCounts({
|
||||
data: $scope.rows,
|
||||
hits: $scope.hits,
|
||||
field: field,
|
||||
count: 5,
|
||||
grouped: false
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
|
||||
var getFieldValues = function (data, field) {
|
||||
var getFieldValues = function (hits, field) {
|
||||
var name = field.name;
|
||||
|
||||
return _.map(data, function (row) {
|
||||
return row.$$_flattened[name] == null ? row[name] : row.$$_flattened[name];
|
||||
var flattenHit = field.indexPattern.flattenHit;
|
||||
return _.map(hits, function (hit) {
|
||||
return flattenHit(hit)[name];
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -23,10 +23,8 @@ define(function (require) {
|
|||
return { error: 'Analysis is not available for geo fields.' };
|
||||
}
|
||||
|
||||
var allValues = getFieldValues(params.data, params.field);
|
||||
var exists = 0;
|
||||
var allValues = getFieldValues(params.hits, params.field);
|
||||
var counts;
|
||||
|
||||
var missing = _countMissing(allValues);
|
||||
|
||||
try {
|
||||
|
@ -37,11 +35,11 @@ define(function (require) {
|
|||
return {
|
||||
value: bucket.value,
|
||||
count: bucket.count,
|
||||
percent: (bucket.count / (params.data.length - missing) * 100).toFixed(1)
|
||||
percent: (bucket.count / (params.hits.length - missing) * 100).toFixed(1)
|
||||
};
|
||||
});
|
||||
|
||||
if (params.data.length - missing === 0) {
|
||||
if (params.hits.length - missing === 0) {
|
||||
return {
|
||||
error: 'This field is present in your elasticsearch mapping' +
|
||||
' but not in any documents in the search results.' +
|
||||
|
@ -50,8 +48,8 @@ define(function (require) {
|
|||
}
|
||||
|
||||
return {
|
||||
total: params.data.length,
|
||||
exists: params.data.length - missing,
|
||||
total: params.hits.length,
|
||||
exists: params.hits.length - missing,
|
||||
missing: missing,
|
||||
buckets: counts,
|
||||
};
|
||||
|
@ -69,7 +67,6 @@ define(function (require) {
|
|||
|
||||
var _groupValues = function (allValues, params) {
|
||||
var groups = {};
|
||||
var value;
|
||||
var k;
|
||||
|
||||
allValues.forEach(function (value) {
|
||||
|
@ -104,4 +101,4 @@ define(function (require) {
|
|||
getFieldValues: getFieldValues,
|
||||
getFieldValueCounts: getFieldValueCounts
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
<disc-field-chooser
|
||||
columns="state.columns"
|
||||
refresh="refreshFieldList"
|
||||
rows="rows"
|
||||
hits="hits"
|
||||
field-counts="fieldCounts"
|
||||
filter="filterQuery"
|
||||
index-pattern="searchSource.get('index')"
|
||||
|
|
|
@ -42,7 +42,8 @@ define(function (require) {
|
|||
'<disc-field-chooser' +
|
||||
' columns="columns"' +
|
||||
' toggle="toggle"' +
|
||||
' data="data"' +
|
||||
' hits="hits"' +
|
||||
' field-counts="fieldCounts"' +
|
||||
' filter="filter"' +
|
||||
' index-pattern="indexPattern"' +
|
||||
' index-pattern-list="indexPatternList"' +
|
||||
|
@ -58,12 +59,17 @@ define(function (require) {
|
|||
indexPatternList = [ 'b', 'a', 'c' ];
|
||||
});
|
||||
|
||||
var flatHits = _.each(hits, indexPattern.flattenHit);
|
||||
var fieldCounts = _.transform(hits, function (counts, hit) {
|
||||
_(indexPattern.flattenHit(hit)).keys().each(function (key) {
|
||||
counts[key] = (counts[key] || 0) + 1;
|
||||
});
|
||||
}, {});
|
||||
|
||||
init($elem, {
|
||||
columns: [],
|
||||
toggle: sinon.spy(),
|
||||
data: flatHits,
|
||||
hits: hits,
|
||||
fieldCounts: fieldCounts,
|
||||
filter: sinon.spy(),
|
||||
indexPattern: indexPattern,
|
||||
indexPatternList: indexPatternList
|
||||
|
@ -130,7 +136,7 @@ define(function (require) {
|
|||
init($elem, {
|
||||
columns: [],
|
||||
toggle: sinon.spy(),
|
||||
data: require('fixtures/hits'),
|
||||
hits: require('fixtures/hits'),
|
||||
filter: sinon.spy(),
|
||||
indexPattern: indexPattern
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue