Skip to content

Commit 74f4a66

Browse files
committed
Aggregations: Fix ReverseNestedAggregator to compute the parent document correctly.
Close elastic#6278
1 parent ae0e701 commit 74f4a66

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,12 @@ public void collect(int childDoc, long bucketOrd) throws IOException {
105105
}
106106

107107
// fast forward to retrieve the parentDoc this childDoc belongs to
108-
int parentDoc = parentDocs.advance(childDoc);
108+
final int parentDoc;
109+
if (parentDocs.docID() < childDoc) {
110+
parentDoc = parentDocs.advance(childDoc);
111+
} else {
112+
parentDoc = parentDocs.docID();
113+
}
109114
assert childDoc <= parentDoc && parentDoc != DocIdSetIterator.NO_MORE_DOCS;
110115
if (bucketOrdToLastCollectedParentDoc.containsKey(bucketOrd)) {
111116
int lastCollectedParentDoc = bucketOrdToLastCollectedParentDoc.lget();

0 commit comments

Comments
 (0)