5757import  org .elasticsearch .index .mapper .vectors .DenseVectorFieldMapper ;
5858import  org .elasticsearch .index .mapper .vectors .DenseVectorFieldTypeTests ;
5959import  org .elasticsearch .index .mapper .vectors .SparseVectorFieldMapper ;
60+ import  org .elasticsearch .index .mapper .vectors .SparseVectorFieldMapperTests ;
6061import  org .elasticsearch .index .mapper .vectors .SparseVectorFieldTypeTests ;
6162import  org .elasticsearch .index .mapper .vectors .TokenPruningConfig ;
6263import  org .elasticsearch .index .query .SearchExecutionContext ;
@@ -725,10 +726,11 @@ public void testSparseVectorMappingUpdate() throws IOException {
725726        for  (int  i  = 0 ; i  < 5 ; i ++) {
726727            Model  model  = TestModel .createRandomInstance (TaskType .SPARSE_EMBEDDING );
727728            final  ChunkingSettings  chunkingSettings  = generateRandomChunkingSettings (false );
729+             IndexVersion  indexVersion  = SparseVectorFieldMapperTests .getIndexOptionsCompatibleIndexVersion ();
728730            final  SemanticTextIndexOptions  indexOptions  = randomSemanticTextIndexOptions (TaskType .SPARSE_EMBEDDING );
729731            String  fieldName  = "field" ;
730732
731-             MapperService  mapperService  = createMapperService (
733+             MapperService  mapperService  = createMapperServiceWithIndexVersion (
732734                mapping (
733735                    b  -> addSemanticTextMapping (
734736                        b ,
@@ -740,17 +742,31 @@ public void testSparseVectorMappingUpdate() throws IOException {
740742                        new  MinimalServiceSettings (model )
741743                    )
742744                ),
743-                 useLegacyFormat 
745+                 useLegacyFormat ,
746+                 indexVersion 
744747            );
745-             assertSemanticTextField (mapperService , fieldName , true , chunkingSettings , indexOptions );
748+             var  expectedIndexOptions  = (indexOptions  == null )
749+                                        ? new  SemanticTextIndexOptions (
750+                                             SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR ,
751+                                             SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion )
752+                                         )
753+                                        : indexOptions ;
754+             assertSemanticTextField (mapperService , fieldName , true , chunkingSettings , expectedIndexOptions );
746755
747756            final  SemanticTextIndexOptions  newIndexOptions  = randomSemanticTextIndexOptions (TaskType .SPARSE_EMBEDDING );
757+             expectedIndexOptions  = (newIndexOptions  == null )
758+                                    ? new  SemanticTextIndexOptions (
759+                                         SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR ,
760+                                         SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion )
761+                                     )
762+                                    : newIndexOptions ;
763+ 
748764            ChunkingSettings  newChunkingSettings  = generateRandomChunkingSettingsOtherThan (chunkingSettings );
749765            merge (
750766                mapperService ,
751767                mapping (b  -> addSemanticTextMapping (b , fieldName , model .getInferenceEntityId (), null , newChunkingSettings , newIndexOptions ))
752768            );
753-             assertSemanticTextField (mapperService , fieldName , true , newChunkingSettings , newIndexOptions );
769+             assertSemanticTextField (mapperService , fieldName , true , newChunkingSettings , expectedIndexOptions );
754770        }
755771    }
756772
@@ -959,13 +975,12 @@ public void testSuccessfulParse() throws IOException {
959975                );
960976            });
961977
962-             var  expectedIndexOptions  = indexOptions ;
963-             if  (expectedIndexOptions  == null ) {
964-                 expectedIndexOptions  = new  SemanticTextIndexOptions (
965-                     SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR ,
966-                     SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion )
967-                 );
968-             }
978+             var  expectedIndexOptions  = (indexOptions  == null )
979+                 ? new  SemanticTextIndexOptions (
980+                         SemanticTextIndexOptions .SupportedIndexOptions .SPARSE_VECTOR ,
981+                         SparseVectorFieldMapper .SparseVectorIndexOptions .getDefaultIndexOptions (indexVersion )
982+                     )
983+                 : indexOptions ;
969984
970985            MapperService  mapperService  = createMapperServiceWithIndexVersion (mapping , useLegacyFormat , indexVersion );
971986            assertSemanticTextField (mapperService , fieldName1 , true , null , expectedIndexOptions );
0 commit comments