@@ -2596,6 +2596,59 @@ public void testComposableTemplateWithSubobjectsFalse() throws Exception {
25962596 );
25972597 }
25982598
2599+ public void testComposableTemplateWithSubobjectsFalseObjectAndSubfield () throws Exception {
2600+ MetadataIndexTemplateService service = getMetadataIndexTemplateService ();
2601+ ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ()).build ();
2602+
2603+ ComponentTemplate subobjects = new ComponentTemplate (new Template (null , new CompressedXContent ("""
2604+ {
2605+ "properties": {
2606+ "foo": {
2607+ "type": "object",
2608+ "subobjects": false
2609+ },
2610+ "foo.bar": {
2611+ "type": "keyword"
2612+ }
2613+ }
2614+ }
2615+ """ ), null ), null , null );
2616+
2617+ project = service .addComponentTemplate (project , true , "subobjects" , subobjects );
2618+ ComposableIndexTemplate it = ComposableIndexTemplate .builder ()
2619+ .indexPatterns (List .of ("test-*" ))
2620+ .template (new Template (null , null , null ))
2621+ .componentTemplates (List .of ("subobjects" , "field_mapping" ))
2622+ .priority (0L )
2623+ .version (1L )
2624+ .build ();
2625+ project = service .addIndexTemplateV2 (project , true , "composable-template" , it );
2626+
2627+ List <CompressedXContent > mappings = MetadataIndexTemplateService .collectMappings (project , "composable-template" , "test-index" );
2628+
2629+ assertNotNull (mappings );
2630+ assertThat (mappings .size (), equalTo (1 ));
2631+ List <Map <String , Object >> parsedMappings = mappings .stream ().map (m -> {
2632+ try {
2633+ return MapperService .parseMapping (NamedXContentRegistry .EMPTY , m );
2634+ } catch (Exception e ) {
2635+ logger .error (e );
2636+ fail ("failed to parse mappings: " + m .string ());
2637+ return null ;
2638+ }
2639+ }).toList ();
2640+
2641+ assertThat (
2642+ parsedMappings .get (0 ),
2643+ equalTo (
2644+ Map .of (
2645+ "_doc" ,
2646+ Map .of ("properties" , Map .of ("foo.bar" , Map .of ("type" , "keyword" ), "foo" , Map .of ("type" , "object" , "subobjects" , false )))
2647+ )
2648+ )
2649+ );
2650+ }
2651+
25992652 public void testAddIndexTemplateWithDeprecatedComponentTemplate () throws Exception {
26002653 ProjectMetadata project = ProjectMetadata .builder (randomProjectIdOrDefault ()).build ();
26012654 MetadataIndexTemplateService service = getMetadataIndexTemplateService ();
0 commit comments