Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update datemath expressions #202

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/young-fireants-compete.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 15 additions & 14 deletions packages/provider-elasticsearch/src/utils/dateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is what we want. The last hour no longer means one hour from right now. In general, these changes are not inclusive of the current time which would be misleading for something like bids where you wouldn't want to have to check at the start of the next hour or the next day for something that was actually present right now.

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' },
Expand Down