diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index fee501990fd..52e7c31f103 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -361,6 +361,9 @@ Bug Fixes
* SOLR-8891: Fix StrField.toObject and toExternal to work with docValue IndexableField
instances. (yonik)
+* SOLR-8865: Real-time get sometimes fails to retrieve stored fields from docValues.
+ (Ishan Chattopadhyaya, yonik)
+
Optimizations
----------------------
* SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not been
diff --git a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
index 2f71b3e8a37..8332c797fa6 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Map;
import org.apache.lucene.document.Document;
+import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.LeafReaderContext;
@@ -258,6 +259,7 @@ public class RealTimeGetComponent extends SearchComponent
if (docid < 0) continue;
Document luceneDocument = searcher.doc(docid, rsp.getReturnFields().getLuceneFieldNames());
SolrDocument doc = toSolrDoc(luceneDocument, core.getLatestSchema());
+ searcher.decorateDocValueFields(doc, docid, searcher.getNonStoredDVs(true));
if( transformer != null ) {
transformer.transform(doc, docid, 0);
}
@@ -408,8 +410,15 @@ public class RealTimeGetComponent extends SearchComponent
// copy the stored fields only
Document out = new Document();
for (IndexableField f : doc.getFields()) {
- if (f.fieldType().stored() ) {
- out.add((IndexableField) f);
+ if (f.fieldType().stored()) {
+ out.add(f);
+ } else if (f.fieldType().docValuesType() != DocValuesType.NONE) {
+ SchemaField schemaField = schema.getFieldOrNull(f.name());
+ if (schemaField != null && !schemaField.stored() && schemaField.useDocValuesAsStored()) {
+ out.add(f);
+ }
+ } else {
+ log.debug("Don't know how to handle field " + f);
}
}
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema15.xml b/solr/core/src/test-files/solr/collection1/conf/schema15.xml
index ea46d85553d..55ec3f1ac60 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema15.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema15.xml
@@ -530,6 +530,7 @@
+
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
index ef82aa189b7..cae373cdd92 100644
--- a/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/schema_latest.xml
@@ -110,7 +110,7 @@
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -230,10 +251,6 @@
-
-
-
-
@@ -258,8 +275,8 @@
-
+
@@ -695,7 +712,7 @@
-
+