1919import org .elasticsearch .logsdb .datageneration .DataGeneratorSpecification ;
2020import org .elasticsearch .logsdb .datageneration .DocumentGenerator ;
2121import org .elasticsearch .logsdb .datageneration .FieldType ;
22+ import org .elasticsearch .logsdb .datageneration .Mapping ;
2223import org .elasticsearch .logsdb .datageneration .MappingGenerator ;
2324import org .elasticsearch .logsdb .datageneration .Template ;
2425import org .elasticsearch .logsdb .datageneration .datasource .DataSourceHandler ;
@@ -72,9 +73,13 @@ public DataSourceResponse.ObjectMappingParametersGenerator handle(
7273
7374 public void testBlockLoader () throws IOException {
7475 var template = new Template (Map .of (fieldName , new Template .Leaf (fieldName , fieldType )));
75- runTest (template , fieldName );
76+ var syntheticSource = randomBoolean ();
77+ var mapping = mappingGenerator .generate (template );
78+
79+ runTest (template , mapping , syntheticSource , fieldName );
7680 }
7781
82+ @ SuppressWarnings ("unchecked" )
7883 public void testBlockLoaderForFieldInObject () throws IOException {
7984 int depth = randomIntBetween (0 , 3 );
8085
@@ -94,14 +99,24 @@ public void testBlockLoaderForFieldInObject() throws IOException {
9499 fullFieldName .append ('.' ).append (fieldName );
95100 currentLevel .put (fieldName , new Template .Leaf (fieldName , fieldType ));
96101 var template = new Template (top );
97- runTest (template , fullFieldName .toString ());
98- }
99102
100- private void runTest (Template template , String fieldName ) throws IOException {
103+ var syntheticSource = randomBoolean ();
104+
101105 var mapping = mappingGenerator .generate (template );
106+
107+ if (syntheticSource && randomBoolean ()) {
108+ // force fallback synthetic source in the hierarchy
109+ var docMapping = (Map <String , Object >) mapping .raw ().get ("_doc" );
110+ var topLevelMapping = (Map <String , Object >) ((Map <String , Object >) docMapping .get ("properties" )).get ("top" );
111+ topLevelMapping .put ("synthetic_source_keep" , "all" );
112+ }
113+
114+ runTest (template , mapping , syntheticSource , fullFieldName .toString ());
115+ }
116+
117+ private void runTest (Template template , Mapping mapping , boolean syntheticSource , String fieldName ) throws IOException {
102118 var mappingXContent = XContentBuilder .builder (XContentType .JSON .xContent ()).map (mapping .raw ());
103119
104- var syntheticSource = randomBoolean ();
105120 var mapperService = syntheticSource ? createSytheticSourceMapperService (mappingXContent ) : createMapperService (mappingXContent );
106121
107122 var document = documentGenerator .generate (template , mapping );
0 commit comments