File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
server/src/test/java/org/elasticsearch/index/mapper/flattened Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -931,6 +931,35 @@ public void testSyntheticSourceWithEmptyObject() throws IOException {
931931 {"field":{"key1":"foo"}}""" ));
932932 }
933933
934+ public void testSyntheticSourceWithMatchesInNestedPath () throws IOException {
935+ DocumentMapper mapper = createSytheticSourceMapperService (
936+ mapping (b -> { b .startObject ("field" ).field ("type" , "flattened" ).endObject (); })
937+ ).documentMapper ();
938+
939+ // This test covers a scenario that previously had a bug.
940+ // Since a.b.c and b.b.d have a matching middle key `b`, and b.b.d starts with a `b`,
941+ // startObject was not called for the first `b` in b.b.d.
942+ // For a full explanation see this comment: https://github.com/elastic/elasticsearch/pull/129600#issuecomment-3024476134
943+ var syntheticSource = syntheticSource (mapper , b -> {
944+ b .startObject ("field" );
945+ {
946+ b .startObject ("a" );
947+ {
948+ b .startObject ("b" ).field ("c" , "1" ).endObject ();
949+ }
950+ b .endObject ();
951+ b .startObject ("b" );
952+ {
953+ b .startObject ("b" ).field ("d" , "2" ).endObject ();
954+ }
955+ b .endObject ();
956+ }
957+ b .endObject ();
958+ });
959+ assertThat (syntheticSource , equalTo ("""
960+ {"field":{"a":{"b":{"c":"1"}},"b":{"b":{"d":"2"}}}}""" ));
961+ }
962+
934963 @ Override
935964 protected boolean supportsCopyTo () {
936965 return false ;
You can’t perform that action at this time.
0 commit comments