@@ -198,6 +198,7 @@ private static void validateIndexVersion(IndexVersion indexVersion, boolean useL
198198 }
199199 }
200200
201+ /*
201202 private MapperService createMapperService(String mappings, boolean useLegacyFormat) throws IOException {
202203 var settings = Settings.builder()
203204 .put(
@@ -208,6 +209,7 @@ private MapperService createMapperService(String mappings, boolean useLegacyForm
208209 .build();
209210 return createMapperService(settings, mappings);
210211 }
212+ */
211213
212214 @ Override
213215 protected Settings getIndexSettings () {
@@ -432,7 +434,13 @@ public void testMultiFieldsSupport() throws IOException {
432434 }), useLegacyFormat ));
433435 assertThat (e .getMessage (), containsString ("Field [semantic] of type [semantic_text] can't be used in multifields" ));
434436 } else {
435- var mapperService = createMapperService (fieldMapping (b -> {
437+ IndexVersion indexVersion = SparseVectorFieldMapperTests .getIndexOptionsCompatibleIndexVersion ();
438+ SparseVectorFieldMapper .SparseVectorIndexOptions expectedIndexOptions =
439+ SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion );
440+ SemanticTextIndexOptions semanticTextIndexOptions = expectedIndexOptions == null
441+ ? null
442+ : new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR , expectedIndexOptions );
443+ var mapperService = createMapperServiceWithIndexVersion (fieldMapping (b -> {
436444 b .field ("type" , "text" );
437445 b .startObject ("fields" );
438446 b .startObject ("semantic" );
@@ -443,10 +451,10 @@ public void testMultiFieldsSupport() throws IOException {
443451 b .endObject ();
444452 b .endObject ();
445453 b .endObject ();
446- }), useLegacyFormat );
447- assertSemanticTextField (mapperService , "field.semantic" , true , null , null );
454+ }), useLegacyFormat , indexVersion );
455+ assertSemanticTextField (mapperService , "field.semantic" , true , null , semanticTextIndexOptions );
448456
449- mapperService = createMapperService (fieldMapping (b -> {
457+ mapperService = createMapperServiceWithIndexVersion (fieldMapping (b -> {
450458 b .field ("type" , "semantic_text" );
451459 b .field ("inference_id" , "my_inference_id" );
452460 b .startObject ("model_settings" );
@@ -457,11 +465,10 @@ public void testMultiFieldsSupport() throws IOException {
457465 b .field ("type" , "text" );
458466 b .endObject ();
459467 b .endObject ();
460- }), useLegacyFormat );
461- var expectedIndexOptions = getDefaultSparseVectorIndexOptionsForMapper (mapperService );
462- assertSemanticTextField (mapperService , "field" , true , null , expectedIndexOptions );
468+ }), useLegacyFormat , indexVersion );
469+ assertSemanticTextField (mapperService , "field" , true , null , semanticTextIndexOptions );
463470
464- mapperService = createMapperService (fieldMapping (b -> {
471+ mapperService = createMapperServiceWithIndexVersion (fieldMapping (b -> {
465472 b .field ("type" , "semantic_text" );
466473 b .field ("inference_id" , "my_inference_id" );
467474 b .startObject ("model_settings" );
@@ -476,10 +483,9 @@ public void testMultiFieldsSupport() throws IOException {
476483 b .endObject ();
477484 b .endObject ();
478485 b .endObject ();
479- }), useLegacyFormat );
480- expectedIndexOptions = getDefaultSparseVectorIndexOptionsForMapper (mapperService );
481- assertSemanticTextField (mapperService , "field" , true , null , expectedIndexOptions );
482- assertSemanticTextField (mapperService , "field.semantic" , true , null , expectedIndexOptions );
486+ }), useLegacyFormat , indexVersion );
487+ assertSemanticTextField (mapperService , "field" , true , null , semanticTextIndexOptions );
488+ assertSemanticTextField (mapperService , "field.semantic" , true , null , semanticTextIndexOptions );
483489
484490 Exception e = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
485491 b .field ("type" , "semantic_text" );
@@ -644,37 +650,39 @@ private void addSparseVectorModelSettingsToBuilder(XContentBuilder b) throws IOE
644650
645651 public void testSparseVectorIndexOptionsValidationAndMapping () throws IOException {
646652 for (int depth = 1 ; depth < 5 ; depth ++) {
647- SparseVectorFieldMapper .SparseVectorIndexOptions indexOptions = SparseVectorFieldTypeTests .randomSparseVectorIndexOptions ();
648653 String inferenceId = "test_model" ;
649654 String fieldName = randomFieldName (depth );
655+ IndexVersion indexVersion = SparseVectorFieldMapperTests .getIndexOptionsCompatibleIndexVersion ();
656+ var sparseVectorIndexOptions = SparseVectorFieldTypeTests .randomSparseVectorIndexOptions ();
657+ var expectedIndexOptions = sparseVectorIndexOptions == null
658+ ? null
659+ : new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR , sparseVectorIndexOptions );
650660
651661 // should not throw an exception
652- MapperService mapper = createMapperService (mapping (b -> {
662+ MapperService mapper = createMapperServiceWithIndexVersion (mapping (b -> {
653663 b .startObject (fieldName );
654664 {
655665 b .field ("type" , SemanticTextFieldMapper .CONTENT_TYPE );
656666 b .field (INFERENCE_ID_FIELD , inferenceId );
657667 addSparseVectorModelSettingsToBuilder (b );
658- if (indexOptions != null ) {
668+ if (sparseVectorIndexOptions != null ) {
659669 b .startObject (INDEX_OPTIONS_FIELD );
660670 {
661671 b .field (SparseVectorFieldMapper .CONTENT_TYPE );
662- indexOptions .toXContent (b , null );
672+ sparseVectorIndexOptions .toXContent (b , null );
663673 }
664674 b .endObject ();
665675 }
666676 }
667677 b .endObject ();
668- }));
678+ }), useLegacyFormat , indexVersion );
669679
670680 assertSemanticTextField (
671681 mapper ,
672682 fieldName ,
673683 true ,
674684 null ,
675- indexOptions == null
676- ? null
677- : new SemanticTextIndexOptions (SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR , indexOptions )
685+ expectedIndexOptions
678686 );
679687 }
680688 }
@@ -721,7 +729,15 @@ public void testSparseVectorMappingUpdate() throws IOException {
721729 ChunkingSettings newChunkingSettings = generateRandomChunkingSettingsOtherThan (chunkingSettings );
722730 merge (
723731 mapperService ,
724- mapping (b -> addSemanticTextMapping (b , fieldName , model .getInferenceEntityId (), null , newChunkingSettings , newIndexOptions ))
732+ mapping (b -> addSemanticTextMapping (
733+ b ,
734+ fieldName ,
735+ model .getInferenceEntityId (),
736+ null ,
737+ newChunkingSettings ,
738+ newIndexOptions ,
739+ new MinimalServiceSettings (model )
740+ ))
725741 );
726742 assertSemanticTextField (mapperService , fieldName , true , newChunkingSettings , expectedIndexOptions );
727743 }
0 commit comments