-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Disable date field mapping changing #25285
Conversation
Make date field mapping unchangeable. Closes elastic#25271
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
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.
Thanks for picking this one up! I left some minor comments.
@@ -296,4 +298,24 @@ public void testMergeAddingParent() throws IOException { | |||
Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(updatedMapper.mapping(), false)); | |||
assertThat(e.getMessage(), containsString("The _parent field's type option can't be changed: [null]->[parent]")); | |||
} | |||
|
|||
public void testMergeDate() throws IOException { |
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.
Can you move this test to DateFieldMapperTests
instead and undo changes to this file?
@@ -490,8 +490,10 @@ protected void parseCreateField(ParseContext context, List<IndexableField> field | |||
|
|||
@Override | |||
protected void doMerge(Mapper mergeWith, boolean updateAllTypes) { | |||
final DateFieldMapper other = (DateFieldMapper) mergeWith; | |||
if (!this.fieldType().equals(other.fieldType())) | |||
throw new IllegalArgumentException("date field cannot be updated"); |
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.
Could you only check the format
property and make the error message more specific?
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.
it is currently a bit confusing since eg. ignore_malformed
can be updated
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.
Thx for your comments, I modified the error message and specified it's date field's format which cannot be updated. And the fieldType()
's equals()
method has been re-implemented to just compare the format of a Date, isn't it ?
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.
it also checks for other properties through the super.equals call
.endObject().endObject().endObject().string(); | ||
DocumentMapper updateFormatMapper = parser.parse("movie", new CompressedXContent(updateFormatMapping)); | ||
|
||
Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(updateFormatMapper.mapping(), false)); |
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.
++, thanks for using expectThrows
Sorry but I just realized there is a better way of doing that, which is by changing |
Yes I noticed that we also did this in |
@PnPie Sorry for the late reply, I was absent lately. Your PR looks good but I think it is not necessary to call checkComtpatibility as part of |
I deleted the |
I think you need to change the test to call diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java
index 448538b..fac4e7c 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java
@@ -25,6 +25,7 @@ import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexService;
+import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESSingleNodeTestCase;
import org.elasticsearch.test.InternalSettingsPlugin;
@@ -352,7 +353,8 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
.startObject("properties")
.startObject("release_date").field("type", "date").field("format", "yyyy/MM/dd").endObject()
.endObject().endObject().endObject().string();
- DocumentMapper initMapper = parser.parse("movie", new CompressedXContent(initMapping));
+ DocumentMapper initMapper = indexService.mapperService().merge("movie", new CompressedXContent(initMapping),
+ MergeReason.MAPPING_UPDATE, randomBoolean());
assertThat(initMapper.mappers().getMapper("release_date"), notNullValue());
assertFalse(initMapper.mappers().getMapper("release_date").fieldType().stored());
@@ -361,9 +363,11 @@ public class DateFieldMapperTests extends ESSingleNodeTestCase {
.startObject("properties")
.startObject("release_date").field("type", "date").field("format", "epoch_millis").endObject()
.endObject().endObject().endObject().string();
- DocumentMapper updateFormatMapper = parser.parse("movie", new CompressedXContent(updateFormatMapping));
- Exception e = expectThrows(IllegalArgumentException.class, () -> initMapper.merge(updateFormatMapper.mapping(), false));
+
+ Exception e = expectThrows(IllegalArgumentException.class,
+ () -> indexService.mapperService().merge("movie", new CompressedXContent(updateFormatMapping),
+ MergeReason.MAPPING_UPDATE, randomBoolean()));
assertThat(e.getMessage(), containsString("Merge conflits: [mapper [release_date] has different [format] values]"));
}
} |
@jpountz Sorry I saw that the |
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.
No need to be sorry! It looks good, I'll check that tests pass and merge. Thanks!
@elasticmachine please test it |
The test failure looks unrelated so I'll merge. Thanks @PnPie! |
Make date field mapping unchangeable. Closes #25271
* master: (42 commits) Harden global checkpoint tracker Remove deprecated created and found from index, delete and bulk (elastic#25516) fix testEnsureVersionCompatibility for 5.5.0 release fix Version.v6_0_0 min compatibility version to 5.5.0 Add bwc indices for 5.5.0 Add v5_5_1 constant [DOCS] revise high level client Search Scroll API docs (elastic#25599) Improve REST error handling when endpoint does not support HTTP verb, add OPTIONS support (elastic#24437) Avoid SecurityException in repository-S3 on DefaultS3OutputStream.flush() (elastic#25254) [Tests] Add tests for CompletionSuggestionBuilder#build() (elastic#25575) Enable cross-setting validation [Docs] Fix typo in bootstrap-checks.asciidoc (elastic#25597) Index ids in binary form. (elastic#25352) bwc checkout should fetch from all remotes IndexingIT should check for global checkpoints regardless of master version [Tests] Add tests for PhraseSuggestionBuilder#build() (elastic#25571) Remove unused class MinimalMap (elastic#25590) [Docs] Document Scroll API for Java High Level REST Client (elastic#25554) Disable date field mapping changing (elastic#25285) Allow BWC Testing against a specific branch (elastic#25510) ...
With this commit we remove a leftover in the docs about the `format` field being updateable. This is not true since we removed support for updates in elastic#25285. Closes elastic#33986 Relates elastic#25285
Disable date field changing in mapping.
I also modified a little
DocumentMapperMergeTests
in format.Closes #25271