Sfoglia il codice sorgente

Fix templating using query

Leandro Piccilli 9 anni fa
parent
commit
538e1fbc64
1 ha cambiato i file con 18 aggiunte e 11 eliminazioni
  1. 18 11
      public/app/plugins/datasource/elasticsearch/query_builder.js

+ 18 - 11
public/app/plugins/datasource/elasticsearch/query_builder.js

@@ -251,7 +251,7 @@ function (queryDef) {
   };
 
   ElasticQueryBuilder.prototype.getTermsQuery = function(queryDef) {
-    var query, queryPath;
+    var query;
 
     if (this.esVersion >= 5) {
       query = {
@@ -262,7 +262,15 @@ function (queryDef) {
           }
         }
       };
-      queryPath = query.query.bool.must;
+
+      if (queryDef.query) {
+        query.query.bool.must.push({
+          "query_string": {
+            "analyze_wildcard": true,
+            "query": queryDef.query,
+          }
+        });
+      }
 
     } else {
       query = {
@@ -277,16 +285,15 @@ function (queryDef) {
           }
         }
       };
-      queryPath = query.query.filtered.query;
-    }
 
-    if (queryDef.query) {
-      queryPath = {
-        "query_string": {
-          "analyze_wildcard": true,
-          "query": queryDef.query,
-        }
-      };
+      if (queryDef.query) {
+        query.query.filtered.query = {
+          "query_string": {
+            "analyze_wildcard": true,
+            "query": queryDef.query,
+          }
+        };
+      }
     }
 
     query.aggs =  {