Commit 9daa3997 by Torkel Ödegaard

feat(elasticsearch): time field selector now works, #1034

parent 83930ec9
......@@ -5,6 +5,9 @@
<i class="fa fa-warning"></i>
</a>
</li>
<li class="tight-form-item small" ng-show="target.datasource">
<em>{{target.datasource}}</em>
</li>
<li class="tight-form-item">
<div class="dropdown">
<a class="pointer dropdown-toggle" data-toggle="dropdown" tabindex="1">
......@@ -48,7 +51,7 @@
Time field
</li>
<li>
<metric-segment segment="timeSegment" get-alt-segments="getFields()" on-value-changed="timestampChanged()"></metric-segment>
<metric-segment segment="timeSegment" get-alt-segments="getTimeFields()" on-value-changed="timeFieldChanged()"></metric-segment>
</li>
</ul>
......
......@@ -6,6 +6,12 @@ function (angular) {
function ElasticQueryBuilder() { }
ElasticQueryBuilder.prototype.getRangeFilter = function(timeField) {
var filter = {};
filter[timeField] = {"gte": "$timeFrom", "lte": "$timeTo"};
return filter;
};
ElasticQueryBuilder.prototype.build = function(target) {
if (target.rawQuery) {
return angular.fromJson(target.rawQuery);
......@@ -23,19 +29,7 @@ function (angular) {
},
"filter": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"gte": "$timeFrom",
"lte": "$timeTo"
}
}
}
],
"must_not": [
]
"must": [{"range": this.getRangeFilter(target.timeField)}]
}
}
}
......
......@@ -143,7 +143,8 @@ function (angular, _, ElasticQueryBuilder) {
};
$scope.getGroupByFields = function(segment) {
return $scope.datasource.metricFindQuery('fields()').then($scope.transformToSegments(false))
return $scope.datasource.metricFindQuery('fields()')
.then($scope.transformToSegments(false))
.then(function(results) {
if (segment.type !== 'plus-button') {
results.splice(0, 0, angular.copy($scope.removeGroupBySegment));
......@@ -153,6 +154,17 @@ function (angular, _, ElasticQueryBuilder) {
.then(null, $scope.handleQueryError);
};
$scope.getTimeFields = function() {
return $scope.datasource.metricFindQuery('fields()')
.then($scope.transformToSegments(false))
.then(null, $scope.handleQueryError);
};
$scope.timeFieldChanged = function() {
$scope.target.timeField = $scope.timeSegment.value;
$scope.queryUpdated();
};
$scope.groupByChanged = function(segment, index) {
if (segment.value === $scope.removeGroupBySegment.value) {
$scope.target.groupByFields.splice(index, 1);
......
......@@ -49,24 +49,18 @@
</li>
</ul>
<input type="text" class="tight-form-clear-input span10"
ng-model="target.target"
give-focus="target.textEditor"
spellcheck='false'
ng-model-onblur ng-change="get_data()"
ng-show="target.textEditor" />
<input type="text" class="tight-form-clear-input span10" ng-model="target.target" give-focus="target.textEditor" spellcheck='false' ng-model-onblur ng-change="get_data()" ng-show="target.textEditor"></input>
<ul class="tight-form-list" role="menu" ng-hide="target.textEditor">
<li ng-repeat="segment in segments" role="menuitem">
<metric-segment segment="segment" get-alt-segments="getAltSegments($index)" on-value-changed="segmentValueChanged(segment, $index)"></metric-segment>
</li>
<li ng-repeat="func in functions">
<span graphite-func-editor class="tight-form-item tight-form-func">
</span>
</li>
<li class="dropdown" graphite-add-func>
</li>
</ul>
<div class="clearfix"></div>
</div>
<ul class="tight-form-list" role="menu" ng-hide="target.textEditor">
<li ng-repeat="segment in segments" role="menuitem">
<metric-segment segment="segment" get-alt-segments="getAltSegments($index)" on-value-changed="segmentValueChanged(segment, $index)"></metric-segment>
</li>
<li ng-repeat="func in functions">
<span graphite-func-editor class="tight-form-item tight-form-func">
</span>
</li>
<li class="dropdown" graphite-add-func>
</li>
</ul>
<div class="clearfix"></div>
</div>
......@@ -9,6 +9,7 @@ define([
var builder = new ElasticQueryBuilder();
var query = builder.build({
timeField: '@timestamp',
select: [{agg: 'Count'}],
groupByFields: [],
});
......
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