elasticsearch_dsl/search/aggregations/
mod.rs

1//! An aggregation summarizes your data as metrics, statistics, or other analytics.
2//!
3//! Aggregations help you answer questions like:
4//!
5//! 1. What’s the average load time for my website?
6//! 2. Who are my most valuable customers based on transaction volume?
7//! 3. What would be considered a large file on my network?
8//! 4. How many products are in each product category?
9//!
10//! Elasticsearch organizes aggregations into three categories:
11//!
12//! - [Metrics](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics.html) aggregations that calculate metrics, such as a sum or average, from field values.
13//! - [Bucket](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket.html) aggregations that group documents into buckets, also called bins, based on field values, ranges, or other criteria.
14//! - [Pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html) aggregations that take input from other aggregations instead of documents or fields.
15
16pub mod bucket;
17pub mod metrics;
18pub mod params;
19pub mod pipeline;
20
21use crate::Map;
22
23pub use self::bucket::*;
24pub use self::metrics::*;
25pub use self::params::*;
26pub use self::pipeline::*;
27
28macro_rules! aggregation {
29    ($($variant:ident($query:ty)),+ $(,)?) => {
30        /// A container enum for supported Elasticsearch query types
31        #[derive(Clone, PartialEq, Serialize)]
32        #[serde(untagged)]
33        #[allow(missing_docs, clippy::large_enum_variant)]
34        pub enum Aggregation {
35            $(
36                $variant($query),
37            )*
38        }
39
40        impl std::fmt::Debug for Aggregation {
41            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42                match self {
43                    $(
44                        Self::$variant(q) => q.fmt(f),
45                    )+
46                }
47            }
48        }
49
50        $(
51            impl From<$query> for Aggregation {
52                fn from(q: $query) -> Self {
53                    Aggregation::$variant(q)
54                }
55            }
56        )+
57    };
58}
59
60aggregation!(
61    Terms(TermsAggregation),
62    TopHits(TopHitsAggregation),
63    Cardinality(CardinalityAggregation),
64    Avg(AvgAggregation),
65    Max(MaxAggregation),
66    Min(MinAggregation),
67    Sum(SumAggregation),
68    Rate(RateAggregation),
69    Sampler(SamplerAggregation),
70    Filter(FilterAggregation),
71    DiversifiedSampler(DiversifiedSamplerAggregation),
72    Boxplot(BoxplotAggregation),
73    DateHistogram(DateHistogramAggregation),
74    GeotileGrid(GeotileGridAggregation),
75    BucketSelector(BucketSelectorAggregation),
76    Children(ChildrenAggregation),
77    Composite(CompositeAggregation),
78    Nested(NestedAggregation),
79);
80
81/// Type alias for a collection of aggregations
82pub type Aggregations = Map<AggregationName, Aggregation>;