Apache Lucene open-source search software
SOLR-8276: Atomic updates and realtime-get do not work with non-stored docvalues
Shalin Shekhar Mangaref103c674a33
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 0a6e9d4acfb..0da9b2ad385 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -317,6 +317,9 @@ Bug Fixes* SOLR-8460: /analysis/field could throw exceptions for custom attributes. (David Smiley, Uwe Schindler)+* SOLR-8276: Atomic updates and realtime-get do not work with non-stored docvalues.+ (Ishan Chattopadhyaya, yonik via shalin)+Other Changes----------------------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.javaindex d384c58e78b..ceaf9fe8f58 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@@ -341,6 +341,7 @@ public class RealTimeGetComponent extends SearchComponentif (docid < 0) return null;StoredDocument luceneDocument = searcher.doc(docid);sid = toSolrInputDocument(luceneDocument, core.getLatestSchema());+ searcher.decorateDocValueFields(sid, docid, searcher.getNonStoredDVs(false));}} finally {if (searcherHolder != null) {@@ -358,7 +359,7 @@ public class RealTimeGetComponent extends SearchComponentSchemaField sf = schema.getFieldOrNull(f.name());Object val = null;if (sf != null) {- if (!sf.stored() || schema.isCopyFieldTarget(sf)) continue;+ if ((!sf.hasDocValues() && !sf.stored()) || schema.isCopyFieldTarget(sf)) continue;val = sf.getType().toObject(f); // object or external string?} else {val = f.stringValue();diff --git a/solr/core/src/test-files/solr/collection1/conf/schema.xml b/solr/core/src/test-files/solr/collection1/conf/schema.xmlindex a45493aef14..64bca9a953c 100644--- a/solr/core/src/test-files/solr/collection1/conf/schema.xml+++ b/solr/core/src/test-files/solr/collection1/conf/schema.xml@@ -654,7 +654,14 @@<dynamicField name="*_d_dv" type="double" indexed="true" stored="true" docValues="true"/><dynamicField name="*_dt_dv" type="date" indexed="true" stored="true" docValues="true"/><dynamicField name="*_f1_dv" type="float" indexed="true" stored="true" docValues="true" multiValued="false"/>-++ <!-- Non-stored, DocValues=true -->+ <dynamicField name="*_i_dvo" multiValued="false" type="int" docValues="true" indexed="true" stored="false" useDocValuesAsStored="true"/>+ <dynamicField name="*_d_dvo" multiValued="false" type="double" docValues="true" indexed="true" stored="false" useDocValuesAsStored="true"/>+ <dynamicField name="*_s_dvo" multiValued="false" type="string" docValues="true" indexed="true" stored="false" useDocValuesAsStored="true"/>+ <dynamicField name="*_ii_dvo" multiValued="true" type="int" docValues="true" indexed="true" stored="false" useDocValuesAsStored="true"/>+ <dynamicField name="*_dd_dvo" multiValued="true" type="double" docValues="true" indexed="true" stored="false" useDocValuesAsStored="true"/>+</fields><defaultSearchField>text</defaultSearchField>diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.javaindex 0b8308566bb..cd9caccd2f3 100644--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java@@ -1009,7 +1009,64 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {}}-++ @Test+ public void testAtomicUpdatesOnNonStoredDocValues() throws Exception {+ assertU(adoc(sdoc("id", 2, "title", "title2", "single_i_dvo", 100)));+ assertU(adoc(sdoc("id", 3, "title", "title3", "single_d_dvo", 3.14)));+ assertU(adoc(sdoc("id", 4, "single_s_dvo", "abc", "single_i_dvo", 1)));+ assertU(commit());++ assertU(adoc(sdoc("id", 2, "title", ImmutableMap.of("set", "newtitle2"),+ "single_i_dvo", ImmutableMap.of("inc", 1))));+ assertU(adoc(sdoc("id", 3, "title", ImmutableMap.of("set", "newtitle3"),+ "single_d_dvo", ImmutableMap.of("inc", 1))));+ assertU(adoc(sdoc("id", 4, "single_i_dvo", ImmutableMap.of("inc", 1))));+ assertU(commit());++ assertJQ(req("q", "id:2"),+ "/response/docs/[0]/id==2",+ "/response/docs/[0]/title/[0]=='newtitle2'",+ "/response/docs/[0]/single_i_dvo==101");++ assertJQ(req("q", "id:3"),+ 1e-4,+ "/response/docs/[0]/id==3",+ "/response/docs/[0]/title/[0]=='newtitle3'",+ "/response/docs/[0]/single_d_dvo==4.14");++ assertJQ(req("q", "id:4"),+ 1e-4,+ "/response/docs/[0]/id==4",+ "/response/docs/[0]/single_s_dvo=='abc'",+ "/response/docs/[0]/single_i_dvo==2");++ // test that non stored docvalues was carried forward for a non-docvalue update+ assertU(adoc(sdoc("id", 3, "title", ImmutableMap.of("set", "newertitle3"))));+ assertU(commit());+ assertJQ(req("q", "id:3"),+ 1e-4,+ "/response/docs/[0]/id==3",+ "/response/docs/[0]/title/[0]=='newertitle3'",+ "/response/docs/[0]/single_d_dvo==4.14");+ }++ @Test+ public void testAtomicUpdatesOnNonStoredDocValuesMulti() throws Exception {+ assertU(adoc(sdoc("id", 1, "title", "title1", "multi_ii_dvo", 100, "multi_ii_dvo", Integer.MAX_VALUE)));+ assertU(commit());++ assertU(adoc(sdoc("id", 1, "title", ImmutableMap.of("set", "newtitle1"))));+ assertU(commit());++ // test that non stored multivalued docvalues was carried forward for a non docvalues update+ assertJQ(req("q", "id:1"),+ "/response/docs/[0]/id==1",+ "/response/docs/[0]/title/[0]=='newtitle1'",+ "/response/docs/[0]/multi_ii_dvo/[0]==100",+ "/response/docs/[0]/multi_ii_dvo/[1]==" + Integer.MAX_VALUE);+ }+@Testpublic void testInvalidOperation() {SolrInputDocument doc;