public static class AggregateArgs.Builder extends Object
AggregateArgs.| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
AggregateArgs.Builder |
addScores()
Set ADDSCORES flag to expose full-text search scores.
|
AggregateArgs.Builder |
apply(AggregateArgs.Apply apply)
Add an APPLY clause.
|
AggregateArgs.Builder |
apply(String expression,
String name)
Convenience method to add an APPLY clause.
|
AggregateArgs |
build()
Build the
AggregateArgs. |
AggregateArgs.Builder |
dialect(QueryDialects dialect)
Set the query dialect.
|
AggregateArgs.Builder |
filter(String filter)
Add a FILTER clause for post-aggregation filtering.
|
AggregateArgs.Builder |
groupBy(AggregateArgs.GroupBy groupBy)
Add a GROUPBY clause.
|
AggregateArgs.Builder |
groupBy(String... properties)
Convenience method to add a GROUPBY clause with properties.
|
AggregateArgs.Builder |
limit(long offset,
long num)
Set LIMIT clause for pagination.
|
AggregateArgs.Builder |
load(String field)
Load document attributes from the source document.
|
AggregateArgs.Builder |
load(String field,
String alias)
Load document attributes from the source document with alias.
|
AggregateArgs.Builder |
loadAll()
Load all document attributes.
|
AggregateArgs.Builder |
param(String name,
byte[] value)
Add a binary query parameter, for example the query vector of a KNN clause (
*=>[KNN 10 @embedding $vec]). |
AggregateArgs.Builder |
param(String name,
String value)
Add a query parameter.
|
AggregateArgs.Builder |
scorer(String scorer)
Set SCORER clause.
|
AggregateArgs.Builder |
sortBy(AggregateArgs.SortBy sortBy)
Add a SORTBY clause.
|
AggregateArgs.Builder |
sortBy(String property,
AggregateArgs.SortDirection direction)
Convenience method to add a SORTBY clause with a single property.
|
AggregateArgs.Builder |
timeout(Duration timeout)
Set timeout for the aggregate operation.
|
AggregateArgs.Builder |
verbatim()
Set VERBATIM flag - do not try to use stemming for query expansion.
|
AggregateArgs.Builder |
withCursor(AggregateArgs.WithCursor withCursor)
Set WITHCURSOR clause for cursor-based pagination.
|
public AggregateArgs.Builder verbatim()
When set, the query terms are searched verbatim without attempting to use stemming for query expansion. This is useful when you want exact matches for your search terms.
public AggregateArgs.Builder load(String field)
Loads the specified field from the source document. For hash documents, this is the field name. For JSON documents, this can be a JSONPath expression.
Performance Note: LOAD operations can significantly hurt performance as they require HMGET operations on each processed record. Consider storing frequently accessed attributes as SORTABLE for better performance.
field - the field identifier (field name for hashes, JSONPath for JSON)public AggregateArgs.Builder load(String field, String alias)
Loads the specified field from the source document and assigns it an alias name for use in the aggregation pipeline. The alias can be referenced in subsequent GROUPBY, SORTBY, APPLY, and FILTER operations.
field - the field identifier (field name for hashes, JSONPath for JSON)alias - the alias name to use in the resultpublic AggregateArgs.Builder loadAll()
Equivalent to using LOAD * in the Redis command. This loads all attributes from the source documents. Use
with caution as this can significantly impact performance when dealing with large documents or many results.
public AggregateArgs.Builder timeout(Duration timeout)
timeout - the timeout durationpublic AggregateArgs.Builder groupBy(AggregateArgs.GroupBy groupBy)
groupBy - the group by specificationpublic AggregateArgs.Builder sortBy(AggregateArgs.SortBy sortBy)
sortBy - the sort by specificationpublic AggregateArgs.Builder apply(AggregateArgs.Apply apply)
apply - the apply specificationpublic AggregateArgs.Builder limit(long offset, long num)
Limits the number of results to return just num results starting at index offset (zero-based). This
is useful for pagination of results.
Performance Note: It is much more efficient to use SORTBY ... MAX if you are only interested
in limiting the output of a sort operation. Use LIMIT for pagination or when you need results without sorting.
// Get results 50-100 of the top 100 results efficiently
.sortBy("score", SortDirection.DESC).max(100)
.limit(50, 50)
offset - the zero-based starting indexnum - the maximum number of results to returnpublic AggregateArgs.Builder filter(String filter)
Filters the results using predicate expressions relating to values in each result. Filters are applied after the query and relate to the current state of the pipeline. This allows filtering on computed fields created by APPLY operations or reducer results.
// Filter by numeric comparison
.filter("@price > 100")
// Filter by computed field
.apply("@price * @quantity", "total_value")
.filter("@total_value > 1000")
// Filter by reducer result
.groupBy("category").reduce(Reducer.count().as("count"))
.filter("@count >= 5")
filter - the filter expression (e.g., "@price > 100", "@category == 'electronics'")public AggregateArgs.Builder withCursor(AggregateArgs.WithCursor withCursor)
Enables cursor-based pagination as a quicker alternative to LIMIT for scanning through large result sets. This is particularly useful when you need to process all results but want to avoid memory issues with very large datasets.
// Basic cursor with read size
.withCursor(WithCursor.of(1000L))
// Cursor with read size and idle timeout
.withCursor(WithCursor.of(1000L, Duration.ofMinutes(5)))
Use RediSearchCommands.ftCursorread(String, AggregationReply.Cursor, int) and
RediSearchCommands.ftCursordel(String, AggregationReply.Cursor) to iterate through
and manage the cursor.
withCursor - the cursor specification with count and optional idle timeoutpublic AggregateArgs.Builder param(String name, String value)
$name and the server substitutes the value wherever that
reference appears, so values need no escaping and cannot alter the query structure, for example
param("category", "electronics") with the query @category:{$category}. The value is sent as UTF-8
text. Adding a parameter with the same name again replaces its value.
Requires QueryDialects.DIALECT2 or higher.
name - the parameter name, referenced as $name in the query, must not be nullvalue - the parameter value, must not be nullpublic AggregateArgs.Builder param(String name, byte[] value)
*=>[KNN 10 @embedding $vec]). The
bytes are sent exactly as given, which the String overload cannot do for arbitrary binary data. The query
references the parameter as $name; adding a parameter with the same name again replaces its value.
Requires QueryDialects.DIALECT2 or higher.
name - the parameter name, referenced as $name in the query, must not be nullvalue - the binary parameter value, sent as-is, must not be nullpublic AggregateArgs.Builder scorer(String scorer)
scorer - the scorer functionpublic AggregateArgs.Builder addScores()
The ADDSCORES option exposes the full-text score values to the aggregation pipeline. You can then use
@__score in subsequent pipeline operations like SORTBY, APPLY, FILTER, and GROUPBY.
// Sort by search relevance score
AggregateArgs.builder()
.addScores()
.sortBy("__score", SortDirection.DESC)
.build();
// Filter by minimum score threshold
AggregateArgs.builder()
.addScores()
.filter("@__score > 0.5")
.build();
public AggregateArgs.Builder dialect(QueryDialects dialect)
dialect - the query dialect@SafeVarargs public final AggregateArgs.Builder groupBy(String... properties)
properties - the properties to group bypublic AggregateArgs.Builder sortBy(String property, AggregateArgs.SortDirection direction)
property - the property to sort bydirection - the sort directionpublic AggregateArgs.Builder apply(String expression, String name)
expression - the expression to applyname - the result field namepublic AggregateArgs build()
AggregateArgs.AggregateArgs.Copyright © 2026 lettuce.io. All rights reserved.