Error messages are like:
"Invalid aggregation request: data did not match any variant of untagged enum
Aggregation at line 18 column 2"
Currently the top level entry for an aggregation request uses #[serde(untagged)], which is trying to deserialize variants until one works. That's why we always get the above error message.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Aggregation {
/// Bucket aggregation, see [BucketAggregation] for details.
Bucket(BucketAggregation),
/// Metric aggregation, see [MetricAggregation] for details.
Metric(MetricAggregation),
}
Effectively Aggregations are externally tagged (https://serde.rs/enum-representations.html).
{"terms": {...}}
{"histogram": {...}}
So ideally we would just flatten the buckets and metrics into a single enum, but serde does not support flattening on enums (serde-rs/serde#1402).
I see 3 Options currently:
- Wait for/Implement flatten on enums in serde
- Manually flatten the enums to the top-level (Internally that would be just an intermediate struct)
- Use a custom deserializer (Ideally it would only manually implement the matching on the keys ("terms", "histogram", etc.) and use the defaults for the rest)
Error messages are like:
"Invalid aggregation request: data did not match any variant of untagged enum
Aggregation at line 18 column 2"
Currently the top level entry for an aggregation request uses
#[serde(untagged)], which is trying to deserialize variants until one works. That's why we always get the above error message.Effectively Aggregations are externally tagged (https://serde.rs/enum-representations.html).
{"terms": {...}} {"histogram": {...}}So ideally we would just flatten the buckets and metrics into a single enum, but serde does not support flattening on enums (serde-rs/serde#1402).
I see 3 Options currently: