Skip to content

dateHistogramAggregation constructor still uses deprecated interval field, breaks on Elasticsearch 8 #222

@elishas

Description

@elishas

The third parameter of dateHistogramAggregation(name, field, interval) sets the interval field in the query body, which was deprecated in Elasticsearch 7.2 and removed in Elasticsearch 8.

esb.dateHistogramAggregation('dateHistogram', 'time', '1h').toJSON()
// Produces: { date_histogram: { field: 'time', interval: '1h' } }
// ES8 rejects this with: x_content_parse_exception: unknown field [interval] did you mean [fixed_interval]?
The library already has .fixedInterval() and .calendarInterval() methods on the DateHistogramAggregation class, but the constructor and .interval() method still use the deprecated field. This means any code using the third constructor parameter breaks on ES8.

The third parameter of dateHistogramAggregation(name, field, interval) sets the interval field in the query body, which was deprecated in Elasticsearch 7.2 and removed in Elasticsearch 8.

esb.dateHistogramAggregation('dateHistogram', 'time', '1h').toJSON()
// Produces: { date_histogram: { field: 'time', interval: '1h' } }
// ES8 rejects this with: x_content_parse_exception: unknown field [interval] did you mean [fixed_interval]?
The library already has .fixedInterval() and .calendarInterval() methods on the DateHistogramAggregation class, but the constructor and .interval() method still use the deprecated field. This means any code using the third constructor parameter breaks on ES8.

Expected behavior:

The constructor should use fixed_interval (or intelligently pick between fixed_interval and calendar_interval based on the value) instead of the deprecated interval field. At minimum, the deprecated interval parameter should be documented as ES7-only.

Suggested fix:

In histogram-aggregation-base.js, the constructor sets:

if (!_.isNil(interval)) this._aggsDef.interval = interval;
For DateHistogramAggregation, this could be overridden to use fixed_interval instead, or the constructor could accept an options object to specify which interval type to use.

Workaround:

Don't pass the interval as the third parameter. Instead, call the methods explicitly:

// Instead of:
esb.dateHistogramAggregation('dateHistogram', 'time', '1h')

// Use:
esb.dateHistogramAggregation('dateHistogram', 'time').fixedInterval('1h')
// or
esb.dateHistogramAggregation('dateHistogram', 'time').calendarInterval('hour')
Environment:

elastic-builder: 4.1.0 (also affects 2.x and 3.x)
Elasticsearch: 8.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions