File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed
main/java/org/elasticsearch/index/mapper
test/java/org/elasticsearch/index/mapper Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,9 @@ public final void validate(MappingLookup mappers) {
341341 if (mappers .isObjectField (copyTo )) {
342342 throw new IllegalArgumentException ("Cannot copy to field [" + copyTo + "] since it is mapped as an object" );
343343 }
344+ if (mappers .getMapper (copyTo ) == null ){
345+ throw new IllegalArgumentException ("Cannot copy to field [" + copyTo + "] since it is a non existent field" );
346+ }
344347
345348 final String targetScope = mappers .nestedLookup ().getNestedParent (copyTo );
346349 checkNestedScopeCompatibility (sourceScope , targetScope );
Original file line number Diff line number Diff line change @@ -645,6 +645,18 @@ public void testCopyFromMultiField() {
645645 assertThat (e .getMessage (), Matchers .containsString ("[copy_to] may not be used to copy from a multi-field: [field.bar]" ));
646646 }
647647
648+ public void testCopyToNonExistentField () {
649+ Exception e = expectThrows (IllegalArgumentException .class , () -> createDocumentMapper (fieldMapping (b -> {
650+ b .startObject ("test_field" );
651+ {
652+ b .field ("type" , "text" );
653+ b .array ("copy_to" , "missing_field" );
654+ }
655+ b .endObject ();
656+ })));
657+ assertThat (e .getMessage (), Matchers .containsString ("Cannot copy to field [missing_field] since it is a non existent field" ));
658+ }
659+
648660 public void testCopyToDateRangeFailure () throws Exception {
649661 DocumentMapper docMapper = createDocumentMapper (topMapping (b -> {
650662 b .startObject ("properties" );
You can’t perform that action at this time.
0 commit comments