elastiql/aggregation/types/variable_width_histogram.rs
1//! [Variable width histogram] aggregation types.
2//!
3//! [Variable width histogram]: https://www.elastic.co/guide/en/elasticsearch/reference/latest/search-aggregations-bucket-variablewidthhistogram-aggregation.html
4
5use serde::{Deserialize, Serialize};
6
7/// [Variable width histogram] is a [*multi-bucket*] aggregation similar to
8/// [histogram]. However, the width of each bucket is not specified. Rather, a
9/// target number of buckets is provided and bucket intervals are dynamically
10/// determined based on the document distribution. This is done using a simple
11/// one-pass document clustering algorithm that aims to obtain low distances
12/// between bucket centroids. Unlike other multi-bucket aggregations, the
13/// intervals will not necessarily have a uniform width.
14///
15/// **Note**: until GraphQL [Union input types] are supported, either
16/// `calendarInterval` or `fixedInterval` *must* be specified but *not* both.
17///
18/// [Variable width histogram]: https://www.elastic.co/guide/en/elasticsearch/reference/latest/search-aggregations-bucket-variablewidthhistogram-aggregation.html
19/// [Union input types]: https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md
20/// [histogram]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
21/// [*multi-bucket*]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket.html
22#[cfg(feature = "graphql")]
23#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
24#[cfg_attr(feature = "builder", builder(field_defaults(setter(into))))]
25#[derive(async_graphql::InputObject, Serialize, Clone, Debug)]
26pub struct VariableWidthHistogramInput {
27 /// The field to perform the aggregation over.
28 pub field: String,
29
30 /// The target number of buckets.
31 pub buckets: u64,
32}
33
34/// [Variable width histogram] is a [*multi-bucket*] aggregation similar to
35/// [histogram]. However, the width of each bucket is not specified. Rather, a
36/// target number of buckets is provided and bucket intervals are dynamically
37/// determined based on the document distribution. This is done using a simple
38/// one-pass document clustering algorithm that aims to obtain low distances
39/// between bucket centroids. Unlike other multi-bucket aggregations, the
40/// intervals will not necessarily have a uniform width.
41///
42/// **Note**: until GraphQL [Union input types] are supported, either
43/// `calendarInterval` or `fixedInterval` *must* be specified but *not* both.
44///
45/// [Variable width histogram]: https://www.elastic.co/guide/en/elasticsearch/reference/latest/search-aggregations-bucket-variablewidthhistogram-aggregation.html
46/// [Union input types]: https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md
47/// [histogram]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html
48/// [*multi-bucket*]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket.html
49#[cfg_attr(test, derive(PartialEq))]
50#[cfg_attr(feature = "graphql", derive(async_graphql::SimpleObject))]
51#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
52#[cfg_attr(feature = "builder", builder(field_defaults(setter(into))))]
53#[derive(Serialize, Deserialize, Clone, Debug)]
54pub struct VariableWidthHistogram {
55 /// The field to perform the aggregation over.
56 #[cfg_attr(feature = "builder", builder(!default))]
57 pub field: String,
58
59 /// The target number of buckets.
60 pub buckets: u64,
61}
62
63#[cfg(feature = "graphql")]
64impl From<VariableWidthHistogramInput> for VariableWidthHistogram {
65 #[inline]
66 fn from(input: VariableWidthHistogramInput) -> Self {
67 Self {
68 field: input.field,
69 buckets: input.buckets,
70 }
71 }
72}