Skip to content

Commit 7eb727c

Browse files
committed
nested value fetcher for docvalues
1 parent 7a7c20c commit 7eb727c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

server/src/main/java/org/elasticsearch/index/mapper/NestedValueFetcher.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
import org.elasticsearch.common.document.DocumentField;
1212
import org.elasticsearch.common.xcontent.support.XContentMapValues;
13+
import org.elasticsearch.search.DocValueFormat;
1314
import org.elasticsearch.search.fetch.subphase.FieldFetcher;
15+
import org.elasticsearch.search.lookup.SourceLookup;
1416
import org.elasticsearch.search.lookup.ValuesLookup;
1517

1618
import java.io.IOException;
@@ -42,6 +44,21 @@ public List<Object> fetchValues(ValuesLookup lookup) throws IOException {
4244
List<Object> nestedEntriesToReturn = new ArrayList<>();
4345
Map<String, Object> filteredSource = new HashMap<>();
4446
Map<String, Object> stub = createSourceMapStub(filteredSource);
47+
SourceLookup filteredSourceLookup = new SourceLookup();
48+
filteredSourceLookup.setSource(filteredSource);
49+
// DocValues will not work here because we are not positioned correctly,
50+
// so we just return an empty list
51+
ValuesLookup filteredLookup = new ValuesLookup() {
52+
@Override
53+
public SourceLookup source() {
54+
return filteredSourceLookup;
55+
}
56+
57+
@Override
58+
public List<Object> docValues(String field, DocValueFormat format) {
59+
return Collections.emptyList();
60+
}
61+
};
4562
List<?> nestedValues = XContentMapValues.extractNestedValue(nestedFieldPath, lookup.source());
4663
if (nestedValues == null) {
4764
return Collections.emptyList();
@@ -50,8 +67,7 @@ public List<Object> fetchValues(ValuesLookup lookup) throws IOException {
5067
// add this one entry only to the stub and use this as source lookup
5168
stub.put(nestedFieldName, entry);
5269

53-
Map<String, DocumentField> fetchResult
54-
= nestedFieldFetcher.fetch(ValuesLookup.sourceOnly(filteredSource));
70+
Map<String, DocumentField> fetchResult = nestedFieldFetcher.fetch(filteredLookup);
5571

5672
Map<String, Object> nestedEntry = new HashMap<>();
5773
for (DocumentField field : fetchResult.values()) {

0 commit comments

Comments
 (0)