mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #14054 from marefr/6367_raw_document_reset
Fix switching from es raw document metric breaks query editor
This commit is contained in:
commit
0a080149ae
@ -160,6 +160,12 @@ export class ElasticMetricAggCtrl {
|
||||
$scope.agg.settings = {};
|
||||
$scope.agg.meta = {};
|
||||
$scope.showOptions = false;
|
||||
|
||||
// reset back to metric/group by query
|
||||
if ($scope.target.bucketAggs.length === 0 && $scope.agg.type !== 'raw_document') {
|
||||
$scope.target.bucketAggs = [queryDef.defaultBucketAgg()];
|
||||
}
|
||||
|
||||
$scope.updatePipelineAggOptions();
|
||||
$scope.onChange();
|
||||
};
|
||||
|
@ -181,8 +181,8 @@ export class ElasticQueryBuilder {
|
||||
|
||||
build(target, adhocFilters?, queryString?) {
|
||||
// make sure query has defaults;
|
||||
target.metrics = target.metrics || [{ type: 'count', id: '1' }];
|
||||
target.bucketAggs = target.bucketAggs || [{ type: 'date_histogram', id: '2', settings: { interval: 'auto' } }];
|
||||
target.metrics = target.metrics || [queryDef.defaultMetricAgg()];
|
||||
target.bucketAggs = target.bucketAggs || [queryDef.defaultBucketAgg()];
|
||||
target.timeField = this.timeField;
|
||||
|
||||
let i, nestedAggs, metric;
|
||||
|
@ -17,6 +17,19 @@ export class ElasticQueryCtrl extends QueryCtrl {
|
||||
super($scope, $injector);
|
||||
|
||||
this.esVersion = this.datasource.esVersion;
|
||||
|
||||
this.target = this.target || {};
|
||||
this.target.metrics = this.target.metrics || [queryDef.defaultMetricAgg()];
|
||||
this.target.bucketAggs = this.target.bucketAggs || [queryDef.defaultBucketAgg()];
|
||||
|
||||
if (this.target.bucketAggs.length === 0) {
|
||||
const metric = this.target.metrics[0];
|
||||
if (!metric || metric.type !== 'raw_document') {
|
||||
this.target.bucketAggs = [queryDef.defaultBucketAgg()];
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
this.queryUpdated();
|
||||
}
|
||||
|
||||
|
@ -228,3 +228,11 @@ export function describeOrderBy(orderBy, target) {
|
||||
return 'metric not found';
|
||||
}
|
||||
}
|
||||
|
||||
export function defaultMetricAgg() {
|
||||
return { type: 'count', id: '1' };
|
||||
}
|
||||
|
||||
export function defaultBucketAgg() {
|
||||
return { type: 'date_histogram', id: '2', settings: { interval: 'auto' } };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user