diff --git a/.changeset/young-fireants-compete.md b/.changeset/young-fireants-compete.md new file mode 100644 index 000000000..a52f31293 --- /dev/null +++ b/.changeset/young-fireants-compete.md @@ -0,0 +1,5 @@ +--- +'contexture-elasticsearch': patch +--- + +Fixes date math expressions that were missing rounding and 1ms offset. Should improve caching and fix subtle bugs. diff --git a/packages/provider-elasticsearch/src/utils/dateUtil.js b/packages/provider-elasticsearch/src/utils/dateUtil.js index ac66d38af..c5694e83b 100644 --- a/packages/provider-elasticsearch/src/utils/dateUtil.js +++ b/packages/provider-elasticsearch/src/utils/dateUtil.js @@ -27,21 +27,22 @@ let quarterToOffset = { } // https://www.elastic.co/guide/en/elasticsearch/reference/7.x/common-options.html#date-math +// -1ms is because ranges use `<=` and not `<` export let rangeToDatemath = { - last1Hour: { from: 'now-1h', to: 'now' }, - last1Day: { from: 'now-1d', to: 'now' }, - last3Days: { from: 'now-3d', to: 'now' }, - last7Days: { from: 'now-7d', to: 'now' }, - last30Days: { from: 'now-30d', to: 'now' }, - last90Days: { from: 'now-90d', to: 'now' }, - last180Days: { from: 'now-180d', to: 'now' }, - last12Months: { from: 'now/d-12M', to: 'now' }, - last15Months: { from: 'now/d-15M', to: 'now' }, - last18Months: { from: 'now/d-18M', to: 'now' }, - last24Months: { from: 'now/d-24M', to: 'now' }, - last36Months: { from: 'now/d-36M', to: 'now' }, - last48Months: { from: 'now/d-48M', to: 'now' }, - last60Months: { from: 'now/d-60M', to: 'now' }, + last1Hour: { from: 'now/h-1h', to: 'now/h-1ms' }, + last1Day: { from: 'now/d-1d', to: 'now/d-1ms' }, + last3Days: { from: 'now/d-3d', to: 'now/d-1ms' }, + last7Days: { from: 'now/d-7d', to: 'now/d-1ms' }, + last30Days: { from: 'now/d-30d', to: 'now/d-1ms' }, + last90Days: { from: 'now/d-90d', to: 'now/d-1ms' }, + last180Days: { from: 'now/d-180d', to: 'now/d-1ms' }, + last12Months: { from: 'now/d-12M', to: 'now/d-1ms' }, + last15Months: { from: 'now/d-15M', to: 'now/d-1ms' }, + last18Months: { from: 'now/d-18M', to: 'now/d-1ms' }, + last24Months: { from: 'now/d-24M', to: 'now/d-1ms' }, + last36Months: { from: 'now/d-36M', to: 'now/d-1ms' }, + last48Months: { from: 'now/d-48M', to: 'now/d-1ms' }, + last60Months: { from: 'now/d-60M', to: 'now/d-1ms' }, lastCalendarMonth: { from: 'now-1M/M', to: 'now/M-1ms' }, lastCalendarYear: { from: 'now-1y/y', to: 'now/y-1ms' }, thisCalendarMonth: { from: 'now/M', to: 'now+1M/M-1ms' },