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? |
jpountz
left a comment
There was a problem hiding this comment.
Thanks for picking this one up! I left some minor comments.
| 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.
Can you move this test to DateFieldMapperTests instead and undo changes to this file?
| 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.
Could you only check the format property and make the error message more specific?
There was a problem hiding this comment.
it is currently a bit confusing since eg. ignore_malformed can be updated
There was a problem hiding this comment.
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.
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.
++, 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 |
jpountz
left a comment
There was a problem hiding this comment.
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
DocumentMapperMergeTestsin format.Closes #25271