The ClosestNestedParentFilter#equals is invoked once the parent agg is completely constructed (FilterCacheFilterWrapper#getDocIdSet). I agree it is tricky, but I think the fix is ok? Maybe we need more assertions to double check.