pub enum MetricSpec {
Count,
Sum {
field: String,
},
Avg {
field: String,
},
Min {
field: String,
},
Max {
field: String,
},
}Expand description
Which metric to compute and (for aggregations) which field to aggregate over.
This is a “tagged enum” — serde uses the “type” JSON key to decide which
variant to deserialize into. For example:
{ "type": "COUNT" } → MetricSpec::Count
{ "type": "SUM", "field": "price" } → MetricSpec::Sum { field: “price” }
#[serde(tag = "type")] tells serde to use the “type” field as the discriminant.
Variants§
Count
Count the number of matching documents. No field needed.
JSON: { "type": "COUNT" }
Sum
Sum the numeric values of a field across all matching documents.
JSON: { "type": "SUM", "field": "price" }
Avg
Compute the arithmetic mean (average) of a field.
JSON: { "type": "AVG", "field": "score" }
Min
Find the smallest value of a field across all matching documents.
JSON: { "type": "MIN", "field": "age" }
Max
Find the largest value of a field across all matching documents.
JSON: { "type": "MAX", "field": "age" }