elastiql/aggregation/types/bucket_selector.rs
1//! Bucket selector aggregation types.
2
3use serde::{Deserialize, Serialize};
4
5use super::GapPolicy;
6
7/// A parent [*pipeline aggregation*] which executes a [script] which
8/// determines whether the current bucket will be retained in the parent
9/// multi-bucket aggregation. The specified metric must be numeric and the
10/// script must return a boolean value.
11///
12/// [*pipeline aggregation*]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html
13/// [script]: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
14#[cfg(feature = "graphql")]
15#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
16#[derive(async_graphql::InputObject, Serialize, Clone, Debug)]
17#[cfg_attr(feature = "builder", builder(field_defaults(setter(into))))]
18pub struct BucketSelectorInput {
19 /// The script to run for this aggregation.
20 pub script: String,
21
22 /// A map of script variables and their associated path to the buckets to
23 /// use for the variable (see [`buckets_path` Syntax] for more details)
24 ///
25 /// [`buckets_path` Syntax]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#buckets-path-syntax
26 #[cfg_attr(feature = "builder", builder(default))]
27 pub buckets_path: crate::scalars::Map,
28
29 /// The policy to apply when gaps are found in the data
30 #[graphql(default_with = "Some(GapPolicy::Skip)")]
31 #[cfg_attr(feature = "builder", builder(default))]
32 #[serde(skip_serializing_if = "Option::is_none")]
33 pub gap_policy: Option<GapPolicy>,
34}
35
36/// A parent [*pipeline aggregation*] which executes a [script] which
37/// determines whether the current bucket will be retained in the parent
38/// multi-bucket aggregation. The specified metric must be numeric and the
39/// script must return a boolean value.
40///
41/// [*pipeline aggregation*]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html
42/// [script]: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
43#[cfg_attr(test, derive(PartialEq))]
44#[cfg_attr(feature = "graphql", derive(async_graphql::SimpleObject))]
45#[cfg_attr(feature = "builder", derive(typed_builder::TypedBuilder))]
46#[derive(Serialize, Deserialize, Clone, Debug)]
47#[cfg_attr(feature = "builder", builder(field_defaults(setter(into))))]
48pub struct BucketSelector {
49 /// The script to run for this aggregation.
50 pub script: String,
51
52 /// A map of script variables and their associated path to the buckets to
53 /// use for the variable (see [`buckets_path` Syntax] for more details)
54 ///
55 /// [`buckets_path` Syntax]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#buckets-path-syntax
56 #[cfg_attr(feature = "builder", builder(default))]
57 pub buckets_path: crate::scalars::Map,
58
59 /// The policy to apply when gaps are found in the data
60 #[cfg_attr(feature = "builder", builder(default))]
61 #[serde(default, skip_serializing_if = "Option::is_none")]
62 pub gap_policy: Option<GapPolicy>,
63}
64
65#[cfg(feature = "graphql")]
66impl From<BucketSelectorInput> for BucketSelector {
67 #[inline]
68 fn from(input: BucketSelectorInput) -> Self {
69 BucketSelector {
70 script: input.script,
71 buckets_path: input.buckets_path,
72 gap_policy: input.gap_policy,
73 }
74 }
75}