Skip to content

Commit

Permalink
Add test for previously broken behaviour on dotted array field
Browse files Browse the repository at this point in the history
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 elastic#79922

This commit adds a test for that scenario and verifies that the bug is fixed.

Closes elastic#65333
  • Loading branch information
javanna committed Mar 17, 2022
1 parent 4a26ed2 commit f8760b9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package org.elasticsearch.index.mapper;

import org.apache.lucene.index.IndexableField;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentHelper;
Expand All @@ -18,6 +20,7 @@
import java.time.Instant;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -796,4 +799,24 @@ public void testDynamicRuntimeDotsInFieldNames() throws IOException {
}
}"""), Strings.toString(doc.dynamicMappingsUpdate()));
}

//test for https://github.com/elastic/elasticsearch/issues/65333
public void testDottedFieldDynamicFalse() throws IOException {
DocumentMapper defaultMapper = createDocumentMapper(
dynamicMapping("false", b -> b.startObject("myfield").field("type", "keyword").endObject())
);

ParsedDocument doc = defaultMapper.parse(source(b -> {
b.field("myfield", "value1");
b.array("something.myfield", "value2", "value3");
}));

assertThat(doc.rootDoc().getFields("myfield"), arrayWithSize(2));
for (IndexableField field : doc.rootDoc().getFields("myfield")) {
assertThat(field.binaryValue(), equalTo(new BytesRef("value1")));
}
assertThat(doc.rootDoc().getFields("something.myfield"), arrayWithSize(0));

assertNull(doc.dynamicMappingsUpdate());
}
}

0 comments on commit f8760b9

Please sign in to comment.