@@ -405,6 +405,21 @@ public void testMixedFields() throws Exception {
405405 }
406406 }
407407
408+ public void testDocValuesFieldWithDocValueSkippers () throws Exception {
409+ try (Directory dir = createNewDirectory ()) {
410+ var codecMode = randomFrom (CodecMode .values ());
411+ indexRandomly (dir , codecMode , between (100 , 1000 ), doc -> addRandomDocValuesField (doc , true ));
412+ final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer .analyze (testShardId (), lastCommit (dir ), () -> {});
413+ logger .info ("--> stats {}" , stats );
414+ try (Directory perFieldDir = createNewDirectory ()) {
415+ rewriteIndexWithPerFieldCodec (dir , codecMode , perFieldDir );
416+ final IndexDiskUsageStats perFieldStats = collectPerFieldStats (perFieldDir );
417+ assertStats (stats , perFieldStats );
418+ assertStats (IndexDiskUsageAnalyzer .analyze (testShardId (), lastCommit (perFieldDir ), () -> {}), perFieldStats );
419+ }
420+ }
421+ }
422+
408423 private static void addFieldsToDoc (Document doc , IndexableField [] fields ) {
409424 for (IndexableField field : fields ) {
410425 doc .add (field );
@@ -442,23 +457,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs,
442457 }
443458 }
444459
445- static void addRandomDocValuesField (Document doc ) {
460+ static void addRandomDocValuesField (Document doc , boolean indexed ) {
446461 if (randomBoolean ()) {
447- doc .add (new NumericDocValuesField ("ndv" , random ().nextInt (1024 )));
462+ int val = random ().nextInt (1024 );
463+ doc .add (indexed ? NumericDocValuesField .indexedField ("ndv" , val ) : new NumericDocValuesField ("ndv" , val ));
448464 }
449- if (randomBoolean ()) {
465+ if (randomBoolean () && indexed == false ) {
450466 doc .add (new BinaryDocValuesField ("bdv" , new BytesRef (randomAlphaOfLength (3 ))));
451467 }
452468 if (randomBoolean ()) {
453- doc .add (new SortedDocValuesField ("sdv" , new BytesRef (randomAlphaOfLength (3 ))));
469+ var value = new BytesRef (randomAlphaOfLength (3 ));
470+ doc .add (indexed ? SortedDocValuesField .indexedField ("sdv" , value ) : new SortedDocValuesField ("sdv" , value ));
454471 }
455472 int numValues = random ().nextInt (5 );
456473 for (int i = 0 ; i < numValues ; ++i ) {
457- doc .add (new SortedSetDocValuesField ("ssdv" , new BytesRef (randomAlphaOfLength (3 ))));
474+ var value = new BytesRef (randomAlphaOfLength (3 ));
475+ doc .add (indexed ? SortedSetDocValuesField .indexedField ("ssdv" , value ) : new SortedSetDocValuesField ("ssdv" , value ));
458476 }
459477 numValues = random ().nextInt (5 );
460478 for (int i = 0 ; i < numValues ; ++i ) {
461- doc .add (new SortedNumericDocValuesField ("sndv" , random ().nextInt (1024 )));
479+ int value = random ().nextInt (1024 );
480+ doc .add (indexed ? SortedNumericDocValuesField .indexedField ("sndv" , value ) : new SortedNumericDocValuesField ("sndv" , value ));
462481 }
463482 }
464483
@@ -535,7 +554,7 @@ private static float[] randomVector(int dimension) {
535554
536555 static void addRandomFields (Document doc ) {
537556 if (randomBoolean ()) {
538- addRandomDocValuesField (doc );
557+ addRandomDocValuesField (doc , false );
539558 }
540559 if (randomBoolean ()) {
541560 addRandomPostings (doc );
0 commit comments