Skip to content

Commit a2a7120

Browse files
author
elasticsearchmachine
committed
Merge remote-tracking branch 'origin/main' into lucene_snapshot
2 parents 8edbe11 + 4ef5ea6 commit a2a7120

File tree

12 files changed

+31
-45
lines changed

12 files changed

+31
-45
lines changed

docs/reference/mapping/types/date.asciidoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ The following parameters are accepted by `date` fields:
125125
`locale`::
126126

127127
The locale to use when parsing dates since months do not have the same names
128-
and/or abbreviations in all languages. The default is the
129-
https://docs.oracle.com/javase/8/docs/api/java/util/Locale.html#ROOT[`ROOT` locale].
128+
and/or abbreviations in all languages. The default is ENGLISH.
130129

131130
<<ignore-malformed,`ignore_malformed`>>::
132131

modules/aggregations/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ dependencies {
4848

4949
tasks.named("yamlRestCompatTestTransform").configure({ task ->
5050
task.skipTest("aggregations/date_agg_per_day_of_week/Date aggregartion per day of week", "week-date behaviour has changed")
51+
task.skipTest("aggregations/stats_metric_fail_formatting/fail formatting", "locale has changed")
5152
})

modules/aggregations/src/test/java/org/elasticsearch/aggregations/bucket/histogram/InternalAutoDateHistogramTests.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.aggregations.bucket.histogram;
1111

12-
import org.elasticsearch.TransportVersion;
1312
import org.elasticsearch.TransportVersions;
1413
import org.elasticsearch.aggregations.bucket.AggregationMultiBucketAggregationTestCase;
1514
import org.elasticsearch.aggregations.bucket.histogram.AutoDateHistogramAggregationBuilder.RoundingInfo;
@@ -28,7 +27,6 @@
2827
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
2928
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
3029
import org.elasticsearch.test.InternalAggregationTestCase;
31-
import org.elasticsearch.test.TransportVersionUtils;
3230

3331
import java.io.IOException;
3432
import java.time.Instant;
@@ -459,33 +457,6 @@ public void testCreateWithReplacementBuckets() {
459457
assertThat(copy.getInterval(), equalTo(orig.getInterval()));
460458
}
461459

462-
public void testSerializationPre830() throws IOException {
463-
// we need to test without sub-aggregations, otherwise we need to also update the interval within the inner aggs
464-
InternalAutoDateHistogram instance = createTestInstance(
465-
randomAlphaOfLengthBetween(3, 7),
466-
createTestMetadata(),
467-
InternalAggregations.EMPTY
468-
);
469-
TransportVersion version = TransportVersionUtils.randomVersionBetween(
470-
random(),
471-
TransportVersions.MINIMUM_COMPATIBLE,
472-
TransportVersionUtils.getPreviousVersion(TransportVersions.V_8_3_0)
473-
);
474-
InternalAutoDateHistogram deserialized = copyInstance(instance, version);
475-
assertEquals(1, deserialized.getBucketInnerInterval());
476-
477-
InternalAutoDateHistogram modified = new InternalAutoDateHistogram(
478-
deserialized.getName(),
479-
deserialized.getBuckets(),
480-
deserialized.getTargetBuckets(),
481-
deserialized.getBucketInfo(),
482-
deserialized.getFormatter(),
483-
deserialized.getMetadata(),
484-
instance.getBucketInnerInterval()
485-
);
486-
assertEqualInstances(instance, modified);
487-
}
488-
489460
public void testReadFromPre830() throws IOException {
490461
byte[] bytes = Base64.getDecoder()
491462
.decode(

modules/aggregations/src/yamlRestTest/resources/rest-api-spec/test/aggregations/stats_metric_fail_formatting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ setup:
3030
cluster_features: "gte_v8.15.0"
3131
reason: fixed in 8.15.0
3232
- do:
33-
catch: /Cannot format stat \[sum\] with format \[DocValueFormat.DateTime\(format\[date_hour_minute_second_millis\] locale\[\], Z, MILLISECONDS\)\]/
33+
catch: /Cannot format stat \[sum\] with format \[DocValueFormat.DateTime\(format\[date_hour_minute_second_millis\] locale\[en\], Z, MILLISECONDS\)\]/
3434
search:
3535
index: test_date
3636
body:

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ static TransportVersion def(int id) {
234234
public static final TransportVersion RRF_QUERY_REWRITE = def(8_758_00_0);
235235
public static final TransportVersion SEARCH_FAILURE_STATS = def(8_759_00_0);
236236
public static final TransportVersion INGEST_GEO_DATABASE_PROVIDERS = def(8_760_00_0);
237+
public static final TransportVersion DATE_TIME_DOC_VALUES_LOCALES = def(8_761_00_0);
237238

238239
/*
239240
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/common/util/LocaleUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ private static Locale parseParts(String[] parts) {
6868
switch (parts.length) {
6969
case 3:
7070
// lang, country, variant
71-
return new Locale(parts[0], parts[1], parts[2]);
71+
return Locale.of(parts[0], parts[1], parts[2]);
7272
case 2:
7373
// lang, country
74-
return new Locale(parts[0], parts[1]);
74+
return Locale.of(parts[0], parts[1]);
7575
case 1:
7676
if ("ROOT".equalsIgnoreCase(parts[0])) {
7777
return Locale.ROOT;
7878
}
7979
// lang
80-
return new Locale(parts[0]);
80+
return Locale.of(parts[0]);
8181
default:
8282
throw new IllegalArgumentException(
8383
"Locales can have at most 3 parts but got " + parts.length + ": " + Arrays.asList(parts)

server/src/main/java/org/elasticsearch/index/mapper/DataStreamTimestampFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ public void doValidate(MappingLookup lookup) {
165165
Map<?, ?> configuredSettings = XContentHelper.convertToMap(BytesReference.bytes(builder), false, XContentType.JSON).v2();
166166
configuredSettings = (Map<?, ?>) configuredSettings.values().iterator().next();
167167

168-
// Only type, meta and format attributes are allowed:
168+
// Only type, meta, format, and locale attributes are allowed:
169169
configuredSettings.remove("type");
170170
configuredSettings.remove("meta");
171171
configuredSettings.remove("format");
172+
configuredSettings.remove("locale");
172173

173174
// ignoring malformed values is disallowed (see previous check),
174175
// however if `index.mapping.ignore_malformed` has been set to true then

server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,16 @@ public final class DateFieldMapper extends FieldMapper {
8080

8181
public static final String CONTENT_TYPE = "date";
8282
public static final String DATE_NANOS_CONTENT_TYPE = "date_nanos";
83-
public static final DateFormatter DEFAULT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_optional_time||epoch_millis");
83+
public static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
84+
// although the locale doesn't affect the results, tests still check formatter equality, which does include locale
85+
public static final DateFormatter DEFAULT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_optional_time||epoch_millis")
86+
.withLocale(DEFAULT_LOCALE);
8487
public static final DateFormatter DEFAULT_DATE_TIME_NANOS_FORMATTER = DateFormatter.forPattern(
8588
"strict_date_optional_time_nanos||epoch_millis"
86-
);
87-
private static final DateMathParser EPOCH_MILLIS_PARSER = DateFormatter.forPattern("epoch_millis").toDateMathParser();
89+
).withLocale(DEFAULT_LOCALE);
90+
private static final DateMathParser EPOCH_MILLIS_PARSER = DateFormatter.forPattern("epoch_millis")
91+
.withLocale(DEFAULT_LOCALE)
92+
.toDateMathParser();
8893

8994
public enum Resolution {
9095
MILLISECONDS(CONTENT_TYPE, NumericType.DATE, DateMillisDocValuesField::new) {
@@ -233,7 +238,7 @@ public static final class Builder extends FieldMapper.Builder {
233238
private final Parameter<Locale> locale = new Parameter<>(
234239
"locale",
235240
false,
236-
() -> Locale.ROOT,
241+
() -> DEFAULT_LOCALE,
237242
(n, c, o) -> LocaleUtils.parse(o.toString()),
238243
m -> toType(m).locale,
239244
(xContentBuilder, n, v) -> xContentBuilder.field(n, v.toString()),

server/src/main/java/org/elasticsearch/index/mapper/DateScriptFieldType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private static class Builder extends AbstractScriptFieldType.Builder<DateFieldSc
6969
(n, c, o) -> o == null ? null : LocaleUtils.parse(o.toString()),
7070
RuntimeField.initializerNotSupported(),
7171
(b, n, v) -> {
72-
if (v != null && false == v.equals(Locale.ROOT)) {
72+
if (v != null && false == v.equals(DateFieldMapper.DEFAULT_LOCALE)) {
7373
b.field(n, v.toString());
7474
}
7575
},
@@ -97,7 +97,7 @@ protected AbstractScriptFieldType<?> createFieldType(
9797
OnScriptError onScriptError
9898
) {
9999
String pattern = format.getValue() == null ? DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.pattern() : format.getValue();
100-
Locale locale = this.locale.getValue() == null ? Locale.ROOT : this.locale.getValue();
100+
Locale locale = this.locale.getValue() == null ? DateFieldMapper.DEFAULT_LOCALE : this.locale.getValue();
101101
DateFormatter dateTimeFormatter = DateFormatter.forPattern(pattern, supportedVersion).withLocale(locale);
102102
return new DateScriptFieldType(name, factory, dateTimeFormatter, script, meta, onScriptError);
103103
}

server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class RangeFieldMapper extends FieldMapper {
5959

6060
public static class Defaults {
6161
public static final DateFormatter DATE_FORMATTER = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
62+
public static final Locale LOCALE = DateFieldMapper.DEFAULT_LOCALE;
6263
}
6364

6465
// this is private since it has a different default
@@ -83,7 +84,7 @@ public static class Builder extends FieldMapper.Builder {
8384
private final Parameter<Locale> locale = new Parameter<>(
8485
"locale",
8586
false,
86-
() -> Locale.ROOT,
87+
() -> Defaults.LOCALE,
8788
(n, c, o) -> LocaleUtils.parse(o.toString()),
8889
m -> toType(m).locale,
8990
(xContentBuilder, n, v) -> xContentBuilder.field(n, v.toString()),

0 commit comments

Comments
 (0)