@@ -127,78 +127,28 @@ public void testDefaults() throws Exception {
127127 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::minimalMapping ));
128128 assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), mapper .mappingSource ().toString ());
129129
130- ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
130+ checkParsedDocument (mapper );
131+ }
131132
132- List <IndexableField > fields = doc1 .rootDoc ().getFields ("field" );
133- assertEquals (2 , fields .size ());
134- assertThat (fields .get (0 ), Matchers .instanceOf (XFeatureField .class ));
135- XFeatureField featureField1 = null ;
136- XFeatureField featureField2 = null ;
137- for (IndexableField field : fields ) {
138- if (field .stringValue ().equals ("ten" )) {
139- featureField1 = (XFeatureField ) field ;
140- } else if (field .stringValue ().equals ("twenty" )) {
141- featureField2 = (XFeatureField ) field ;
142- } else {
143- throw new UnsupportedOperationException ();
144- }
145- }
133+ public void testDefaultsPreIndexOptions () throws Exception {
134+ DocumentMapper mapper = getDocumentMapperPreviousVersion (fieldMapping (this ::minimalMapping ));
135+ assertEquals (Strings .toString (fieldMapping (this ::minimalMapping )), mapper .mappingSource ().toString ());
146136
147- int freq1 = getFrequency (featureField1 .tokenStream (null , null ));
148- int freq2 = getFrequency (featureField2 .tokenStream (null , null ));
149- assertTrue (freq1 < freq2 );
137+ checkParsedDocument (mapper );
150138 }
151139
152140 public void testWithIndexOptionsPrune () throws Exception {
153141 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::mappingWithIndexOptionsPrune ));
154142 assertEquals (Strings .toString (fieldMapping (this ::mappingWithIndexOptionsPrune )), mapper .mappingSource ().toString ());
155143
156- ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
157-
158- List <IndexableField > fields = doc1 .rootDoc ().getFields ("field" );
159- assertEquals (2 , fields .size ());
160- assertThat (fields .get (0 ), Matchers .instanceOf (XFeatureField .class ));
161- XFeatureField featureField1 = null ;
162- XFeatureField featureField2 = null ;
163- for (IndexableField field : fields ) {
164- if (field .stringValue ().equals ("ten" )) {
165- featureField1 = (XFeatureField ) field ;
166- } else if (field .stringValue ().equals ("twenty" )) {
167- featureField2 = (XFeatureField ) field ;
168- } else {
169- throw new UnsupportedOperationException ();
170- }
171- }
172-
173- int freq1 = getFrequency (featureField1 .tokenStream (null , null ));
174- int freq2 = getFrequency (featureField2 .tokenStream (null , null ));
175- assertTrue (freq1 < freq2 );
144+ checkParsedDocument (mapper );
176145 }
177146
178147 public void testWithIndexOptionsPruningConfigOnly () throws Exception {
179148 DocumentMapper mapper = createDocumentMapper (fieldMapping (this ::mappingWithIndexOptionsPruningConfig ));
180149 assertEquals (Strings .toString (fieldMapping (this ::mappingWithIndexOptionsPruningConfig )), mapper .mappingSource ().toString ());
181150
182- ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
183-
184- List <IndexableField > fields = doc1 .rootDoc ().getFields ("field" );
185- assertEquals (2 , fields .size ());
186- assertThat (fields .get (0 ), Matchers .instanceOf (XFeatureField .class ));
187- XFeatureField featureField1 = null ;
188- XFeatureField featureField2 = null ;
189- for (IndexableField field : fields ) {
190- if (field .stringValue ().equals ("ten" )) {
191- featureField1 = (XFeatureField ) field ;
192- } else if (field .stringValue ().equals ("twenty" )) {
193- featureField2 = (XFeatureField ) field ;
194- } else {
195- throw new UnsupportedOperationException ();
196- }
197- }
198-
199- int freq1 = getFrequency (featureField1 .tokenStream (null , null ));
200- int freq2 = getFrequency (featureField2 .tokenStream (null , null ));
201- assertTrue (freq1 < freq2 );
151+ checkParsedDocument (mapper );
202152 }
203153
204154 public void testDotInFieldName () throws Exception {
@@ -349,7 +299,7 @@ public void testTokensFreqRatioCorrect() {
349299 assertThat (
350300 eTestInteger .getMessage (),
351301 containsString (
352- "Failed to parse mapping: [pruning_config] field [tokens_freq_ratio_threshold]field should be a number between 1 and 100 "
302+ "Failed to parse mapping: org.elasticsearch.xcontent.XContentParseException: [0:0] [pruning_config] failed to parse field [tokens_freq_ratio_threshold] "
353303 )
354304 );
355305
@@ -364,7 +314,7 @@ public void testTokensFreqRatioCorrect() {
364314 })));
365315 assertThat (
366316 eTestRangeLower .getMessage (),
367- containsString ("[pruning_config] field [tokens_freq_ratio_threshold] field should be a number between 1 and 100" )
317+ containsString ("Failed to parse mapping: java.lang.IllegalArgumentException: [tokens_freq_ratio_threshold] must be between [1] and [ 100], got -2.0 " )
368318 );
369319
370320 Exception eTestRangeHigher = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
@@ -378,7 +328,7 @@ public void testTokensFreqRatioCorrect() {
378328 })));
379329 assertThat (
380330 eTestRangeHigher .getMessage (),
381- containsString ("[pruning_config] field [tokens_freq_ratio_threshold] field should be a number between 1 and 100" )
331+ containsString ("Failed to parse mapping: java.lang.IllegalArgumentException: [tokens_freq_ratio_threshold] must be between [1] and [ 100], got 101 " )
382332 );
383333 }
384334
@@ -395,7 +345,7 @@ public void testTokensWeightThresholdCorrect() {
395345 assertThat (
396346 eTestDouble .getMessage (),
397347 containsString (
398- "Failed to parse mapping: [pruning_config] field [tokens_weight_threshold]field should be a number between 0.0 and 1.0 "
348+ "Failed to parse mapping: org.elasticsearch.xcontent.XContentParseException: [0:0] [pruning_config] failed to parse field [tokens_weight_threshold] "
399349 )
400350 );
401351
@@ -410,7 +360,7 @@ public void testTokensWeightThresholdCorrect() {
410360 })));
411361 assertThat (
412362 eTestRangeLower .getMessage (),
413- containsString ("[pruning_config] field [tokens_weight_threshold] field should be a number between 0.0 and 1.0 " )
363+ containsString ("Failed to parse mapping: java.lang.IllegalArgumentException: [tokens_weight_threshold] must be between 0 and 1" )
414364 );
415365
416366 Exception eTestRangeHigher = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
@@ -424,7 +374,7 @@ public void testTokensWeightThresholdCorrect() {
424374 })));
425375 assertThat (
426376 eTestRangeHigher .getMessage (),
427- containsString ("[pruning_config] field [tokens_weight_threshold] field should be a number between 0.0 and 1.0 " )
377+ containsString ("Failed to parse mapping: java.lang.IllegalArgumentException: [tokens_weight_threshold] must be between 0 and 1" )
428378 );
429379 }
430380
@@ -559,4 +509,33 @@ private Map<String, Float> toFloats(Map<String, ?> value) {
559509 }
560510 return result ;
561511 }
512+
513+ private void checkParsedDocument (DocumentMapper mapper ) throws IOException {
514+ ParsedDocument doc1 = mapper .parse (source (this ::writeField ));
515+
516+ List <IndexableField > fields = doc1 .rootDoc ().getFields ("field" );
517+ assertEquals (2 , fields .size ());
518+ assertThat (fields .get (0 ), Matchers .instanceOf (XFeatureField .class ));
519+ XFeatureField featureField1 = null ;
520+ XFeatureField featureField2 = null ;
521+ for (IndexableField field : fields ) {
522+ if (field .stringValue ().equals ("ten" )) {
523+ featureField1 = (XFeatureField ) field ;
524+ } else if (field .stringValue ().equals ("twenty" )) {
525+ featureField2 = (XFeatureField ) field ;
526+ } else {
527+ throw new UnsupportedOperationException ();
528+ }
529+ }
530+
531+ int freq1 = getFrequency (featureField1 .tokenStream (null , null ));
532+ int freq2 = getFrequency (featureField2 .tokenStream (null , null ));
533+ assertTrue (freq1 < freq2 );
534+ }
535+
536+ private final IndexVersion PRE_SPARSE_VECTOR_INDEX_OPTIONS_VERSION = IndexVersions .DEFAULT_TO_ACORN_HNSW_FILTER_HEURISTIC ;
537+
538+ private DocumentMapper getDocumentMapperPreviousVersion (XContentBuilder mappings ) throws IOException {
539+ return createMapperService (PRE_SPARSE_VECTOR_INDEX_OPTIONS_VERSION , mappings ).documentMapper ();
540+ }
562541}
0 commit comments