mirror of
https://github.com/grafana/grafana.git
synced 2025-01-24 23:37:01 -06:00
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
This commit is contained in:
parent
048f6f5301
commit
03f7fd0527
@ -116,7 +116,7 @@
|
||||
<div class="gf-form offset-width-7">
|
||||
<label class="gf-form-label width-10">Min Doc Count</label>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
class="gf-form-input max-width-12"
|
||||
ng-model="agg.settings.min_doc_count"
|
||||
ng-blur="onChangeInternal()"
|
||||
@ -153,7 +153,7 @@
|
||||
<div class="gf-form offset-width-7">
|
||||
<label class="gf-form-label width-10">Min Doc Count</label>
|
||||
<input
|
||||
type="number"
|
||||
type="text"
|
||||
class="gf-form-input max-width-12"
|
||||
ng-model="agg.settings.min_doc_count"
|
||||
ng-blur="onChangeInternal()"
|
||||
|
@ -55,6 +55,10 @@ export class ElasticQueryBuilder {
|
||||
|
||||
if (aggDef.settings.min_doc_count !== void 0) {
|
||||
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) {
|
||||
|
@ -103,6 +103,50 @@ describe('ElasticQueryBuilder', () => {
|
||||
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(
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user