From b3274bd770c01c6166bc2ad52e327e879c331c95 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 22 May 2014 14:44:32 +0200 Subject: [PATCH] Aggregations: Fix ReverseNestedAggregator to compute the parent document correctly. Close #6278 --- .../bucket/nested/ReverseNestedAggregator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java index ac0dad6335a..b08aae29c15 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedAggregator.java @@ -105,7 +105,12 @@ public class ReverseNestedAggregator extends SingleBucketAggregator implements R } // fast forward to retrieve the parentDoc this childDoc belongs to - int parentDoc = parentDocs.advance(childDoc); + final int parentDoc; + if (parentDocs.docID() < childDoc) { + parentDoc = parentDocs.advance(childDoc); + } else { + parentDoc = parentDocs.docID(); + } assert childDoc <= parentDoc && parentDoc != DocIdSetIterator.NO_MORE_DOCS; if (bucketOrdToLastCollectedParentDoc.containsKey(bucketOrd)) { int lastCollectedParentDoc = bucketOrdToLastCollectedParentDoc.lget();