K - Key type.V - Value type.public static class AggregateArgs.Builder<K,V> extends Object
AggregateArgs.| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
AggregateArgs.Builder<K,V> |
addScores()
Set ADDSCORES flag to expose full-text search scores.
|
AggregateArgs.Builder<K,V> |
apply(AggregateArgs.Apply<K,V> apply)
Add an APPLY clause.
|
AggregateArgs.Builder<K,V> |
apply(V expression,
K name)
Convenience method to add an APPLY clause.
|
AggregateArgs<K,V> |
build()
Build the
AggregateArgs. |
AggregateArgs.Builder<K,V> |
dialect(QueryDialects dialect)
Set the query dialect.
|
AggregateArgs.Builder<K,V> |
filter(V filter)
Add a FILTER clause for post-aggregation filtering.
|
AggregateArgs.Builder<K,V> |
groupBy(AggregateArgs.GroupBy<K,V> groupBy)
Add a GROUPBY clause.
|
AggregateArgs.Builder<K,V> |
groupBy(K... properties)
Convenience method to add a GROUPBY clause with properties.
|
AggregateArgs.Builder<K,V> |
limit(long offset,
long num)
Set LIMIT clause for pagination.
|
AggregateArgs.Builder<K,V> |
load(K field)
Load document attributes from the source document.
|
AggregateArgs.Builder<K,V> |
load(K field,
K alias)
Load document attributes from the source document with alias.
|
AggregateArgs.Builder<K,V> |
loadAll()
Load all document attributes.
|
AggregateArgs.Builder<K,V> |
param(K name,
V value)
Add a parameter for parameterized queries.
|
AggregateArgs.Builder<K,V> |
scorer(V scorer)
Set SCORER clause.
|
AggregateArgs.Builder<K,V> |
sortBy(AggregateArgs.SortBy<K> sortBy)
Add a SORTBY clause.
|
AggregateArgs.Builder<K,V> |
sortBy(K property,
AggregateArgs.SortDirection direction)
Convenience method to add a SORTBY clause with a single property.
|
AggregateArgs.Builder<K,V> |
timeout(Duration timeout)
Set timeout for the aggregate operation.
|
AggregateArgs.Builder<K,V> |
verbatim()
Set VERBATIM flag - do not try to use stemming for query expansion.
|
AggregateArgs.Builder<K,V> |
withCursor(AggregateArgs.WithCursor withCursor)
Set WITHCURSOR clause for cursor-based pagination.
|
public AggregateArgs.Builder<K,V> 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<K,V> load(K 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<K,V> load(K field, K 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<K,V> 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<K,V> timeout(Duration timeout)
timeout - the timeout durationpublic AggregateArgs.Builder<K,V> groupBy(AggregateArgs.GroupBy<K,V> groupBy)
groupBy - the group by specificationpublic AggregateArgs.Builder<K,V> sortBy(AggregateArgs.SortBy<K> sortBy)
sortBy - the sort by specificationpublic AggregateArgs.Builder<K,V> apply(AggregateArgs.Apply<K,V> apply)
apply - the apply specificationpublic AggregateArgs.Builder<K,V> 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<K,V> filter(V 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<K,V> 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 io.lettuce.core.api.RediSearchCommands#ftCursorread(Object, long) and
io.lettuce.core.api.RediSearchCommands#ftCursordel(Object, long) to iterate through and manage the cursor.
withCursor - the cursor specification with count and optional idle timeoutpublic AggregateArgs.Builder<K,V> param(K name, V value)
Defines a value parameter that can be referenced in the query using $name. Each parameter reference in the
search query is substituted by the corresponding parameter value. This is useful for dynamic queries and prevents
injection attacks.
Note: To use PARAMS, set DIALECT to 2 or greater.
// Define parameters
AggregateArgs.builder()
.param("category", "electronics")
.param("min_price", "100")
.dialect(QueryDialects.DIALECT2)
.build();
// Use in query: "@category:$category @price:[$min_price +inf]"
name - the parameter name (referenced as $name in query)value - the parameter valuepublic AggregateArgs.Builder<K,V> scorer(V scorer)
scorer - the scorer functionpublic AggregateArgs.Builder<K,V> 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<K,V> dialect(QueryDialects dialect)
dialect - the query dialect@SafeVarargs public final AggregateArgs.Builder<K,V> groupBy(K... properties)
properties - the properties to group bypublic AggregateArgs.Builder<K,V> sortBy(K property, AggregateArgs.SortDirection direction)
property - the property to sort bydirection - the sort directionpublic AggregateArgs.Builder<K,V> apply(V expression, K name)
expression - the expression to applyname - the result field namepublic AggregateArgs<K,V> build()
AggregateArgs.AggregateArgs.Copyright © 2025 lettuce.io. All rights reserved.