-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Fix use of time zone in date_histogram rewrite #31407
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.apache.lucene.search.DocIdSetIterator; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.joda.DateMathParser; | ||
import org.elasticsearch.common.rounding.DateTimeUnit; | ||
import org.elasticsearch.common.rounding.Rounding; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
@@ -33,6 +34,7 @@ | |
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.fielddata.AtomicNumericFieldData; | ||
import org.elasticsearch.index.fielddata.IndexNumericFieldData; | ||
import org.elasticsearch.index.mapper.DateFieldMapper; | ||
import org.elasticsearch.index.mapper.MappedFieldType; | ||
import org.elasticsearch.index.mapper.MappedFieldType.Relation; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
|
@@ -70,6 +72,7 @@ | |
public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuilder<ValuesSource.Numeric, DateHistogramAggregationBuilder> | ||
implements MultiBucketAggregationBuilder { | ||
public static final String NAME = "date_histogram"; | ||
private static DateMathParser DEFAULT_DATE_PARSER = new DateMathParser(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER); | ||
|
||
public static final Map<String, DateTimeUnit> DATE_FIELD_UNITS; | ||
|
||
|
@@ -380,7 +383,7 @@ DateTimeZone rewriteTimeZone(QueryShardContext context) throws IOException { | |
Long anyInstant = null; | ||
final IndexNumericFieldData fieldData = context.getForField(ft); | ||
for (LeafReaderContext ctx : reader.leaves()) { | ||
AtomicNumericFieldData leafFD = ((IndexNumericFieldData) fieldData).load(ctx); | ||
AtomicNumericFieldData leafFD = fieldData.load(ctx); | ||
SortedNumericDocValues values = leafFD.getLongValues(); | ||
if (values.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) { | ||
anyInstant = values.nextValue(); | ||
|
@@ -406,11 +409,10 @@ DateTimeZone rewriteTimeZone(QueryShardContext context) throws IOException { | |
// rounding rounds down, so 'nextTransition' is a good upper bound | ||
final long high = nextTransition; | ||
|
||
final DocValueFormat format = ft.docValueFormat(null, null); | ||
final Object formattedLow = format.format(low); | ||
final Object formattedHigh = format.format(high); | ||
final Object formattedLow = DocValueFormat.RAW.format(low); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the field is a date, it's a bit confusing to use the RAW format imo, maybe use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was even thinking about just boxing the long to a Long because there really isn't much more to it in this case. Would that work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It relies on the assumption that we store millis internally, but I think that's fine. 👍 |
||
final Object formattedHigh = DocValueFormat.RAW.format(high); | ||
if (ft.isFieldWithinQuery(reader, formattedLow, formattedHigh, | ||
true, false, tz, null, context) == Relation.WITHIN) { | ||
true, false, DateTimeZone.UTC, DEFAULT_DATE_PARSER, context) == Relation.WITHIN) { | ||
// All values in this reader have the same offset despite daylight saving times. | ||
// This is very common for location-based timezones such as Europe/Paris in | ||
// combination with time-based indices. | ||
|
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.
Should we use the epoch_millis parser specifically rather than a parser that understands epoch millis among other formats?
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.
I thought I did that, might have not pushed it though because I think it was a late addition. Will do.