Skip to main content

oxsearch_sql/generated/
translate.rs

1// Generated by `cargo run -p xtask -- generate` from elastic/elasticsearch-specification 9.5 at
2// 84bf510a907bae62ffe29af35f516af287a79eab. Don't edit it: change the generator.
3
4/// The request's body.
5#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
6#[non_exhaustive]
7pub struct RequestBody {
8    /// The maximum number of rows (or entries) to return in one response.
9    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
10    pub fetch_size: ::core::option::Option<i32>,
11    /// The Elasticsearch query DSL for additional filtering.
12    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
13    pub filter: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
14    /// The SQL query to run.
15    pub query: ::std::string::String,
16    /// The ISO-8601 time zone ID for the search.
17    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
18    pub time_zone: ::core::option::Option<::oxsearch_core::TimeZone>,
19}
20
21impl RequestBody {
22    /// A `RequestBody` with its required properties set.
23    pub fn new(query: impl ::core::convert::Into<::std::string::String>) -> Self {
24        Self {
25            fetch_size: ::core::option::Option::None,
26            filter: ::core::option::Option::None,
27            query: query.into(),
28            time_zone: ::core::option::Option::None,
29        }
30    }
31}
32
33impl RequestBody {
34    /// Sets `fetch_size`.
35    pub fn fetch_size(mut self, value: i32) -> Self {
36        self.fetch_size = ::core::option::Option::Some(value.into());
37        self
38    }
39    /// Sets `filter`.
40    pub fn filter(
41        mut self,
42        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
43    ) -> Self {
44        self.filter = ::core::option::Option::Some(value.into());
45        self
46    }
47    /// Sets `time_zone`.
48    pub fn time_zone(
49        mut self,
50        value: impl ::core::convert::Into<::oxsearch_core::TimeZone>,
51    ) -> Self {
52        self.time_zone = ::core::option::Option::Some(value.into());
53        self
54    }
55}
56
57/// Translate SQL into Elasticsearch queries.
58///
59/// Translate an SQL search into a search API request containing Query DSL.
60/// It accepts the same request body parameters as the SQL search API, excluding `cursor`.
61#[derive(Clone, Debug, PartialEq)]
62#[non_exhaustive]
63pub struct Request {
64    /// The body.
65    pub body: ::core::option::Option<crate::translate::RequestBody>,
66}
67
68impl Request {
69    /// A `Request` with its required properties set.
70    pub fn new() -> Self {
71        Self {
72            body: ::core::option::Option::None,
73        }
74    }
75}
76
77impl Request {
78    /// Sets `body`.
79    pub fn body(
80        mut self,
81        value: impl ::core::convert::Into<crate::translate::RequestBody>,
82    ) -> Self {
83        self.body = ::core::option::Option::Some(value.into());
84        self
85    }
86}
87
88#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
89#[non_exhaustive]
90pub struct Response {
91    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
92    pub aggregations: ::core::option::Option<
93        ::indexmap::IndexMap<::std::string::String, ::oxsearch_aggs::AggregationContainer>,
94    >,
95    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
96    pub size: ::core::option::Option<i64>,
97    #[serde(
98        rename = "_source",
99        skip_serializing_if = "::core::option::Option::is_none"
100    )]
101    pub source: ::core::option::Option<::oxsearch_core::search::SourceConfig>,
102    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
103    pub fields: ::core::option::Option<::std::vec::Vec<::oxsearch_core::query_dsl::FieldAndFormat>>,
104    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
105    pub query: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
106    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
107    pub sort: ::core::option::Option<::oxsearch_core::Sort>,
108    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
109    pub track_total_hits: ::core::option::Option<::oxsearch_search::search::TrackHits>,
110}
111
112impl Response {
113    /// A `Response` with its required properties set.
114    pub fn new() -> Self {
115        Self {
116            aggregations: ::core::option::Option::None,
117            size: ::core::option::Option::None,
118            source: ::core::option::Option::None,
119            fields: ::core::option::Option::None,
120            query: ::core::option::Option::None,
121            sort: ::core::option::Option::None,
122            track_total_hits: ::core::option::Option::None,
123        }
124    }
125}
126
127impl Response {
128    /// Sets `aggregations`.
129    pub fn aggregations(
130        mut self,
131        value: impl ::core::convert::Into<
132            ::indexmap::IndexMap<::std::string::String, ::oxsearch_aggs::AggregationContainer>,
133        >,
134    ) -> Self {
135        self.aggregations = ::core::option::Option::Some(value.into());
136        self
137    }
138    /// Sets `size`.
139    pub fn size(mut self, value: i64) -> Self {
140        self.size = ::core::option::Option::Some(value.into());
141        self
142    }
143    /// Sets `source`.
144    pub fn source(
145        mut self,
146        value: impl ::core::convert::Into<::oxsearch_core::search::SourceConfig>,
147    ) -> Self {
148        self.source = ::core::option::Option::Some(value.into());
149        self
150    }
151    /// Sets `fields`.
152    pub fn fields(
153        mut self,
154        value: impl ::core::convert::Into<::std::vec::Vec<::oxsearch_core::query_dsl::FieldAndFormat>>,
155    ) -> Self {
156        self.fields = ::core::option::Option::Some(value.into());
157        self
158    }
159    /// Sets `query`.
160    pub fn query(
161        mut self,
162        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
163    ) -> Self {
164        self.query = ::core::option::Option::Some(value.into());
165        self
166    }
167    /// Sets `sort`.
168    pub fn sort(mut self, value: impl ::core::convert::Into<::oxsearch_core::Sort>) -> Self {
169        self.sort = ::core::option::Option::Some(value.into());
170        self
171    }
172    /// Sets `track_total_hits`.
173    pub fn track_total_hits(
174        mut self,
175        value: impl ::core::convert::Into<::oxsearch_search::search::TrackHits>,
176    ) -> Self {
177        self.track_total_hits = ::core::option::Option::Some(value.into());
178        self
179    }
180}
181
182impl ::oxsearch_core::Endpoint for Request {
183    type Response = crate::translate::Response;
184
185    fn name(&self) -> &'static str {
186        "sql.translate"
187    }
188
189    fn route(&self) -> ::core::result::Result<::oxsearch_core::Route, ::oxsearch_core::Error> {
190        ::core::result::Result::Ok(::oxsearch_core::Route::new(
191            if self.body.is_some() {
192                ::oxsearch_core::Method::Post
193            } else {
194                ::oxsearch_core::Method::Get
195            },
196            "/_sql/translate",
197        ))
198    }
199
200    fn query(
201        &self,
202    ) -> ::core::result::Result<
203        ::std::vec::Vec<(&'static str, ::std::string::String)>,
204        ::oxsearch_core::Error,
205    > {
206        ::core::result::Result::Ok(::std::vec::Vec::new())
207    }
208
209    fn body(
210        &self,
211    ) -> ::core::result::Result<::core::option::Option<::oxsearch_core::Body>, ::oxsearch_core::Error>
212    {
213        self.body
214            .as_ref()
215            .map(|body| ::oxsearch_core::__private::json_body(body))
216            .transpose()
217    }
218}