From 3057c9747caf69bf0b1881890cbc1998c2c2928c Mon Sep 17 00:00:00 2001 From: Leandro Piccilli Date: Tue, 26 Jul 2016 22:05:49 +0200 Subject: [PATCH] Change size on terms aggregation for ES 5.x --- .../app/plugins/datasource/elasticsearch/query_builder.js | 5 +++-- .../datasource/elasticsearch/specs/datasource_specs.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/query_builder.js b/public/app/plugins/datasource/elasticsearch/query_builder.js index 09b1d7ce8f1..02953a0d2eb 100644 --- a/public/app/plugins/datasource/elasticsearch/query_builder.js +++ b/public/app/plugins/datasource/elasticsearch/query_builder.js @@ -28,7 +28,8 @@ function (queryDef) { return queryNode; } - queryNode.terms.size = parseInt(aggDef.settings.size, 10); + queryNode.terms.size = parseInt(aggDef.settings.size, 10) === 0 ? 1000 : parseInt(aggDef.settings.size, 10); + if (aggDef.settings.orderBy !== void 0) { queryNode.terms.order = {}; queryNode.terms.order[aggDef.settings.orderBy] = aggDef.settings.order; @@ -268,7 +269,7 @@ function (queryDef) { "1": { "terms": { "field": queryDef.field, - "size": 0, + "size": 1000, "order": { "_term": "asc" } diff --git a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts index 4e89ab853fa..ed201583152 100644 --- a/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts +++ b/public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts @@ -151,7 +151,7 @@ describe('ElasticDatasource', function() { }); describe('When issuing metricFind query on es5.x', function() { - var requestOptions, parts, header; + var requestOptions, parts, header, body; beforeEach(function() { createDatasource({url: 'http://es.com', index: 'test', jsonData: {esVersion: '5'}}); @@ -170,6 +170,7 @@ describe('ElasticDatasource', function() { parts = requestOptions.data.split('\n'); header = angular.fromJson(parts[0]); + body = angular.fromJson(parts[1]); }); it('should not set search type to count', function() { @@ -177,10 +178,12 @@ describe('ElasticDatasource', function() { }); it('should set size to 0', function() { - var body = angular.fromJson(parts[1]); expect(body.size).to.be(0); }); + it('should not set terms aggregation size to 0', function() { + expect(body['aggs']['1']['terms'].size).to.not.be(0); + }); }); });