2222import java .time .ZoneOffset ;
2323import java .time .format .DateTimeFormatter ;
2424import java .util .HashMap ;
25+ import java .util .List ;
2526import java .util .Locale ;
2627import java .util .Map ;
2728import java .util .function .Supplier ;
@@ -260,29 +261,7 @@ private Supplier<Map<String, Object>> wildcardMapping(boolean hasParent, DataSou
260261 };
261262 }
262263
263- private Map <String , Object > stringSubField (FieldType parent , DataSourceRequest .LeafMappingParametersGenerator request ) {
264- var subFields = new HashMap <FieldType , Supplier <Map <String , Object >>>();
265- subFields .put (FieldType .KEYWORD , () -> {
266- var mapping = keywordMapping (true , request ).get ();
267- mapping .remove ("copy_to" );
268- return mapping ;
269- });
270- subFields .put (FieldType .TEXT , () -> textMapping (true , request ).get ());
271- subFields .put (FieldType .MATCH_ONLY_TEXT , () -> matchOnlyTextMapping (true , request ).get ());
272- subFields .put (FieldType .WILDCARD , () -> wildcardMapping (true , request ).get ());
273-
274- var options = subFields .entrySet ().stream ().filter (e -> e .getKey ().equals (parent ) == false ).toList ();
275- var child = ESTestCase .randomFrom (options );
276- FieldType childType = child .getKey ();
277- var childValue = child .getValue ().get ();
278- childValue .put ("type" , childType .toString ());
279- return Map .of ("subfield_" + childType , childValue );
280- }
281-
282- private Supplier <Map <String , Object >> matchOnlyTextMapping (
283- boolean hasParent ,
284- DataSourceRequest .LeafMappingParametersGenerator request
285- ) {
264+ private Supplier <Map <String , Object >> matchOnlyTextMapping (boolean hasParent , DataSourceRequest .LeafMappingParametersGenerator request ) {
286265 return () -> {
287266 var mapping = new HashMap <String , Object >();
288267 if (hasParent == false && ESTestCase .randomDouble () <= 0.2 ) {
@@ -292,6 +271,26 @@ private Supplier<Map<String, Object>> matchOnlyTextMapping(
292271 };
293272 }
294273
274+ private Map <String , Object > stringSubField (FieldType parent , DataSourceRequest .LeafMappingParametersGenerator request ) {
275+
276+ List <FieldType > stringTypes = List .of (FieldType .TEXT , FieldType .MATCH_ONLY_TEXT , FieldType .KEYWORD , FieldType .WILDCARD );
277+ var childType = ESTestCase .randomValueOtherThan (parent , () -> ESTestCase .randomFrom (stringTypes ));
278+ var child = switch (childType ) {
279+ case TEXT -> textMapping (true , request ).get ();
280+ case MATCH_ONLY_TEXT -> matchOnlyTextMapping (true , request ).get ();
281+ case WILDCARD -> wildcardMapping (true , request ).get ();
282+ case KEYWORD -> {
283+ var mapping = keywordMapping (true , request ).get ();
284+ mapping .remove ("copy_to" );
285+ yield mapping ;
286+ }
287+ default -> throw new AssertionError ("unreachable" );
288+ };
289+
290+ child .put ("type" , childType .toString ());
291+ return Map .of ("subfield_" + childType , child );
292+ }
293+
295294 public static HashMap <String , Object > commonMappingParameters () {
296295 var map = new HashMap <String , Object >();
297296 map .put ("store" , ESTestCase .randomBoolean ());
0 commit comments