|
7 | 7 | */
|
8 | 8 | package org.elasticsearch.index.mapper;
|
9 | 9 |
|
| 10 | +import org.apache.lucene.index.IndexableField; |
| 11 | +import org.apache.lucene.util.BytesRef; |
10 | 12 | import org.elasticsearch.common.Strings;
|
11 | 13 | import org.elasticsearch.common.bytes.BytesReference;
|
12 | 14 | import org.elasticsearch.common.xcontent.XContentHelper;
|
|
18 | 20 | import java.time.Instant;
|
19 | 21 |
|
20 | 22 | import static org.hamcrest.CoreMatchers.containsString;
|
| 23 | +import static org.hamcrest.Matchers.arrayWithSize; |
21 | 24 | import static org.hamcrest.Matchers.equalTo;
|
22 | 25 | import static org.hamcrest.Matchers.instanceOf;
|
23 | 26 | import static org.hamcrest.Matchers.not;
|
@@ -796,4 +799,25 @@ public void testDynamicRuntimeDotsInFieldNames() throws IOException {
|
796 | 799 | }
|
797 | 800 | }"""), Strings.toString(doc.dynamicMappingsUpdate()));
|
798 | 801 | }
|
| 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 | + } |
799 | 823 | }
|
0 commit comments