elasticsearch_dsl/search/aggregations/bucket/
children_aggregation.rs1use crate::search::*;
2use crate::util::*;
3use serde::Serialize;
4
5#[derive(Debug, Clone, Serialize, PartialEq)]
6pub struct ChildrenAggregation {
11 children: ChildrenAggregationInner,
12
13 #[serde(skip_serializing_if = "ShouldSkip::should_skip")]
14 aggs: Aggregations,
15}
16
17#[derive(Debug, Clone, Serialize, PartialEq)]
18struct ChildrenAggregationInner {
19 #[serde(rename = "type")]
20 type_: String,
21}
22
23impl Aggregation {
24 pub fn children<T>(type_: T) -> ChildrenAggregation
28 where
29 T: ToString,
30 {
31 ChildrenAggregation {
32 children: ChildrenAggregationInner {
33 type_: type_.to_string(),
34 },
35 aggs: Aggregations::new(),
36 }
37 }
38}
39
40impl ChildrenAggregation {
41 add_aggregate!();
42}
43
44#[cfg(test)]
45mod tests {
46 use super::*;
47
48 #[test]
49 fn serialization() {
50 assert_serialize_aggregation(
51 Aggregation::children("answer"),
52 json!({ "children": { "type": "answer" } }),
53 );
54
55 assert_serialize_aggregation(
56 Aggregation::children("answer").aggregate("avg_score", Aggregation::avg("score")),
57 json!({
58 "children": {
59 "type": "answer"
60 },
61 "aggs": {
62 "avg_score": {
63 "avg": {
64 "field": "score"
65 }
66 }
67 }
68 }),
69 );
70 }
71}