瀏覽代碼

[elasticsearch] Fix bug when switching from "Raw Document" metric type
when switch to "raw Document" metric type we do free all "Group by"
however when we switch back to another type we do not reset the default aggregation (date histogram)
Thus all modification will through exception as no "Group by" is defined and panel should be recreated
the fix will reintialize the "Group by" by setting default value

Dhia MOAKHAR 8 年之前
父節點
當前提交
045f5e11fc
共有 1 個文件被更改,包括 5 次插入4 次删除
  1. 5 4
      public/app/plugins/datasource/elasticsearch/query_builder.js

+ 5 - 4
public/app/plugins/datasource/elasticsearch/query_builder.js

@@ -194,11 +194,12 @@ function (queryDef) {
     if (target.bucketAggs.length === 0) {
     if (target.bucketAggs.length === 0) {
       metric = target.metrics[0];
       metric = target.metrics[0];
       if (metric && metric.type !== 'raw_document') {
       if (metric && metric.type !== 'raw_document') {
-        throw {message: 'Invalid query'};
-      }
-      var size = metric && metric.hasOwnProperty("settings") && metric.settings.hasOwnProperty("size")
+        target.bucketAggs = [{type: 'date_histogram', id: '2', settings: {interval: 'auto'}}];
+      } else {
+        var size = metric && metric.hasOwnProperty("settings") && metric.settings.hasOwnProperty("size")
                    && metric.settings["size"] !== null ? metric.settings["size"] : 500 ;
                    && metric.settings["size"] !== null ? metric.settings["size"] : 500 ;
-      return this.documentQuery(query,size);
+        return this.documentQuery(query,size);
+      }
     }
     }
 
 
     nestedAggs = query;
     nestedAggs = query;