Skip to content

Commit 3a5a4ea

Browse files
authored
Add test for previously broken behaviour on dotted array field (#85081)
Previously, when using dynamic: false, an array field with a dot in its name, whose suffix matched a mapped field’s name, had its values merged with the mapped field unexpectedly. This has been fixed by #79922 This commit adds a test for that scenario and verifies that the bug is fixed. Closes #65333
1 parent b9f7e45 commit 3a5a4ea

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
package org.elasticsearch.index.mapper;
99

10+
import org.apache.lucene.index.IndexableField;
11+
import org.apache.lucene.util.BytesRef;
1012
import org.elasticsearch.common.Strings;
1113
import org.elasticsearch.common.bytes.BytesReference;
1214
import org.elasticsearch.common.xcontent.XContentHelper;
@@ -18,6 +20,7 @@
1820
import java.time.Instant;
1921

2022
import static org.hamcrest.CoreMatchers.containsString;
23+
import static org.hamcrest.Matchers.arrayWithSize;
2124
import static org.hamcrest.Matchers.equalTo;
2225
import static org.hamcrest.Matchers.instanceOf;
2326
import static org.hamcrest.Matchers.not;
@@ -796,4 +799,25 @@ public void testDynamicRuntimeDotsInFieldNames() throws IOException {
796799
}
797800
}"""), Strings.toString(doc.dynamicMappingsUpdate()));
798801
}
802+
803+
// test for https://github.com/elastic/elasticsearch/issues/65333
804+
public void testDottedFieldDynamicFalse() throws IOException {
805+
DocumentMapper defaultMapper = createDocumentMapper(
806+
dynamicMapping("false", b -> b.startObject("myfield").field("type", "keyword").endObject())
807+
);
808+
809+
ParsedDocument doc = defaultMapper.parse(source(b -> {
810+
b.field("myfield", "value1");
811+
b.array("something.myfield", "value2", "value3");
812+
}));
813+
814+
assertThat(doc.rootDoc().getFields("myfield"), arrayWithSize(2));
815+
for (IndexableField field : doc.rootDoc().getFields("myfield")) {
816+
assertThat(field.binaryValue(), equalTo(new BytesRef("value1")));
817+
}
818+
// dynamic is false, so `something.myfield` should be ignored entirely. It used to be merged with myfield by mistake.
819+
assertThat(doc.rootDoc().getFields("something.myfield"), arrayWithSize(0));
820+
821+
assertNull(doc.dynamicMappingsUpdate());
822+
}
799823
}

0 commit comments

Comments
 (0)