From ff6e5899b279257be90119aa43cc4af1d2825f49 Mon Sep 17 00:00:00 2001 From: Przemyslaw Gomulka Date: Mon, 18 Oct 2021 16:52:20 +0200 Subject: [PATCH] Deprecate resolution loss on date field (#78921) backport(#79355) When storing nanoseconds on a date field the nanosecond part is lost as it cannot be stored. The date_nanos field should be used instead. This commit emits a deprecation warning to notify users about this. closes #37962 backports #78921 --- .../elasticsearch/upgrades/IndexingIT.java | 2 +- .../60_pipeline_timestamp_date_mapping.yml | 2 +- .../49_range_timezone_bug.yml | 2 +- .../index/mapper/DateFieldMapper.java | 52 +++++++++++++++---- .../index/mapper/DynamicFieldsBuilder.java | 3 +- .../index/mapper/MappingParser.java | 3 +- .../MetadataRolloverServiceTests.java | 4 +- .../index/mapper/DateFieldMapperTests.java | 24 +++++++-- .../datastreams/AutoCreateDataStreamIT.java | 5 +- .../ml/transforms/PainlessDomainSplitIT.java | 4 +- .../test/multi_cluster/80_transform.yml | 4 +- .../test/remote_cluster/80_transform.yml | 8 +-- .../continuous/TransformContinuousIT.java | 22 ++++++-- 13 files changed, 101 insertions(+), 34 deletions(-) diff --git a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java index b4b519ce82f30..0be7df8d7eb05 100644 --- a/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java +++ b/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/IndexingIT.java @@ -219,7 +219,7 @@ public void testDateNanosFormatUpgrade() throws IOException { Request index = new Request("POST", "/" + indexName + "/_doc/"); XContentBuilder doc = XContentBuilder.builder(XContentType.JSON.xContent()) .startObject() - .field("date", "2015-01-01T12:10:30.123456789Z") + .field("date", "2015-01-01T12:10:30.123Z") .field("date_nanos", "2015-01-01T12:10:30.123456789Z") .endObject(); index.addParameter("refresh", "true"); diff --git a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/60_pipeline_timestamp_date_mapping.yml b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/60_pipeline_timestamp_date_mapping.yml index 0f514f2213492..a096814689a64 100644 --- a/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/60_pipeline_timestamp_date_mapping.yml +++ b/qa/smoke-test-ingest-with-all-dependencies/src/test/resources/rest-api-spec/test/ingest/60_pipeline_timestamp_date_mapping.yml @@ -9,7 +9,7 @@ index: timetest body: mappings: - "properties": { "my_time": {"type": "date", "format": "strict_date_optional_time_nanos"}} + "properties": { "my_time": {"type": "date_nanos", "format": "strict_date_optional_time_nanos"}} - do: ingest.put_pipeline: diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/49_range_timezone_bug.yml b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/49_range_timezone_bug.yml index 5785015d7eeb6..bb9b910978844 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/49_range_timezone_bug.yml +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/search.aggregation/49_range_timezone_bug.yml @@ -8,7 +8,7 @@ setup: mappings: properties: mydate: - type: date + type: date_nanos format: "uuuu-MM-dd'T'HH:mm:ss.SSSSSSSSSZZZZZ" - do: diff --git a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java index 687eee3af0ee3..890afe4c02f0c 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/DateFieldMapper.java @@ -75,6 +75,7 @@ public final class DateFieldMapper extends FieldMapper { public static final DateFormatter DEFAULT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_optional_time||epoch_millis"); public static final DateFormatter DEFAULT_DATE_TIME_NANOS_FORMATTER = DateFormatter.forPattern("strict_date_optional_time_nanos||epoch_millis"); + private final String indexName; public enum Resolution { MILLISECONDS(CONTENT_TYPE, NumericType.DATE) { @@ -234,6 +235,7 @@ public static class Builder extends FieldMapper.Builder { private final Parameter nullValue = Parameter.stringParam("null_value", false, m -> toType(m).nullValueAsString, null).acceptsNull(); private final Parameter ignoreMalformed; + private String indexName; private final Parameter