@@ -88,6 +88,7 @@ protected void mappingWithIndexOptionsPrune(XContentBuilder b) throws IOExceptio
8888 protected void mappingWithIndexOptionsPruningConfig (XContentBuilder b ) throws IOException {
8989 b .field ("type" , "sparse_vector" );
9090 b .startObject ("index_options" );
91+ b .field ("prune" , true );
9192 b .startObject ("pruning_config" );
9293 b .field ("tokens_freq_ratio_threshold" , 5.0 );
9394 b .field ("tokens_weight_threshold" , 0.4 );
@@ -296,29 +297,64 @@ public void testPruningConfigurationIsMap() {
296297 Exception e = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
297298 b .field ("type" , "sparse_vector" );
298299 b .startObject ("index_options" );
300+ b .field ("prune" , true );
299301 b .field ("pruning_config" , "this_is_not_a_map" );
300302 b .endObject ();
301303 })));
302304 assertThat (e .getMessage (), containsString ("index_options] field [pruning_config] should be a map" ));
303305 }
304306
307+ public void testWithIndexOptionsPruningConfigPruneRequired () throws Exception {
308+
309+ Exception eTestPruneIsFalse = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
310+ b .field ("type" , "sparse_vector" );
311+ b .startObject ("index_options" );
312+ b .field ("prune" , false );
313+ b .startObject ("pruning_config" );
314+ b .field ("tokens_freq_ratio_threshold" , 5.0 );
315+ b .field ("tokens_weight_threshold" , 0.4 );
316+ b .endObject ();
317+ b .endObject ();
318+ })));
319+ assertThat (
320+ eTestPruneIsFalse .getMessage (),
321+ containsString ("Failed to parse mapping: [index_options] field [pruning_config] should not be set if [prune] is false" )
322+ );
323+
324+ Exception eTestPruneIsMissing = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
325+ b .field ("type" , "sparse_vector" );
326+ b .startObject ("index_options" );
327+ b .startObject ("pruning_config" );
328+ b .field ("tokens_freq_ratio_threshold" , 5.0 );
329+ b .field ("tokens_weight_threshold" , 0.4 );
330+ b .endObject ();
331+ b .endObject ();
332+ })));
333+ assertThat (
334+ eTestPruneIsMissing .getMessage (),
335+ containsString ("[index_options] field [pruning_config] should only be set if [prune] is set to true" )
336+ );
337+ }
338+
305339 public void testTokensFreqRatioCorrect () {
306340 Exception eTestInteger = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
307341 b .field ("type" , "sparse_vector" );
308342 b .startObject ("index_options" );
343+ b .field ("prune" , true );
309344 b .startObject ("pruning_config" );
310345 b .field ("tokens_freq_ratio_threshold" , "notaninteger" );
311346 b .endObject ();
312347 b .endObject ();
313348 })));
314349 assertThat (
315350 eTestInteger .getMessage (),
316- containsString ("[pruning_config] field [tokens_freq_ratio_threshold] field should be a number between 1 and 100" )
351+ containsString ("Failed to parse mapping: [pruning_config] field [tokens_freq_ratio_threshold]field should be a number between 1 and 100" )
317352 );
318353
319354 Exception eTestRangeLower = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
320355 b .field ("type" , "sparse_vector" );
321356 b .startObject ("index_options" );
357+ b .field ("prune" , true );
322358 b .startObject ("pruning_config" );
323359 b .field ("tokens_freq_ratio_threshold" , -2 );
324360 b .endObject ();
@@ -332,6 +368,7 @@ public void testTokensFreqRatioCorrect() {
332368 Exception eTestRangeHigher = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
333369 b .field ("type" , "sparse_vector" );
334370 b .startObject ("index_options" );
371+ b .field ("prune" , true );
335372 b .startObject ("pruning_config" );
336373 b .field ("tokens_freq_ratio_threshold" , 101 );
337374 b .endObject ();
@@ -347,19 +384,21 @@ public void testTokensWeightThresholdCorrect() {
347384 Exception eTestDouble = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
348385 b .field ("type" , "sparse_vector" );
349386 b .startObject ("index_options" );
387+ b .field ("prune" , true );
350388 b .startObject ("pruning_config" );
351389 b .field ("tokens_weight_threshold" , "notadouble" );
352390 b .endObject ();
353391 b .endObject ();
354392 })));
355393 assertThat (
356394 eTestDouble .getMessage (),
357- containsString ("[pruning_config] field [tokens_weight_threshold] field should be a number between 0.0 and 1.0" )
395+ containsString ("Failed to parse mapping: [pruning_config] field [tokens_weight_threshold]field should be a number between 0.0 and 1.0" )
358396 );
359397
360398 Exception eTestRangeLower = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
361399 b .field ("type" , "sparse_vector" );
362400 b .startObject ("index_options" );
401+ b .field ("prune" , true );
363402 b .startObject ("pruning_config" );
364403 b .field ("tokens_weight_threshold" , -0.1 );
365404 b .endObject ();
@@ -373,6 +412,7 @@ public void testTokensWeightThresholdCorrect() {
373412 Exception eTestRangeHigher = expectThrows (MapperParsingException .class , () -> createMapperService (fieldMapping (b -> {
374413 b .field ("type" , "sparse_vector" );
375414 b .startObject ("index_options" );
415+ b .field ("prune" , true );
376416 b .startObject ("pruning_config" );
377417 b .field ("tokens_weight_threshold" , 1.1 );
378418 b .endObject ();
0 commit comments