diff --git a/lucene/core/src/java/org/apache/lucene/codecs/PointsWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/PointsWriter.java index 56689ecae7c..53db281777a 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/PointsWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/PointsWriter.java @@ -54,6 +54,12 @@ public abstract class PointsWriter implements Closeable { // This segment has no points continue; } + FieldInfo readerFieldInfo = mergeState.fieldInfos[i].fieldInfo(fieldName); + if (readerFieldInfo == null) { + // This segment never saw this field + continue; + } + MergeState.DocMap docMap = mergeState.docMaps[i]; int docBase = mergeState.docBase[i]; pointsReader.intersect(fieldInfo.name, diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 57ce3ddea6d..66a0e73b601 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -4116,6 +4116,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable { (mergeState.mergeFieldInfos.hasDocValues() ? "docValues" : "no docValues") + "; " + (mergeState.mergeFieldInfos.hasProx() ? "prox" : "no prox") + "; " + (mergeState.mergeFieldInfos.hasProx() ? "freqs" : "no freqs") + "; " + + (mergeState.mergeFieldInfos.hasPointValues() ? "points" : "no points") + "; " + String.format(Locale.ROOT, "%.1f sec (%.1f sec stopped, %.1f sec paused) to merge segment [%.2f MB, %.2f MB/sec]", sec, diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java index 7231b1afc6f..9ced11a0718 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java @@ -39,6 +39,7 @@ import org.apache.lucene.index.PointValues.IntersectVisitor; import org.apache.lucene.index.PointValues.Relation; import org.apache.lucene.index.PointValues; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.TestUtil; @@ -562,4 +563,23 @@ public class TestPointValues extends LuceneTestCase { r.close(); dir.close(); } + + public void testPointsFieldMissingFromOneSegment() throws Exception { + Directory dir = FSDirectory.open(createTempDir()); + IndexWriterConfig iwc = new IndexWriterConfig(null); + IndexWriter w = new IndexWriter(dir, iwc); + Document doc = new Document(); + doc.add(new StringField("id", "0", Field.Store.NO)); + doc.add(new IntPoint("int0", 0)); + w.addDocument(doc); + w.commit(); + + doc = new Document(); + doc.add(new IntPoint("int1", 17)); + w.addDocument(doc); + w.forceMerge(1); + + w.close(); + dir.close(); + } }