redis/jedis · error · NoSuchElementException

No more aggregation results available

Error message

No more aggregation results available

What it means

Thrown by AggregateIterator.next() when called after the aggregation cursor is exhausted: the current batch was already returned, and there is no cursorId left to fetch the next batch. It is a standard Iterator contract violation (NoSuchElementException), signalling the caller iterated past the end of the aggregation results.

Solutions

  1. Guard every next() call with hasNext() and stop iterating when it returns false
  2. Use a for-each loop or the iterator in a standard while(hasNext()) pattern instead of manual index-based loops
  3. If you need to re-run the aggregation, build a new AggregateIterator rather than reusing the exhausted one

Example fix

// before
AggregationResult r = iterator.next(); // NoSuchElementException after exhaustion
// after
while (iterator.hasNext()) {
  AggregationResult r = iterator.next();
  // process batch
}
Defensive patterns

Strategy: type-guard

Validate before calling

// call site guard
if (!iterator.hasNext()) return; // or break the loop

Type guard

boolean canAdvance(java.util.Iterator<AggregationResult> it) {
  return it != null && it.hasNext();
}

Try / catch

try {
  AggregationResult r = iterator.next();
} catch (java.util.NoSuchElementException e) {
  // iteration past end — treat as loop-exit bug, not a data error
}

Prevention

When it happens

Trigger: Calling next() again after hasNext() returns false — i.e. after the initial batch was consumed and cursorId is null or 0.

Common situations: Manual while loops without checking hasNext(); calling next() a fixed number of times assuming a batch size; reusing an exhausted AggregateIterator for a second pass.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/98ec0a14d07b5f2b. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/search/aggr/AggregateIterator.java:110

      throw new JedisException("No connections available from connection provider");
    }
    // Randomly select an entry from the map to distribute load across shards
    List<? extends Map.Entry<?, ?>> entries = new ArrayList<>(connectionMap.entrySet());
    this.connectionEntry = entries.get(ThreadLocalRandom.current().nextInt(entries.size()));

    // Execute initial aggregation command
    initializeAggregation(aggregationBuilder);
  }

  @Override
  public boolean hasNext() {
    return aggrCommandResult != null || cursorId != null && cursorId > 0;
  }

  @Override
  public AggregationResult next() {
    if (!hasNext()) {
      throw new NoSuchElementException("No more aggregation results available");
    }

    try {
      if (aggrCommandResult != null) {
        try {
          return aggrCommandResult;
        } finally {
          aggrCommandResult = null;
        }
      } else {
        return doFetch();
      }

    } catch (Exception e) {
      throw new JedisException("Failed to fetch next aggregation batch", e);
    }
  }

View on GitHub (pinned to 6dac31d4c2)