|
9 | 9 |
|
10 | 10 | package org.elasticsearch.action.admin.indices.diskusage; |
11 | 11 |
|
| 12 | +import org.apache.lucene.codecs.Codec; |
12 | 13 | import org.apache.lucene.codecs.DocValuesFormat; |
13 | 14 | import org.apache.lucene.codecs.KnnVectorsFormat; |
14 | 15 | import org.apache.lucene.codecs.PostingsFormat; |
|
67 | 68 | import org.apache.lucene.util.FixedBitSet; |
68 | 69 | import org.elasticsearch.common.lucene.Lucene; |
69 | 70 | import org.elasticsearch.core.IOUtils; |
| 71 | +import org.elasticsearch.index.codec.Elasticsearch900Lucene101Codec; |
70 | 72 | import org.elasticsearch.index.codec.postings.ES812PostingsFormat; |
| 73 | +import org.elasticsearch.index.codec.tsdb.ES87TSDBDocValuesFormat; |
| 74 | +import org.elasticsearch.index.codec.zstd.Zstd814StoredFieldsFormat; |
71 | 75 | import org.elasticsearch.index.shard.ShardId; |
72 | 76 | import org.elasticsearch.index.store.LuceneFilesExtensions; |
73 | 77 | import org.elasticsearch.test.ESTestCase; |
@@ -405,6 +409,21 @@ public void testMixedFields() throws Exception { |
405 | 409 | } |
406 | 410 | } |
407 | 411 |
|
| 412 | + public void testDocValuesFieldWithDocValueSkippers() throws Exception { |
| 413 | + try (Directory dir = createNewDirectory()) { |
| 414 | + var codecMode = randomFrom(CodecMode.values()); |
| 415 | + indexRandomly(dir, codecMode, between(100, 1000), doc -> addRandomDocValuesField(doc, true)); |
| 416 | + final IndexDiskUsageStats stats = IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(dir), () -> {}); |
| 417 | + logger.info("--> stats {}", stats); |
| 418 | + try (Directory perFieldDir = createNewDirectory()) { |
| 419 | + rewriteIndexWithPerFieldCodec(dir, codecMode, perFieldDir); |
| 420 | + final IndexDiskUsageStats perFieldStats = collectPerFieldStats(perFieldDir); |
| 421 | + assertStats(stats, perFieldStats); |
| 422 | + assertStats(IndexDiskUsageAnalyzer.analyze(testShardId(), lastCommit(perFieldDir), () -> {}), perFieldStats); |
| 423 | + } |
| 424 | + } |
| 425 | + } |
| 426 | + |
408 | 427 | private static void addFieldsToDoc(Document doc, IndexableField[] fields) { |
409 | 428 | for (IndexableField field : fields) { |
410 | 429 | doc.add(field); |
@@ -442,23 +461,27 @@ static void indexRandomly(Directory directory, CodecMode codecMode, int numDocs, |
442 | 461 | } |
443 | 462 | } |
444 | 463 |
|
445 | | - static void addRandomDocValuesField(Document doc) { |
| 464 | + static void addRandomDocValuesField(Document doc, boolean indexed) { |
446 | 465 | if (randomBoolean()) { |
447 | | - doc.add(new NumericDocValuesField("ndv", random().nextInt(1024))); |
| 466 | + int val = random().nextInt(1024); |
| 467 | + doc.add(indexed ? NumericDocValuesField.indexedField("ndv", val) : new NumericDocValuesField("ndv", val)); |
448 | 468 | } |
449 | | - if (randomBoolean()) { |
| 469 | + if (randomBoolean() && indexed == false) { |
450 | 470 | doc.add(new BinaryDocValuesField("bdv", new BytesRef(randomAlphaOfLength(3)))); |
451 | 471 | } |
452 | 472 | if (randomBoolean()) { |
453 | | - doc.add(new SortedDocValuesField("sdv", new BytesRef(randomAlphaOfLength(3)))); |
| 473 | + var value = new BytesRef(randomAlphaOfLength(3)); |
| 474 | + doc.add(indexed ? SortedDocValuesField.indexedField("sdv", value) : new SortedDocValuesField("sdv", value)); |
454 | 475 | } |
455 | 476 | int numValues = random().nextInt(5); |
456 | 477 | for (int i = 0; i < numValues; ++i) { |
457 | | - doc.add(new SortedSetDocValuesField("ssdv", new BytesRef(randomAlphaOfLength(3)))); |
| 478 | + var value = new BytesRef(randomAlphaOfLength(3)); |
| 479 | + doc.add(indexed ? SortedSetDocValuesField.indexedField("ssdv", value) : new SortedSetDocValuesField("ssdv", value)); |
458 | 480 | } |
459 | 481 | numValues = random().nextInt(5); |
460 | 482 | for (int i = 0; i < numValues; ++i) { |
461 | | - doc.add(new SortedNumericDocValuesField("sndv", random().nextInt(1024))); |
| 483 | + int value = random().nextInt(1024); |
| 484 | + doc.add(indexed ? SortedNumericDocValuesField.indexedField("sndv", value) : new SortedNumericDocValuesField("sndv", value)); |
462 | 485 | } |
463 | 486 | } |
464 | 487 |
|
@@ -535,7 +558,7 @@ private static float[] randomVector(int dimension) { |
535 | 558 |
|
536 | 559 | static void addRandomFields(Document doc) { |
537 | 560 | if (randomBoolean()) { |
538 | | - addRandomDocValuesField(doc); |
| 561 | + addRandomDocValuesField(doc, false); |
539 | 562 | } |
540 | 563 | if (randomBoolean()) { |
541 | 564 | addRandomPostings(doc); |
|
0 commit comments