@@ -405,6 +405,21 @@ public void testMixedFields() throws Exception {
405
405
}
406
406
}
407
407
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
+
408
423
private static void addFieldsToDoc (Document doc , IndexableField [] fields ) {
409
424
for (IndexableField field : fields ) {
410
425
doc .add (field );
@@ -442,23 +457,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs,
442
457
}
443
458
}
444
459
445
- static void addRandomDocValuesField (Document doc ) {
460
+ static void addRandomDocValuesField (Document doc , boolean indexed ) {
446
461
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 ));
448
464
}
449
- if (randomBoolean ()) {
465
+ if (randomBoolean () && indexed == false ) {
450
466
doc .add (new BinaryDocValuesField ("bdv" , new BytesRef (randomAlphaOfLength (3 ))));
451
467
}
452
468
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 ));
454
471
}
455
472
int numValues = random ().nextInt (5 );
456
473
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 ));
458
476
}
459
477
numValues = random ().nextInt (5 );
460
478
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 ));
462
481
}
463
482
}
464
483
@@ -535,7 +554,7 @@ private static float[] randomVector(int dimension) {
535
554
536
555
static void addRandomFields (Document doc ) {
537
556
if (randomBoolean ()) {
538
- addRandomDocValuesField (doc );
557
+ addRandomDocValuesField (doc , false );
539
558
}
540
559
if (randomBoolean ()) {
541
560
addRandomPostings (doc );
0 commit comments