public class AggregateIterator extends java.lang.Object implements java.util.Iterator<AggregationResult>, java.io.Closeable
The iterator supports the remove() method which deletes the cursor on the server and
terminates the iteration, freeing server resources immediately.
This implementation uses connection pooling to prevent connection pool exhaustion during long-running aggregation operations. Connections are borrowed from the pool for each batch operation and returned immediately after use.
Usage example:
{
@code
// 100 results per batch, 60 second TTL for the cursor
AggregationBuilder aggr = new AggregationBuilder().groupBy("@field").cursor(100, 60000);
try (AggregateIterator iterator = new AggregateIterator(provider, "myindex", aggr)) {
while (iterator.hasNext()) {
AggregationResult batch = iterator.next();
if (batch.isEmpty()) {
break; // FT.AGGREGATE returned empty result set
}
// Process batch - access rows via batch.getRows()
// Optionally terminate early and free server resources
if (someCondition) {
iterator.remove(); // Deletes cursor and stops iteration
break;
}
}
}
}
| Constructor and Description |
|---|
AggregateIterator(ConnectionProvider connectionProvider,
java.lang.String indexName,
AggregationBuilder aggregationBuilder)
Creates a new AggregateIterator.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
java.lang.Long |
getCursorId()
Returns the current cursor ID.
|
boolean |
hasNext() |
AggregationResult |
next() |
void |
remove() |
public AggregateIterator(ConnectionProvider connectionProvider, java.lang.String indexName, AggregationBuilder aggregationBuilder)
connectionProvider - the connection provider for cluster/standalone RedisindexName - the search index nameaggregationBuilder - the aggregation query with cursor configurationjava.lang.IllegalArgumentException - if aggregation doesn't have cursor configuredpublic boolean hasNext()
hasNext in interface java.util.Iterator<AggregationResult>public AggregationResult next()
next in interface java.util.Iterator<AggregationResult>public java.lang.Long getCursorId()
public void remove()
remove in interface java.util.Iterator<AggregationResult>public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableCopyright © 2026. All rights reserved.