Skip to content

Commit efd7457

Browse files
author
Christoph Büscher
committed
Handle handle fields that have doc values but are not indexed
1 parent 077e89d commit efd7457

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

server/src/main/java/org/elasticsearch/search/query/TopDocsCollectorContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ static int shortcutTotalHitCount(IndexReader reader, Query query) throws IOExcep
375375
} else if (fieldInfo.getIndexOptions() != IndexOptions.NONE) {
376376
Terms terms = context.reader().terms(field);
377377
count += terms.getDocCount();
378+
} else {
379+
return -1; // no shortcut possible for fields that are not indexed
378380
}
379381
}
380382
return count;

server/src/test/java/org/elasticsearch/search/query/QueryPhaseTests.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.apache.lucene.document.Document;
2323
import org.apache.lucene.document.Field.Store;
24+
import org.apache.lucene.document.LatLonDocValuesField;
25+
import org.apache.lucene.document.LatLonPoint;
2426
import org.apache.lucene.document.NumericDocValuesField;
2527
import org.apache.lucene.document.SortedSetDocValuesField;
2628
import org.apache.lucene.document.StringField;
@@ -121,10 +123,13 @@ private void countTestCase(boolean withDeletions) throws Exception {
121123
if (randomBoolean()) {
122124
doc.add(new StringField("foo", "bar", Store.NO));
123125
doc.add(new SortedSetDocValuesField("foo", new BytesRef("bar")));
126+
doc.add(new SortedSetDocValuesField("docValuesOnlyField", new BytesRef("bar")));
127+
doc.add(new LatLonDocValuesField("latLonDVField", 1.0, 1.0));
128+
doc.add(new LatLonPoint("latLonDVField", 1.0, 1.0));
124129
}
125130
if (randomBoolean()) {
126-
doc.add(new StringField("foo", "bar", Store.NO));
127-
doc.add(new SortedSetDocValuesField("foo", new BytesRef("bar")));
131+
doc.add(new StringField("foo", "baz", Store.NO));
132+
doc.add(new SortedSetDocValuesField("foo", new BytesRef("baz")));
128133
}
129134
if (withDeletions && (rarely() || i == 0)) {
130135
doc.add(new StringField("delete", "yes", Store.NO));
@@ -140,6 +145,10 @@ private void countTestCase(boolean withDeletions) throws Exception {
140145
Query tq = new TermQuery(new Term("foo", "bar"));
141146
Query tCsq = new ConstantScoreQuery(tq);
142147
Query dvfeq = new DocValuesFieldExistsQuery("foo");
148+
Query dvfeq_points = new DocValuesFieldExistsQuery("latLonDVField");
149+
Query dvfeqCsq = new ConstantScoreQuery(dvfeq);
150+
// field with doc-values but not indexed will need to collect
151+
Query dvOnlyfeq = new DocValuesFieldExistsQuery("docValuesOnlyField");
143152
BooleanQuery bq = new BooleanQuery.Builder()
144153
.add(matchAll, Occur.SHOULD)
145154
.add(tq, Occur.MUST)
@@ -150,6 +159,9 @@ private void countTestCase(boolean withDeletions) throws Exception {
150159
countTestCase(tq, reader, withDeletions, withDeletions);
151160
countTestCase(tCsq, reader, withDeletions, withDeletions);
152161
countTestCase(dvfeq, reader, withDeletions, true);
162+
countTestCase(dvfeq_points, reader, withDeletions, true);
163+
countTestCase(dvfeqCsq, reader, withDeletions, true);
164+
countTestCase(dvOnlyfeq, reader, true, true);
153165
countTestCase(bq, reader, true, true);
154166
reader.close();
155167
w.close();

0 commit comments

Comments
 (0)