Grouping
vespa.querybuilder.grouping.grouping
Grouping
A Pythonic DSL for building Vespa grouping expressions programmatically.
This class provides a set of static methods that build grouping syntax strings which can be combined to form a valid Vespa “select=…” grouping expression.
For a guide to grouping in vespa, see https://docs.vespa.ai/en/grouping.html. For the reference docs, see https://docs.vespa.ai/en/reference/grouping-syntax.html.
Minimal Example
from vespa.querybuilder import Grouping as G
# Build a simple grouping expression which groups on "my_attribute"
# and outputs the count of matching documents under each group:
expr = G.all(
G.group("my_attribute"),
G.each(
G.output(G.count())
)
)
print(expr)
all(group(my_attribute) each(output(count())))
In the above example, the “all(...)” wraps the grouping operations at the top level. We first group on “my_attribute”, then under “each(...)” we add an output aggregator “count()”. The “print” output is the exact grouping expression string you would pass to Vespa in the “select” query parameter.
For multi-level (nested) grouping, you can nest additional calls to “group(...)” or “each(...)” inside. For example:
# Nested grouping:
# 1) Group by 'category'
# 2) Within each category, group by 'sub_category'
# 3) Output the count() under each sub-category
nested_expr = G.all(
G.group("category"),
G.each(
G.group("sub_category"),
G.each(
G.output(G.count())
)
)
)
print(nested_expr)
all(group(category) each(group(sub_category) each(output(count()))))
You may use any of the static methods below to build more advanced groupings, aggregations, or arithmetic/string expressions for sorting, filtering, or bucket definitions. Refer to Vespa documentation for the complete details.
all(*args)
staticmethod
Corresponds to the “all(...)” grouping block in Vespa, which means “group all documents (no top-level grouping) and then do the enclosed operations”.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
str
|
Sub-expressions to include within the |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string. |
each(*args)
staticmethod
Corresponds to the “each(...)” grouping block in Vespa, which means “create a group for each unique value and then do the enclosed operations”.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
str
|
Sub-expressions to include within the |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string. |
group(field)
staticmethod
Defines a grouping step on a field or expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
field
|
str
|
The field or expression on which to group. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string. |
count()
staticmethod
“count()” aggregator.
By default, returns a string 'count()'. Negative ordering or usage can be done by prefixing a minus, e.g.: order(-count()) in Vespa syntax.
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'count()' or prefixed version if used with a minus operator. |
sum(value)
staticmethod
“sum(...)” aggregator. Sums the given expression or field over all documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression to sum. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'sum(...)'. |
avg(value)
staticmethod
“avg(...)” aggregator. Computes the average of the given expression or field for all documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression to average. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'avg(...)'. |
min(value)
staticmethod
“min(...)” aggregator. Keeps the minimum value of the expression or field among all documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression to find the minimum of. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'min(...)'. |
max(value)
staticmethod
“max(...)” aggregator. Keeps the maximum value of the expression or field among all documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression to find the maximum of. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'max(...)'. |
stddev(value)
staticmethod
“stddev(...)” aggregator. Computes the population standard deviation for the expression or field among all documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'stddev(...)'. |
xor(value)
staticmethod
“xor(...)” aggregator. XORs all values of the expression or field together over the documents in the group.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[str, int, float]
|
The field or numeric expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'xor(...)'. |
output(*args)
staticmethod
Defines output aggregators to be collected for the grouping level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Union[str, Expression]
|
Multiple aggregator expressions, e.g., 'count()', 'sum(price)'. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Expression |
Expression
|
A Vespa grouping expression string of the form 'output(...)'. |
order(*args)
staticmethod
Defines an order(...) clause to sort groups by the given expressions or aggregators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args
|
Union[str, Expression]
|
Multiple expressions or aggregators to order by. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Expression |
Expression
|
A Vespa grouping expression string of the form 'order(...)'. |
precision(value)
staticmethod
Sets the “precision(...)” for the grouping step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
int
|
Precision value. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'precision(...)'. |
add(*expressions)
staticmethod
“add(...)” expression. Adds all arguments together in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to be added. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'add(expr1, expr2, ...)'. |
sub(*expressions)
staticmethod
“sub(...)” expression. Subtracts each subsequent argument from the first.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions involved in subtraction. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'sub(expr1, expr2, ...)'. |
mul(*expressions)
staticmethod
“mul(...)” expression. Multiplies all arguments in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to multiply. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'mul(expr1, expr2, ...)'. |
div(*expressions)
staticmethod
“div(...)” expression. Divides the first argument by the second, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to divide in order. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'div(expr1, expr2, ...)'. |
mod(*expressions)
staticmethod
“mod(...)” expression. Modulo the first argument by the second, result by the third, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to apply modulo on in order. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'mod(expr1, expr2, ...)'. |
and_(*expressions)
staticmethod
“and(...)” expression. Bitwise AND of the arguments in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to apply bitwise AND. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'and(expr1, expr2, ...)'. |
or_(*expressions)
staticmethod
“or(...)” expression. Bitwise OR of the arguments in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to apply bitwise OR. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'or(expr1, expr2, ...)'. |
xor_expr(*expressions)
staticmethod
“xor(...)” bitwise expression.
(Note: For aggregator use, see xor(...) aggregator method above.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The expressions to apply bitwise XOR. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'xor(expr1, expr2, ...)'. |
strlen(expr)
staticmethod
“strlen(...)” expression. Returns the number of bytes in the string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The string field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'strlen(...)'. |
strcat(*expressions)
staticmethod
“strcat(...)” expression. Concatenate all string arguments in order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The string expressions to concatenate. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'strcat(expr1, expr2, ...)'. |
todouble(expr)
staticmethod
“todouble(...)” expression. Convert argument to double.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'todouble(...)'. |
tolong(expr)
staticmethod
“tolong(...)” expression. Convert argument to long.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'tolong(...)'. |
tostring(expr)
staticmethod
“tostring(...)” expression. Convert argument to string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'tostring(...)'. |
toraw(expr)
staticmethod
“toraw(...)” expression. Convert argument to raw data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to convert. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'toraw(...)'. |
cat(*expressions)
staticmethod
“cat(...)” expression. Concatenate the binary representation of arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*expressions
|
str
|
The binary expressions or fields to concatenate. |
()
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'cat(expr1, expr2, ...)'. |
md5(expr, width)
staticmethod
“md5(...)” expression.
Does an MD5 over the binary representation of the argument, and keeps the lowest 'width' bits.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to apply MD5 on. |
required |
width
|
int
|
The number of bits to keep. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'md5(expr, width)'. |
xorbit(expr, width)
staticmethod
“xorbit(...)” expression.
Performs an XOR of 'width' bits over the binary representation of the argument. Width is rounded up to a multiple of 8.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field to apply xorbit on. |
required |
width
|
int
|
The number of bits for the XOR operation. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'xorbit(expr, width)'. |
relevance()
staticmethod
array_at(array_name, index_expr)
staticmethod
“array.at(...)” accessor expression. Returns a single element from the array at the given index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array_name
|
str
|
The name of the array. |
required |
index_expr
|
Union[str, int]
|
The index or expression that evaluates to an index. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'array.at(array_name, index)'. |
zcurve_x(expr)
staticmethod
“zcurve.x(...)” expression. Returns the X component of the given zcurve-encoded 2D point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The zcurve-encoded field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'zcurve.x(expr)'. |
zcurve_y(expr)
staticmethod
“zcurve.y(...)” expression. Returns the Y component of the given zcurve-encoded 2D point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The zcurve-encoded field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'zcurve.y(expr)'. |
time_dayofmonth(expr)
staticmethod
“time.dayofmonth(...)” expression. Returns the day of month (1-31).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.dayofmonth(expr)'. |
time_dayofweek(expr)
staticmethod
“time.dayofweek(...)” expression. Returns the day of week (0-6), Monday = 0.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.dayofweek(expr)'. |
time_dayofyear(expr)
staticmethod
“time.dayofyear(...)” expression. Returns the day of year (0-365).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.dayofyear(expr)'. |
time_hourofday(expr)
staticmethod
“time.hourofday(...)” expression. Returns the hour of day (0-23).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.hourofday(expr)'. |
time_minuteofhour(expr)
staticmethod
“time.minuteofhour(...)” expression. Returns the minute of hour (0-59).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.minuteofhour(expr)'. |
time_monthofyear(expr)
staticmethod
“time.monthofyear(...)” expression. Returns the month of year (1-12).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.monthofyear(expr)'. |
time_secondofminute(expr)
staticmethod
“time.secondofminute(...)” expression. Returns the second of minute (0-59).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.secondofminute(expr)'. |
time_year(expr)
staticmethod
“time.year(...)” expression. Returns the full year (e.g. 2009).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.year(expr)'. |
time_date(expr)
staticmethod
“time.date(...)” expression. Returns the date (e.g. 2009-01-10).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The timestamp field or expression. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'time.date(expr)'. |
math_exp(expr)
staticmethod
“math.exp(...)” expression. Returns e^expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'math.exp(expr)'. |
math_log(expr)
staticmethod
“math.log(...)” expression. Returns the natural logarithm of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.log(expr)'. |
math_log1p(expr)
staticmethod
“math.log1p(...)” expression. Returns the natural logarithm of (1 + expr).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.log1p(expr)'. |
math_log10(expr)
staticmethod
“math.log10(...)” expression. Returns the base-10 logarithm of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.log10(expr)'. |
math_sqrt(expr)
staticmethod
“math.sqrt(...)” expression. Returns the square root of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.sqrt(expr)'. |
math_cbrt(expr)
staticmethod
“math.cbrt(...)” expression. Returns the cube root of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.cbrt(expr)'. |
math_sin(expr)
staticmethod
“math.sin(...)” expression. Returns the sine of expr (argument in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.sin(expr)'. |
math_cos(expr)
staticmethod
“math.cos(...)” expression. Returns the cosine of expr (argument in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.cos(expr)'. |
math_tan(expr)
staticmethod
“math.tan(...)” expression. Returns the tangent of expr (argument in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.tan(expr)'. |
math_asin(expr)
staticmethod
“math.asin(...)” expression. Returns the arcsine of expr (in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.asin(expr)'. |
math_acos(expr)
staticmethod
“math.acos(...)” expression. Returns the arccosine of expr (in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.acos(expr)'. |
math_atan(expr)
staticmethod
“math.atan(...)” expression. Returns the arctangent of expr (in radians).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.atan(expr)'. |
math_sinh(expr)
staticmethod
“math.sinh(...)” expression. Returns the hyperbolic sine of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.sinh(expr)'. |
math_cosh(expr)
staticmethod
“math.cosh(...)” expression. Returns the hyperbolic cosine of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.cosh(expr)'. |
math_tanh(expr)
staticmethod
“math.tanh(...)” expression. Returns the hyperbolic tangent of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.tanh(expr)'. |
math_asinh(expr)
staticmethod
“math.asinh(...)” expression. Returns the inverse hyperbolic sine of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.asinh(expr)'. |
math_acosh(expr)
staticmethod
“math.acosh(...)” expression. Returns the inverse hyperbolic cosine of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.acosh(expr)'. |
math_atanh(expr)
staticmethod
“math.atanh(...)” expression. Returns the inverse hyperbolic tangent of expr.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.atanh(expr)'. |
math_pow(expr_x, expr_y)
staticmethod
“math.pow(...)” expression. Returns expr_x^expr_y.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr_x
|
str
|
The expression or field for the base. |
required |
expr_y
|
str
|
The expression or field for the exponent. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.pow(expr_x, expr_y)'. |
math_hypot(expr_x, expr_y)
staticmethod
“math.hypot(...)” expression. Returns the length of the hypotenuse given expr_x and expr_y.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr_x
|
str
|
The expression or field for the first side of the triangle. |
required |
expr_y
|
str
|
The expression or field for the second side of the triangle. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
'math.hypot(expr_x, expr_y)'. |
size(expr)
staticmethod
“size(...)” expression. Returns the number of elements if expr is a list; otherwise returns 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The list expression or field. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'size(expr)'. |
sort(expr)
staticmethod
“sort(...)” expression. Sorts the elements of the list argument in ascending order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The list expression or field to sort. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'sort(expr)'. |
reverse(expr)
staticmethod
“reverse(...)” expression. Reverses the elements of the list argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
str
|
The list expression or field to reverse. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'reverse(expr)'. |
fixedwidth(value, bucket_width)
staticmethod
“fixedwidth(...)” bucket expression. Maps the value of the first argument into consecutive buckets whose width is the second argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The field or expression to bucket. |
required |
bucket_width
|
Union[int, float]
|
The width of each bucket. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'fixedwidth(value, bucket_width)'. |
predefined(value, buckets)
staticmethod
“predefined(...)” bucket expression. Maps the value into the provided list of buckets.
Each 'bucket' must be a string representing the range, e.g.: 'bucket(-inf,0)', 'bucket[0,10)', 'bucket[10,inf)', etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
The field or expression to bucket. |
required |
buckets
|
List[str]
|
A list of bucket definitions. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'predefined(value, ( ))'. |
interpolatedlookup(array_attr, lookup_expr)
staticmethod
“interpolatedlookup(...)” expression. Counts elements in a sorted array that are less than an expression, with linear interpolation if the expression is between element values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
array_attr
|
str
|
The sorted array field name. |
required |
lookup_expr
|
str
|
The expression or value to lookup. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa expression string of the form 'interpolatedlookup(array, expr)'. |
summary(summary_class='')
staticmethod
“summary(...)” hit aggregator. Produces a summary of the requested summary class.
If no summary class is specified, “summary()” is used.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
summary_class
|
str
|
Name of the summary class. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
str |
Expression
|
A Vespa grouping expression string of the form 'summary(...)'. |
as_(expression, label)
staticmethod
Appends an ' as(label)' part to a grouping block expression.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expression
|
str
|
The expression to be labeled. |
required |
label
|
str
|
The label to be used. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A Vespa grouping expression string of the form 'expression as(label)' |
alias(alias_name, expression)
staticmethod
Defines an alias(...) grouping syntax. This lets you name an expression, so you can reference it later by $alias_name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
alias_name
|
str
|
The alias name. |
required |
expression
|
str
|
The expression to alias. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A Vespa grouping expression string of the form 'alias(alias_name, expression)'. |