Skip to content

Commit

Permalink
Use new date_histogram intervals in timelion (#77160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Roes authored Sep 10, 2020
1 parent 8ad4784 commit 100afab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@

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 = {
time_buckets: {
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),
},
},
};
Expand Down

0 comments on commit 100afab

Please sign in to comment.