2929import org .elasticsearch .index .mapper .DocumentMapper ;
3030import org .elasticsearch .index .mapper .DocumentParsingException ;
3131import org .elasticsearch .index .mapper .MappedFieldType ;
32+ import org .elasticsearch .index .mapper .Mapper ;
3233import org .elasticsearch .index .mapper .MapperParsingException ;
3334import org .elasticsearch .index .mapper .MapperService ;
3435import org .elasticsearch .index .mapper .MapperTestCase ;
3536import org .elasticsearch .index .mapper .ParsedDocument ;
37+ import org .elasticsearch .index .mapper .SourceToParse ;
3638import org .elasticsearch .index .query .SearchExecutionContext ;
3739import org .elasticsearch .inference .WeightedToken ;
3840import org .elasticsearch .search .lookup .Source ;
5153import java .util .List ;
5254import java .util .Map ;
5355
56+ import static org .elasticsearch .index .IndexVersions .UPGRADE_TO_LUCENE_10_0_0 ;
5457import static org .elasticsearch .index .mapper .vectors .SparseVectorFieldMapper .NEW_SPARSE_VECTOR_INDEX_VERSION ;
5558import static org .elasticsearch .index .mapper .vectors .SparseVectorFieldMapper .PREVIOUS_SPARSE_VECTOR_INDEX_VERSION ;
59+ import static org .elasticsearch .index .mapper .vectors .SparseVectorFieldMapper .SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION ;
5660import static org .elasticsearch .xcontent .XContentFactory .jsonBuilder ;
5761import static org .hamcrest .Matchers .containsString ;
5862import static org .hamcrest .Matchers .equalTo ;
@@ -78,7 +82,7 @@ protected void minimalMapping(XContentBuilder b) throws IOException {
7882 b .field ("type" , "sparse_vector" );
7983 }
8084
81- protected void mappingWithIndexOptions (XContentBuilder b ) throws IOException {
85+ protected void minimalMappingWithExplicitIndexOptions (XContentBuilder b ) throws IOException {
8286 b .field ("type" , "sparse_vector" );
8387 b .startObject ("index_options" );
8488 {
@@ -131,7 +135,7 @@ private static int getFrequency(TokenStream tk) throws IOException {
131135
132136 public void testDefaults () throws Exception {
133137 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
134- assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), mapper .mappingSource ().toString ());
138+ assertEquals (Strings .toString (fieldMapping (this ::minimalMappingWithExplicitIndexOptions )), mapper .mappingSource ().toString ());
135139
136140 ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
137141
@@ -155,6 +159,19 @@ public void testDefaults() throws Exception {
155159 assertTrue (freq1 < freq2 );
156160 }
157161
162+ public void testMappingWithoutIndexOptionsUsesDefaults () throws Exception {
163+ DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
164+ assertEquals (Strings .toString (fieldMapping (this ::minimalMappingWithExplicitIndexOptions )), mapper .mappingSource ().toString ());
165+
166+ IndexVersion preIndexOptionsVersion = IndexVersionUtils .randomVersionBetween (
167+ random (),
168+ UPGRADE_TO_LUCENE_10_0_0 ,
169+ SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_VERSION
170+ );
171+ DocumentMapper previousMapper = createDocumentMapper (preIndexOptionsVersion , fieldMapping (this ::minimalMapping ));
172+ assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), previousMapper .mappingSource ().toString ());
173+ }
174+
158175 public void testDotInFieldName () throws Exception {
159176 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
160177 ParsedDocument parsedDocument = mapper .parse (source (b -> b .field ("field" , Map .of ("foo.bar" , 10 , "foobar" , 20 ))));
@@ -579,7 +596,7 @@ public void testTypeQueryFinalizationDefaultsPreviousVersion() throws Exception
579596
580597 public void testTypeQueryFinalizationWithIndexExplicit () throws Exception {
581598 IndexVersion version = IndexVersion .current ();
582- MapperService mapperService = createMapperService (version , fieldMapping (this ::mappingWithIndexOptions ));
599+ MapperService mapperService = createMapperService (version , fieldMapping (this ::minimalMapping ));
583600
584601 // query should be pruned via explicit index options
585602 performTypeQueryFinalizationTest (
@@ -758,7 +775,7 @@ private MapperService getMapperServiceForRandomizedFinalizationTest(
758775 return createMapperService (indexVersion , fieldMapping (this ::mappingWithIndexOptionsPruneFalse ));
759776 }
760777
761- return createMapperService (indexVersion , fieldMapping (this ::mappingWithIndexOptions ));
778+ return createMapperService (indexVersion , fieldMapping (this ::minimalMapping ));
762779 }
763780
764781 private static List <WeightedToken > QUERY_VECTORS = List .of (
0 commit comments