elastiql/aggregation/types/bucket_script.rs
1//! Bucket script aggregation types.
2
3use serde::{Deserialize, Serialize};
4
5use super::GapPolicy;
6
7/// A parent [*pipeline aggregation*] which executes a [script] which can
8/// perform per bucket computations on specified metrics in the parent
9/// multi-bucket aggregation. The specified metric must be numeric and the
10/// script must return a numeric 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 BucketScriptInput {
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 #[serde(skip_serializing_if = "Option::is_none")]
28 pub buckets_path: Option<crate::scalars::Map>,
29
30 /// The policy to apply when gaps are found in the data
31 #[graphql(default_with = "Some(GapPolicy::Skip)")]
32 #[cfg_attr(feature = "builder", builder(default))]
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub gap_policy: Option<GapPolicy>,
35
36 /// Format to apply to the output value of this aggregation
37 #[cfg_attr(feature = "builder", builder(default))]
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub format: Option<String>,
40}
41
42/// A parent [*pipeline aggregation*] which executes a [script] which can
43/// perform per bucket computations on specified metrics in the parent
44/// multi-bucket aggregation. The specified metric must be numeric and the
45/// script must return a numeric value.
46///
47/// [*pipeline aggregation*]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html
48/// [script]: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.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#[derive(Serialize, Deserialize, Clone, Debug)]
53#[cfg_attr(feature = "builder", builder(field_defaults(setter(into))))]
54pub struct BucketScript {
55 /// The script to run for this aggregation.
56 pub script: String,
57
58 /// A map of script variables and their associated path to the buckets to
59 /// use for the variable (see [`buckets_path` Syntax] for more details)
60 ///
61 /// [`buckets_path` Syntax]: /// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html#buckets-path-syntax
62 #[cfg_attr(feature = "builder", builder(default))]
63 #[serde(default, skip_serializing_if = "Option::is_none")]
64 pub buckets_path: Option<crate::scalars::Map>,
65
66 /// The policy to apply when gaps are found in the data
67 #[cfg_attr(feature = "builder", builder(default))]
68 #[serde(default, skip_serializing_if = "Option::is_none")]
69 pub gap_policy: Option<GapPolicy>,
70
71 /// Format to apply to the output value of this aggregation
72 #[cfg_attr(feature = "builder", builder(default))]
73 #[serde(default, skip_serializing_if = "Option::is_none")]
74 pub format: Option<String>,
75}
76
77#[cfg(feature = "graphql")]
78impl From<BucketScriptInput> for BucketScript {
79 #[inline]
80 fn from(input: BucketScriptInput) -> Self {
81 BucketScript {
82 script: input.script,
83 buckets_path: input.buckets_path,
84 gap_policy: input.gap_policy,
85 format: input.format,
86 }
87 }
88}