Commit 792b194d by Torkel Ödegaard

feat(elasticsearch): finished work on adding support for filters aggregate, you…

feat(elasticsearch): finished work on adding support for filters aggregate, you can now split series by query using group by filters, closes #2785
parent e694a74c
...@@ -80,6 +80,15 @@ function (angular, _, queryDef) { ...@@ -80,6 +80,15 @@ function (angular, _, queryDef) {
break; break;
} }
case 'filters': { case 'filters': {
settings.filters = settings.filters || [{query: '*'}];
settingsLinkText = _.reduce(settings.filters, function(memo, value, index) {
memo += 'Q' + (index + 1) + ' = ' + value.query + ' ';
return memo;
}, '');
if (settingsLinkText.length > 50) {
settingsLinkText = settingsLinkText.substr(0, 50) + "...";
}
settingsLinkText = 'Filter Queries (' + settings.filters.length + ')';
break; break;
} }
case 'date_histogram': { case 'date_histogram': {
...@@ -94,6 +103,14 @@ function (angular, _, queryDef) { ...@@ -94,6 +103,14 @@ function (angular, _, queryDef) {
return true; return true;
}; };
$scope.addFiltersQuery = function() {
$scope.agg.settings.filters.push({query: '*'});
};
$scope.removeFiltersQuery = function(filter) {
$scope.agg.settings.filters = _.without($scope.agg.settings.filters, filter);
};
$scope.toggleOptions = function() { $scope.toggleOptions = function() {
$scope.showOptions = !$scope.showOptions; $scope.showOptions = !$scope.showOptions;
$scope.updateOrderByOptions(); $scope.updateOrderByOptions();
......
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
<li> <li>
<metric-segment-model property="agg.type" options="bucketAggTypes" on-change="onTypeChanged()" custom="false" css-class="tight-form-item-large"></metric-segment-model> <metric-segment-model property="agg.type" options="bucketAggTypes" on-change="onTypeChanged()" custom="false" css-class="tight-form-item-large"></metric-segment-model>
</li> </li>
<li ng-if="agg.type !== 'filters'"> <li ng-if="agg.field">
<metric-segment-model property="agg.field" get-options="getFields()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment> <metric-segment-model property="agg.field" get-options="getFields()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment>
</li> </li>
<li ng-if="agg.type === 'filters'"> <li ng-if="!agg.field">
<input type="text" class="tight-form-input tight-form-item-xxlarge" ng-model="agg.query" spellcheck='false' placeholder="Lucence query" ng-blur="onChange()"> <span class="tight-form-item tight-form-item-xxlarge">&nbsp;</span>
</li> </li>
<li class="tight-form-item last" ng-if="settingsLinkText"> <li class="tight-form-item last" ng-if="settingsLinkText">
<a ng-click="toggleOptions()">{{settingsLinkText}}</a> <a ng-click="toggleOptions()">{{settingsLinkText}}</a>
...@@ -78,6 +78,27 @@ ...@@ -78,6 +78,27 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
</div> </div>
<div class="tight-form-inner-box" ng-if="agg.type === 'filters'">
<div class="tight-form" ng-repeat="filter in agg.settings.filters" ng-class="{last: $last}">
<ul class="tight-form-list">
<li class="tight-form-item" style="width: 100px">
Query {{$index + 1}}
</li>
<li>
<input type="text" class="tight-form-input input-large" ng-model="filter.query" spellcheck='false' placeholder="Lucence query" ng-blur="onChangeInternal()">
</li>
<li class="tight-form-item last" ng-if="$first">
<a class="pointer" ng-click="addFiltersQuery()"><i class="fa fa-plus"></i></a>
</li>
<li class="tight-form-item last" ng-if="!$first">
<a class="pointer" ng-click="removeFiltersQuery(filter)"><i class="fa fa-minus"></i></a>
</li>
</ul>
<div class="clearfix"></div>
</div>
</div>
</div> </div>
...@@ -54,19 +54,15 @@ function (angular) { ...@@ -54,19 +54,15 @@ function (angular) {
} }
}; };
ElasticQueryBuilder.prototype.getFiltersAgg = function(target) { ElasticQueryBuilder.prototype.getFiltersAgg = function(aggDef) {
var filterObj = {}; var filterObj = {};
for (var i = 0; i < target.bucketAggs.length; i++) { for (var i = 0; i < aggDef.settings.filters.length; i++) {
var aggDef = target.bucketAggs[i]; var query = aggDef.settings.filters[i].query;
if (aggDef.type !== 'filters') { filterObj[query] = {
continue;
}
filterObj[aggDef.query] = {
query: { query: {
query_string: { query_string: {
query: aggDef.query, query: query,
analyze_wildcard: true analyze_wildcard: true
} }
} }
...@@ -81,7 +77,7 @@ function (angular) { ...@@ -81,7 +77,7 @@ function (angular) {
return angular.fromJson(target.rawQuery); return angular.fromJson(target.rawQuery);
} }
var i, nestedAggs, metric, filtersHandled; var i, nestedAggs, metric;
var query = { var query = {
"size": 0, "size": 0,
"query": { "query": {
...@@ -118,12 +114,7 @@ function (angular) { ...@@ -118,12 +114,7 @@ function (angular) {
break; break;
} }
case 'filters': { case 'filters': {
// skip filters if we already processed them esAgg["filters"] = {filters: this.getFiltersAgg(aggDef)};
if (filtersHandled) {
continue;
}
esAgg["filters"] = {filters: this.getFiltersAgg(target)};
filtersHandled = true;
break; break;
} }
case 'terms': { case 'terms': {
......
...@@ -100,8 +100,16 @@ define([ ...@@ -100,8 +100,16 @@ define([
metrics: [{type: 'count', id: '1'}], metrics: [{type: 'count', id: '1'}],
timeField: '@timestamp', timeField: '@timestamp',
bucketAggs: [ bucketAggs: [
{type: 'filters', query: '@metric:cpu', id: '2'}, {
{type: 'filters', query: '@metric:logins.count', id: '3' }, id: '2',
type: 'filters',
settings: {
filters: [
{query: '@metric:cpu' },
{query: '@metric:logins.count' },
]
}
},
{type: 'date_histogram', field: '@timestamp', id: '4'} {type: 'date_histogram', field: '@timestamp', id: '4'}
], ],
}); });
......
...@@ -359,8 +359,16 @@ define([ ...@@ -359,8 +359,16 @@ define([
refId: 'A', refId: 'A',
metrics: [{type: 'count', id: '1'}], metrics: [{type: 'count', id: '1'}],
bucketAggs: [ bucketAggs: [
{type: 'filters', query: '@metric:cpu', id: '2'}, {
{type: 'filters', query: '@metric:logins.count', id: '5'}, id: '2',
type: 'filters',
settings: {
filters: [
{query: '@metric:cpu' },
{query: '@metric:logins.count' },
]
}
},
{type: 'date_histogram', field: '@timestamp', id: '3'} {type: 'date_histogram', field: '@timestamp', id: '3'}
], ],
}]; }];
......
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