-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Make range query rounding consistent #50237
Conversation
Currently the rounding for date math used in range queries behaves differently for `date` and `date_range` as explained in elastic#50009. The behaviour on `date` fields is the one we document in https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#range-query-date-math-rounding. This change adapts the rounding behaviour for RangeType.DATE so it uses the same logic as the `date` type. Closes elastic#50009
Pinging @elastic/es-search (:Search/Search) |
Opening as WIP to illustrate the issue better. Original issue needs to be discussed to decide whether we see the current behaviour as a bug, in which case this could be considered a bugfix, or as the standing behaviour, in which case this should be documented as a breaking issue if we want to change it to make the date/date_range behaviour consistent. |
@elasticmachine update branch |
@jpountz thanks for the review, after you took a look I still extended testing a bit by adding some randomized testing to make sure we treat bounds the same on Before this change, a range query with an upper bound not specified up to milliseconds like e.g. The reverse will happen for lower bounds specified with “gt”. Both In order for user keep the current behaviour, they will need to change their
Can you take another look at the test changes and if you think the phrasing in the migration docs is sufficient? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to src/main look good, but I'd like to avoid relying on string representations in tests. Could we instead test a rounded range against the expected non-rounded range, e.g. something like assertEquals(range on "gt 2020-01-20", range on "gt 2020-01-20 23:59:59.999Z")
?
Since this is a bug fix, I think this should get backported to 7.x.
|
||
[float] | ||
==== Consistent rounding of range queries on dates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrase this title, and maybe the paragraph below as well to make it clear that only date ranges changed behavior? A majority of users are using date
fields but only a minority uses date_range
fields, so it would help if users could notice that this change doesn't apply to them only by looking at the title.
@jpountz thanks for the review, I pushed updates to the migration notes and found a way of avoiding relying on string representations in the tests comparing the bounds with the behaviour on the plain |
Looking into elastic#50237 I realized that two of the examples given in the documentation around date math rounding for range queries on date fields using `gt` and `lt` is slightly off by a nanosecond. This PR changes this to the bounds that are currently parsed using these parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two small comments, LGTM otherwise. Thanks for fixing it @cbuescher.
|
||
- do: | ||
search: | ||
rest_total_hits_as_int: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this parameter is supposed to only exist for the 6.x -> 7.x transition, let's use track_total_hits: true
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saw that “rest_total_hits_as_int” is still used all over the place in the yml tests, also in other tests in same test suite. I agree it would be good to get rid of it when its supposed to go away, but I’d like to keep it for consistency with the rest atm. Maybe we should open an issue to clean up all of those in a separate PR?
Currently the rounding used in range queries can behave differently for `date` and `date_range` as explained in elastic#50009. The behaviour on `date` fields is the one we document in https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#range-query-date-math-rounding. This change adapts the rounding behaviour for RangeType.DATE so it uses the same logic as the `date` for the `date_range` type. Closes elastic#50009
) Currently the rounding used in range queries can behave differently for `date` and `date_range` as explained in #50009. The behaviour on `date` fields is the one we document in https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#range-query-date-math-rounding. This change adapts the rounding behaviour for RangeType.DATE so it uses the same logic as the `date` for the `date_range` type. Backport of #50237
Looking into #50237 I realized that two of the examples given in the documentation around date math rounding for range queries on date fields using `gt` and `lt` is slightly off by a nanosecond. This PR changes this to the bounds that are currently parsed using these parameters.
Looking into #50237 I realized that two of the examples given in the documentation around date math rounding for range queries on date fields using `gt` and `lt` is slightly off by a nanosecond. This PR changes this to the bounds that are currently parsed using these parameters.
Looking into #50237 I realized that two of the examples given in the documentation around date math rounding for range queries on date fields using `gt` and `lt` is slightly off by a nanosecond. This PR changes this to the bounds that are currently parsed using these parameters.
Looking into #50237 I realized that two of the examples given in the documentation around date math rounding for range queries on date fields using `gt` and `lt` is slightly off by a nanosecond. This PR changes this to the bounds that are currently parsed using these parameters.
Currently the rounding for date math used in range queries behaves differently
for
date
anddate_range
as explained in #50009. The behaviour ondate
fields is the one we document in
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html#range-query-date-math-rounding.
This change adapts the rounding behaviour for RangeType.DATE so it uses the same
logic as the
date
type.Closes #50009