Added group by to Elasticsearch data source.
This commit is contained in:
@@ -313,16 +313,23 @@ function (angular, _, config, kbn, moment, ElasticQueryBuilder) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ElasticDatasource.prototype._getTimeSeries = function(results) {
|
ElasticDatasource.prototype._getTimeSeries = function(results) {
|
||||||
|
var _aggregation2timeSeries = function(aggregation) {
|
||||||
|
var datapoints = aggregation.date_histogram.buckets.map(function(entry) {
|
||||||
|
return [entry.stats.avg, entry.key];
|
||||||
|
});
|
||||||
|
return { target: aggregation.key, datapoints: datapoints };
|
||||||
|
};
|
||||||
var data = [];
|
var data = [];
|
||||||
|
|
||||||
if (results && results.aggregations) {
|
if (results && results.aggregations) {
|
||||||
for (var target in results.aggregations) {
|
for (var target in results.aggregations) {
|
||||||
if (results.aggregations.hasOwnProperty(target) &&
|
if (!results.aggregations.hasOwnProperty(target)) {
|
||||||
results.aggregations[target].date_histogram &&
|
continue;
|
||||||
results.aggregations[target].date_histogram.buckets) {
|
}
|
||||||
var datapoints = results.aggregations[target].date_histogram.buckets.map(function(entry) {
|
if (results.aggregations[target].date_histogram && results.aggregations[target].date_histogram.buckets) {
|
||||||
return [entry.metric.avg, entry.key];
|
data.push(_aggregation2timeSeries(results.aggregations[target]));
|
||||||
});
|
} else if (results.aggregations[target].terms && results.aggregations[target].terms.buckets) {
|
||||||
data.push({ target: target, datapoints: datapoints });
|
[].push.apply(data, results.aggregations[target].terms.buckets.map(_aggregation2timeSeries));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,22 +75,6 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <div class="tight-form" ng-hide="target.rawQuery">
|
|
||||||
<ul class="tight-form-list">
|
|
||||||
<li class="tight-form-item">
|
|
||||||
<i class="fa fa-eye invisible"></i>
|
|
||||||
</li>
|
|
||||||
<li class="tight-form-item query-keyword" style="width: 75px;">
|
|
||||||
Measurement
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<metric-segment segment="measurementSegment" get-alt-segments="getMeasurements()" on-value-changed="measurementChanged()"></metric-segment>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<div class="tight-form" ng-hide="target.rawQuery">
|
<div class="tight-form" ng-hide="target.rawQuery">
|
||||||
<ul class="tight-form-list">
|
<ul class="tight-form-list">
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
@@ -148,67 +132,21 @@
|
|||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- <div class="tight-form" ng-hide="target.rawQuery">
|
<div class="tight-form" ng-hide="target.rawQuery">
|
||||||
<ul class="tight-form-list">
|
<ul class="tight-form-list">
|
||||||
<li class="tight-form-item">
|
<li class="tight-form-item">
|
||||||
<i class="fa fa-eye invisible"></i>
|
<i class="fa fa-eye invisible"></i>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li class="tight-form-item query-keyword" style="width: 75px;">
|
<li class="tight-form-item query-keyword" style="width: 75px;">
|
||||||
WHERE
|
Group By
|
||||||
</li>
|
|
||||||
|
|
||||||
<li ng-repeat="segment in tagSegments">
|
|
||||||
<metric-segment segment="segment" get-alt-segments="getTagsOrValues(segment, $index)" on-value-changed="tagSegmentUpdated(segment, $index)"></metric-segment>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
<!-- <div class="tight-form">
|
|
||||||
<ul class="tight-form-list" ng-hide="target.rawQuery">
|
|
||||||
<li class="tight-form-item">
|
|
||||||
<i class="fa fa-eye invisible"></i>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="tight-form-item" >
|
|
||||||
<span class="query-keyword">GROUP BY</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="tight-form-item">
|
|
||||||
time($interval)
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li ng-repeat="segment in groupBySegments">
|
|
||||||
<metric-segment segment="segment" get-alt-segments="getGroupByTagSegments(segment, 0)" on-value-changed="groupByTagUpdated(segment, $index)"></metric-segment>
|
|
||||||
</li>
|
|
||||||
<li class="dropdown">
|
|
||||||
<a class="tight-form-item pointer" data-toggle="dropdown" bs-tooltip="'Insert missing values, important when stacking'" data-placement="right">
|
|
||||||
<span ng-show="target.fill">
|
|
||||||
fill ({{target.fill}})
|
|
||||||
</span>
|
|
||||||
<span ng-show="!target.fill">
|
|
||||||
no fill
|
|
||||||
</span>
|
|
||||||
</a>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li><a ng-click="target.fill = ''">no fill</a></li>
|
|
||||||
<li><a ng-click="target.fill = 'null'">fill (null)</a></li>
|
|
||||||
<li><a ng-click="target.fill = '0'">fill (0)</a></li>
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<ul class="tight-form-list pull-right">
|
|
||||||
<li class="tight-form-item">
|
|
||||||
Alias pattern
|
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<input type="text" class="input-medium tight-form-input" ng-model="target.alias" spellcheck='false' placeholder="alias" ng-blur="get_data()">
|
<metric-segment segment="groupByFieldSegment" on-value-changed="groupByFieldChanged()"></metric-segment>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="clearfix"></div>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
|
<div class="clearfix"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function () {
|
|||||||
"min_doc_count": 0,
|
"min_doc_count": 0,
|
||||||
},
|
},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"metric": {
|
"stats": {
|
||||||
"stats": {
|
"stats": {
|
||||||
"field": target.valueField
|
"field": target.valueField
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,16 @@ function () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (target.groupByField) {
|
||||||
|
query["aggs"][target.termKey + "_" + target.termValue]["aggs"] = {
|
||||||
|
"terms": {
|
||||||
|
"terms": {
|
||||||
|
"field": target.groupByField
|
||||||
|
},
|
||||||
|
"aggs": query["aggs"][target.termKey + "_" + target.termValue]["aggs"]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
query = JSON.stringify(query);
|
query = JSON.stringify(query);
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ function (angular, _, ElasticQueryBuilder) {
|
|||||||
}
|
}
|
||||||
$scope.termValueSegment = new MetricSegment({value: target.termValue});
|
$scope.termValueSegment = new MetricSegment({value: target.termValue});
|
||||||
|
|
||||||
|
if (!target.groupByField) {
|
||||||
|
target.groupByField = 'host.raw';
|
||||||
|
}
|
||||||
|
$scope.groupByFieldSegment = new MetricSegment({value: target.groupByField});
|
||||||
|
|
||||||
if (!target.measurement) {
|
if (!target.measurement) {
|
||||||
$scope.measurementSegment = MetricSegment.newSelectMeasurement();
|
$scope.measurementSegment = MetricSegment.newSelectMeasurement();
|
||||||
} else {
|
} else {
|
||||||
@@ -93,6 +98,11 @@ function (angular, _, ElasticQueryBuilder) {
|
|||||||
$scope.$parent.get_data();
|
$scope.$parent.get_data();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.groupByFieldChanged = function() {
|
||||||
|
$scope.target.groupBy = $scope.groupByFieldSegment.value;
|
||||||
|
$scope.$parent.get_data();
|
||||||
|
};
|
||||||
|
|
||||||
$scope.fixTagSegments = function() {
|
$scope.fixTagSegments = function() {
|
||||||
var count = $scope.tagSegments.length;
|
var count = $scope.tagSegments.length;
|
||||||
var lastSegment = $scope.tagSegments[Math.max(count-1, 0)];
|
var lastSegment = $scope.tagSegments[Math.max(count-1, 0)];
|
||||||
|
|||||||
Reference in New Issue
Block a user