Skip to content

Commit

Permalink
Merge pull request elastic#2146 from w33ble/select-scripted
Browse files Browse the repository at this point in the history
Select scripted fields
  • Loading branch information
rashidkpc committed Dec 6, 2014
2 parents 4f26fc7 + cc797a9 commit 0627fd2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/kibana/components/doc_viewer/doc_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ define(function (require) {

$scope.flattened = $scope.indexPattern.flattenHit($scope.hit);
$scope.formatted = _.mapValues($scope.flattened, function (value, name) {
var formatter = $scope.mapping[name] ? $scope.mapping[name].format : defaultFormat;
var mapping = $scope.mapping[name];
var formatter = (mapping && mapping.format) ? mapping.format : defaultFormat;
return formatter.convert(value);
});
$scope.fields = _.keys($scope.flattened).sort();
Expand Down
4 changes: 4 additions & 0 deletions src/kibana/components/index_patterns/_get_computed_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ define(function (require) {
}
});

_.each(self.getFields('scripted'), function (field) {
scriptFields[field.name] = { script: field.script };
});

return {
fields: ['*', '_source'],
scriptFields: scriptFields
Expand Down
4 changes: 3 additions & 1 deletion src/kibana/directives/field_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ define(function (require) {

var type = $scope.field ? $scope.field.type : $scope.fieldType;
var name = $scope.field ? $scope.field.name : $scope.fieldName;
var results = $scope.field ? !$scope.field.rowCount : false;
var results = $scope.field ? !$scope.field.rowCount && !$scope.field.scripted : false;
var scripted = $scope.field ? $scope.field.scripted : false;

var displayName = $filter('shortDots')(name);

$el
.text(displayName)
.attr('title', name)
.toggleClass('no-results', results)
.toggleClass('scripted', scripted)
.prepend(typeIcon(type));
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ define(function (require) {
filter.vals = _.clone(filter.defaults);
},
isFieldFiltered: function (field) {
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 matchName = (!filter.vals.name || field.name.indexOf(filter.vals.name) !== -1);

return !field.display
&& (filter.vals.type == null || field.type === filter.vals.type)
&& (filter.vals.analyzed == null || field.analyzed === filter.vals.analyzed)
&& (filter.vals.indexed == null || field.indexed === filter.vals.indexed)
&& (!filter.vals.missing || field.rowCount > 0)
&& (!filter.vals.name || field.name.indexOf(filter.vals.name) !== -1)
&& matchFilter
&& isAnalyzed
&& isIndexed
&& rowsScritpedOrMissing
&& matchName
;
},
popularity: function (field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ define(function (require) {
});

if (params.data.length - missing === 0) {
return {error: 'This is field is present in your elasticsearch mapping,' +
' but not in any documents in the search results. You may still be able to visualize or search on it'};
return {
error: 'This field is present in your elasticsearch mapping' +
' but not in any documents in the search results.' +
' You may still be able to visualize or search on it.'
};
}

return {
Expand Down
3 changes: 2 additions & 1 deletion src/kibana/plugins/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ define(function (require) {
counts[name] = counts[name] ? counts[name] + 1 : 1;

var defaultFormat = courier.indexPatterns.fieldFormats.defaultByType.string;
var formatter = indexPattern.fields.byName[name] ? indexPattern.fields.byName[name].format : defaultFormat;
var field = indexPattern.fields.byName[name];
var formatter = (field && field.format) ? field.format : defaultFormat;

return formatter.convert(value);
};
Expand Down
1 change: 1 addition & 0 deletions test/utils/stub_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define(function (require) {
return field;
})
});
this.getFields = sinon.spy();
}
return StubIndexPattern;
};
Expand Down

0 comments on commit 0627fd2

Please sign in to comment.