@@ -178,6 +178,14 @@ private MapperService createMapperService(
178178 ) throws IOException {
179179 validateIndexVersion (minIndexVersion , useLegacyFormat );
180180 IndexVersion indexVersion = IndexVersionUtils .randomVersionBetween (random (), minIndexVersion , maxIndexVersion );
181+ return createMapperServiceWithIndexVersion (mappings , useLegacyFormat , indexVersion );
182+ }
183+
184+ private MapperService createMapperServiceWithIndexVersion (
185+ XContentBuilder mappings ,
186+ boolean useLegacyFormat ,
187+ IndexVersion indexVersion
188+ ) throws IOException {
181189 var settings = Settings .builder ()
182190 .put (IndexMetadata .SETTING_INDEX_VERSION_CREATED .getKey (), indexVersion )
183191 .put (InferenceMetadataFieldsMapper .USE_LEGACY_SEMANTIC_TEXT_FORMAT .getKey (), useLegacyFormat )
@@ -517,7 +525,8 @@ public void testDynamicUpdate() throws IOException {
517525 inferenceId ,
518526 new MinimalServiceSettings ("service" , TaskType .SPARSE_EMBEDDING , null , null , null )
519527 );
520- assertSemanticTextField (mapperService , fieldName , true , null , null );
528+ var expectedIndexOptions = getDefaultSparseVectorIndexOptionsForMapper (mapperService );
529+ assertSemanticTextField (mapperService , fieldName , true , null , expectedIndexOptions );
521530 assertInferenceEndpoints (mapperService , fieldName , inferenceId , inferenceId );
522531 }
523532
@@ -528,7 +537,8 @@ public void testDynamicUpdate() throws IOException {
528537 searchInferenceId ,
529538 new MinimalServiceSettings ("service" , TaskType .SPARSE_EMBEDDING , null , null , null )
530539 );
531- assertSemanticTextField (mapperService , fieldName , true , null , null );
540+ var expectedIndexOptions = getDefaultSparseVectorIndexOptionsForMapper (mapperService );
541+ assertSemanticTextField (mapperService , fieldName , true , null , expectedIndexOptions );
532542 assertInferenceEndpoints (mapperService , fieldName , inferenceId , searchInferenceId );
533543 }
534544 }
@@ -918,6 +928,8 @@ private static void assertInferenceEndpoints(
918928
919929 public void testSuccessfulParse () throws IOException {
920930 for (int depth = 1 ; depth < 4 ; depth ++) {
931+ final IndexVersion indexVersion = SemanticInferenceMetadataFieldsMapperTests .getRandomCompatibleIndexVersion (useLegacyFormat );
932+
921933 final String fieldName1 = randomFieldName (depth );
922934 final String fieldName2 = randomFieldName (depth + 1 );
923935 final String searchInferenceId = randomAlphaOfLength (8 );
@@ -950,15 +962,23 @@ public void testSuccessfulParse() throws IOException {
950962 );
951963 });
952964
953- MapperService mapperService = createMapperService (mapping , useLegacyFormat );
954- assertSemanticTextField (mapperService , fieldName1 , true , null , indexOptions );
965+ var expectedIndexOptions = indexOptions ;
966+ if (expectedIndexOptions == null ) {
967+ expectedIndexOptions = new SemanticTextIndexOptions (
968+ SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR ,
969+ SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion )
970+ );
971+ }
972+
973+ MapperService mapperService = createMapperServiceWithIndexVersion (mapping , useLegacyFormat , indexVersion );
974+ assertSemanticTextField (mapperService , fieldName1 , true , null , expectedIndexOptions );
955975 assertInferenceEndpoints (
956976 mapperService ,
957977 fieldName1 ,
958978 model1 .getInferenceEntityId (),
959979 setSearchInferenceId ? searchInferenceId : model1 .getInferenceEntityId ()
960980 );
961- assertSemanticTextField (mapperService , fieldName2 , true , null , indexOptions );
981+ assertSemanticTextField (mapperService , fieldName2 , true , null , expectedIndexOptions );
962982 assertInferenceEndpoints (
963983 mapperService ,
964984 fieldName2 ,
0 commit comments