diff --git a/public/app/plugins/datasource/elasticsearch/metric_agg.js b/public/app/plugins/datasource/elasticsearch/metric_agg.js
index c0c4ffc08d4..88053b0efac 100644
--- a/public/app/plugins/datasource/elasticsearch/metric_agg.js
+++ b/public/app/plugins/datasource/elasticsearch/metric_agg.js
@@ -67,7 +67,6 @@ function (angular, _, queryDef) {
} else if (!$scope.agg.field) {
$scope.agg.field = 'select field';
}
-
switch($scope.agg.type) {
case 'cardinality': {
var precision_threshold = $scope.agg.settings.precision_threshold || '';
@@ -103,12 +102,14 @@ function (angular, _, queryDef) {
break;
}
case 'raw_document': {
- $scope.target.metrics = [$scope.agg];
+ $scope.agg.settings.size = $scope.agg.settings.size || 500;
+ $scope.settingsLinkText = 'Size: ' + $scope.agg.settings.size ;
+ $scope.target.metrics.splice(0,$scope.target.metrics.length, $scope.agg);
+
$scope.target.bucketAggs = [];
break;
}
}
-
if ($scope.aggDef.supportsInlineScript) {
// I know this stores the inline script twice
// but having it like this simplifes the query_builder
diff --git a/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html b/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html
index 8c25c2d5347..b4a1a61ed32 100644
--- a/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html
+++ b/public/app/plugins/datasource/elasticsearch/partials/metric_agg.html
@@ -72,6 +72,11 @@
+
+
+
+
+
diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js
index 62a7b379c8e..1493fd3eb95 100644
--- a/public/app/plugins/datasource/elasticsearch/query_builder.js
+++ b/public/app/plugins/datasource/elasticsearch/query_builder.js
@@ -109,8 +109,8 @@ function (queryDef) {
return filterObj;
};
- ElasticQueryBuilder.prototype.documentQuery = function(query) {
- query.size = 500;
+ ElasticQueryBuilder.prototype.documentQuery = function(query, size) {
+ query.size = size === undefined ? 500 : size;
query.sort = {};
query.sort[this.timeField] = {order: 'desc', unmapped_type: 'boolean'};
@@ -194,9 +194,12 @@ function (queryDef) {
if (target.bucketAggs.length === 0) {
metric = target.metrics[0];
if (metric && metric.type !== 'raw_document') {
- throw {message: 'Invalid query'};
+ 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 ;
+ return this.documentQuery(query,size);
}
- return this.documentQuery(query, target);
}
nestedAggs = query;
diff --git a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
index 18645ad498d..4ea108359a1 100644
--- a/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+++ b/public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
@@ -156,13 +156,22 @@ describe('ElasticQueryBuilder', function() {
it('with raw_document metric', function() {
var query = builder.build({
- metrics: [{type: 'raw_document', id: '1'}],
+ metrics: [{type: 'raw_document', id: '1',settings: {}}],
timeField: '@timestamp',
bucketAggs: [],
});
expect(query.size).to.be(500);
});
+ it('with raw_document metric size set', function() {
+ var query = builder.build({
+ metrics: [{type: 'raw_document', id: '1',settings: {size: 1337}}],
+ timeField: '@timestamp',
+ bucketAggs: [],
+ });
+
+ expect(query.size).to.be(1337);
+ });
it('with moving average', function() {
var query = builder.build({