From 03f7fd0527b07db4bea8dc2e4e18d0d169ea9cb6 Mon Sep 17 00:00:00 2001 From: Marcus Efraimsson Date: Wed, 17 Jun 2020 10:04:38 +0200 Subject: [PATCH] Elasticsearch: Support using a variable for histogram and terms min doc count (#25392) Support using a variable for histogram and terms min doc count. This is an addition to #21064. Ref #21052 Ref #21064 --- .../elasticsearch/partials/bucket_agg.html | 4 +- .../datasource/elasticsearch/query_builder.ts | 4 ++ .../elasticsearch/specs/query_builder.test.ts | 44 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html index cca50a6fbfb..bf23328e623 100644 --- a/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html +++ b/public/app/plugins/datasource/elasticsearch/partials/bucket_agg.html @@ -116,7 +116,7 @@
{ expect(secondLevel.aggs['5'].avg.field).toBe('@value'); }); + it('with term agg and valid min_doc_count', () => { + const query = builder.build( + { + metrics: [{ type: 'count', id: '1' }], + bucketAggs: [ + { + type: 'terms', + field: '@host', + settings: { min_doc_count: 1 }, + id: '2', + }, + { type: 'date_histogram', field: '@timestamp', id: '3' }, + ], + }, + 100, + '1000' + ); + + const firstLevel = query.aggs['2']; + expect(firstLevel.terms.min_doc_count).toBe(1); + }); + + it('with term agg and variable as min_doc_count', () => { + const query = builder.build( + { + metrics: [{ type: 'count', id: '1' }], + bucketAggs: [ + { + type: 'terms', + field: '@host', + settings: { min_doc_count: '$min_doc_count' }, + id: '2', + }, + { type: 'date_histogram', field: '@timestamp', id: '3' }, + ], + }, + 100, + '1000' + ); + + const firstLevel = query.aggs['2']; + expect(firstLevel.terms.min_doc_count).toBe('$min_doc_count'); + }); + it('with metric percentiles', () => { const query = builder.build( {