Use new date_histogram intervals in timelion (#77160)

This commit is contained in:
Tim Roes 2020-09-10 16:06:41 +02:00 committed by GitHub
parent 8ad47846ca
commit 100afab308
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -100,9 +100,17 @@ describe('es', () => {
expect(agg.time_buckets.date_histogram.time_zone).to.equal('Etc/UTC');
});
it('sets the field and interval', () => {
it('sets the field', () => {
expect(agg.time_buckets.date_histogram.field).to.equal('@timestamp');
expect(agg.time_buckets.date_histogram.interval).to.equal('1y');
});
it('sets the interval for calendar_interval correctly', () => {
expect(agg.time_buckets.date_histogram).to.have.property('calendar_interval', '1y');
});
it('sets the interval for fixed_interval correctly', () => {
const a = createDateAgg({ timefield: '@timestamp', interval: '24h' }, tlConfig);
expect(a.time_buckets.date_histogram).to.have.property('fixed_interval', '24h');
});
it('sets min_doc_count to 0', () => {

View file

@ -19,6 +19,8 @@
import _ from 'lodash';
import { buildAggBody } from './agg_body';
import { search } from '../../../../../../plugins/data/server';
const { dateHistogramInterval } = search.aggs;
export default function createDateAgg(config, tlConfig, scriptedFields) {
const dateAgg = {
@ -26,13 +28,13 @@ export default function createDateAgg(config, tlConfig, scriptedFields) {
meta: { type: 'time_buckets' },
date_histogram: {
field: config.timefield,
interval: config.interval,
time_zone: tlConfig.time.timezone,
extended_bounds: {
min: tlConfig.time.from,
max: tlConfig.time.to,
},
min_doc_count: 0,
...dateHistogramInterval(config.interval),
},
},
};