Commit 03f7fd05 by Marcus Efraimsson Committed by GitHub

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
parent 048f6f53
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
<div class="gf-form offset-width-7"> <div class="gf-form offset-width-7">
<label class="gf-form-label width-10">Min Doc Count</label> <label class="gf-form-label width-10">Min Doc Count</label>
<input <input
type="number" type="text"
class="gf-form-input max-width-12" class="gf-form-input max-width-12"
ng-model="agg.settings.min_doc_count" ng-model="agg.settings.min_doc_count"
ng-blur="onChangeInternal()" ng-blur="onChangeInternal()"
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
<div class="gf-form offset-width-7"> <div class="gf-form offset-width-7">
<label class="gf-form-label width-10">Min Doc Count</label> <label class="gf-form-label width-10">Min Doc Count</label>
<input <input
type="number" type="text"
class="gf-form-input max-width-12" class="gf-form-input max-width-12"
ng-model="agg.settings.min_doc_count" ng-model="agg.settings.min_doc_count"
ng-blur="onChangeInternal()" ng-blur="onChangeInternal()"
......
...@@ -55,6 +55,10 @@ export class ElasticQueryBuilder { ...@@ -55,6 +55,10 @@ export class ElasticQueryBuilder {
if (aggDef.settings.min_doc_count !== void 0) { if (aggDef.settings.min_doc_count !== void 0) {
queryNode.terms.min_doc_count = parseInt(aggDef.settings.min_doc_count, 10); queryNode.terms.min_doc_count = parseInt(aggDef.settings.min_doc_count, 10);
if (isNaN(queryNode.terms.min_doc_count)) {
queryNode.terms.min_doc_count = aggDef.settings.min_doc_count;
}
} }
if (aggDef.settings.missing) { if (aggDef.settings.missing) {
......
...@@ -103,6 +103,50 @@ describe('ElasticQueryBuilder', () => { ...@@ -103,6 +103,50 @@ describe('ElasticQueryBuilder', () => {
expect(secondLevel.aggs['5'].avg.field).toBe('@value'); 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', () => { it('with metric percentiles', () => {
const query = builder.build( const query = builder.build(
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment