Skip to main content

oxsearch_sql/generated/
query.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    /// If `true`, the response has partial results when there are shard request timeouts or shard failures.
9    /// If `false`, the API returns an error with no partial results.
10    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
11    pub allow_partial_search_results: ::core::option::Option<bool>,
12    /// The default catalog (cluster) for queries.
13    /// If unspecified, the queries execute on the data in the local cluster only.
14    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
15    pub catalog: ::core::option::Option<::std::string::String>,
16    /// If `true`, the results are in a columnar fashion: one row represents all the values of a certain column from the current page of results.
17    /// The API supports this parameter only for CBOR, JSON, SMILE, and YAML responses.
18    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
19    pub columnar: ::core::option::Option<bool>,
20    /// The cursor used to retrieve a set of paginated results.
21    /// If you specify a cursor, the API only uses the `columnar` and `time_zone` request body parameters.
22    /// It ignores other request body parameters.
23    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
24    pub cursor: ::core::option::Option<::std::string::String>,
25    /// The maximum number of rows (or entries) to return in one response.
26    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
27    pub fetch_size: ::core::option::Option<i32>,
28    /// If `false`, the API returns an exception when encountering multiple values for a field.
29    /// If `true`, the API is lenient and returns the first value from the array with no guarantee of consistent results.
30    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
31    pub field_multi_value_leniency: ::core::option::Option<bool>,
32    /// The Elasticsearch query DSL for additional filtering.
33    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
34    pub filter: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
35    /// If `true`, the search can run on frozen indices.
36    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
37    pub index_using_frozen: ::core::option::Option<bool>,
38    /// The retention period for an async or saved synchronous search.
39    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
40    pub keep_alive: ::core::option::Option<::oxsearch_core::Duration>,
41    /// If `true`, Elasticsearch stores synchronous searches if you also specify the `wait_for_completion_timeout` parameter.
42    /// If `false`, Elasticsearch only stores async searches that don't finish before the `wait_for_completion_timeout`.
43    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
44    pub keep_on_completion: ::core::option::Option<bool>,
45    /// The minimum retention period for the scroll cursor.
46    /// After this time period, a pagination request might fail because the scroll cursor is no longer available.
47    /// Subsequent scroll requests prolong the lifetime of the scroll cursor by the duration of `page_timeout` in the scroll request.
48    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
49    pub page_timeout: ::core::option::Option<::oxsearch_core::Duration>,
50    /// The values for parameters in the query.
51    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
52    pub params: ::core::option::Option<::std::vec::Vec<::serde_json::Value>>,
53    /// The SQL query to run.
54    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
55    pub query: ::core::option::Option<::std::string::String>,
56    /// Specifies a subset of projects to target using project
57    /// metadata tags in a subset of Lucene query syntax.
58    /// Allowed Lucene queries: the _alias tag and a single value (possibly wildcarded).
59    /// Examples:
60    /// _alias:my-project
61    /// _alias:_origin
62    /// _alias:*pr*
63    /// Supported in serverless only.
64    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
65    pub project_routing: ::core::option::Option<::oxsearch_core::ProjectRouting>,
66    /// The timeout before the request fails.
67    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
68    pub request_timeout: ::core::option::Option<::oxsearch_core::Duration>,
69    /// One or more runtime fields for the search request.
70    /// These fields take precedence over mapped fields with the same name.
71    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
72    pub runtime_mappings: ::core::option::Option<::oxsearch_mapping::RuntimeFields>,
73    /// The ISO-8601 time zone ID for the search.
74    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
75    pub time_zone: ::core::option::Option<::oxsearch_core::TimeZone>,
76    /// The period to wait for complete results.
77    /// It defaults to no timeout, meaning the request waits for complete search results.
78    /// If the search doesn't finish within this period, the search becomes async.
79    ///
80    /// To save a synchronous search, you must specify this parameter and the `keep_on_completion` parameter.
81    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
82    pub wait_for_completion_timeout: ::core::option::Option<::oxsearch_core::Duration>,
83}
84
85impl RequestBody {
86    /// A `RequestBody` with its required properties set.
87    pub fn new() -> Self {
88        Self {
89            allow_partial_search_results: ::core::option::Option::None,
90            catalog: ::core::option::Option::None,
91            columnar: ::core::option::Option::None,
92            cursor: ::core::option::Option::None,
93            fetch_size: ::core::option::Option::None,
94            field_multi_value_leniency: ::core::option::Option::None,
95            filter: ::core::option::Option::None,
96            index_using_frozen: ::core::option::Option::None,
97            keep_alive: ::core::option::Option::None,
98            keep_on_completion: ::core::option::Option::None,
99            page_timeout: ::core::option::Option::None,
100            params: ::core::option::Option::None,
101            query: ::core::option::Option::None,
102            project_routing: ::core::option::Option::None,
103            request_timeout: ::core::option::Option::None,
104            runtime_mappings: ::core::option::Option::None,
105            time_zone: ::core::option::Option::None,
106            wait_for_completion_timeout: ::core::option::Option::None,
107        }
108    }
109}
110
111impl RequestBody {
112    /// Sets `allow_partial_search_results`.
113    pub fn allow_partial_search_results(mut self, value: bool) -> Self {
114        self.allow_partial_search_results = ::core::option::Option::Some(value.into());
115        self
116    }
117    /// Sets `catalog`.
118    pub fn catalog(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
119        self.catalog = ::core::option::Option::Some(value.into());
120        self
121    }
122    /// Sets `columnar`.
123    pub fn columnar(mut self, value: bool) -> Self {
124        self.columnar = ::core::option::Option::Some(value.into());
125        self
126    }
127    /// Sets `cursor`.
128    pub fn cursor(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
129        self.cursor = ::core::option::Option::Some(value.into());
130        self
131    }
132    /// Sets `fetch_size`.
133    pub fn fetch_size(mut self, value: i32) -> Self {
134        self.fetch_size = ::core::option::Option::Some(value.into());
135        self
136    }
137    /// Sets `field_multi_value_leniency`.
138    pub fn field_multi_value_leniency(mut self, value: bool) -> Self {
139        self.field_multi_value_leniency = ::core::option::Option::Some(value.into());
140        self
141    }
142    /// Sets `filter`.
143    pub fn filter(
144        mut self,
145        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
146    ) -> Self {
147        self.filter = ::core::option::Option::Some(value.into());
148        self
149    }
150    /// Sets `index_using_frozen`.
151    pub fn index_using_frozen(mut self, value: bool) -> Self {
152        self.index_using_frozen = ::core::option::Option::Some(value.into());
153        self
154    }
155    /// Sets `keep_alive`.
156    pub fn keep_alive(
157        mut self,
158        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
159    ) -> Self {
160        self.keep_alive = ::core::option::Option::Some(value.into());
161        self
162    }
163    /// Sets `keep_on_completion`.
164    pub fn keep_on_completion(mut self, value: bool) -> Self {
165        self.keep_on_completion = ::core::option::Option::Some(value.into());
166        self
167    }
168    /// Sets `page_timeout`.
169    pub fn page_timeout(
170        mut self,
171        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
172    ) -> Self {
173        self.page_timeout = ::core::option::Option::Some(value.into());
174        self
175    }
176    /// Sets `params`.
177    pub fn params(
178        mut self,
179        value: impl ::core::convert::Into<::std::vec::Vec<::serde_json::Value>>,
180    ) -> Self {
181        self.params = ::core::option::Option::Some(value.into());
182        self
183    }
184    /// Sets `query`.
185    pub fn query(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
186        self.query = ::core::option::Option::Some(value.into());
187        self
188    }
189    /// Sets `project_routing`.
190    pub fn project_routing(
191        mut self,
192        value: impl ::core::convert::Into<::oxsearch_core::ProjectRouting>,
193    ) -> Self {
194        self.project_routing = ::core::option::Option::Some(value.into());
195        self
196    }
197    /// Sets `request_timeout`.
198    pub fn request_timeout(
199        mut self,
200        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
201    ) -> Self {
202        self.request_timeout = ::core::option::Option::Some(value.into());
203        self
204    }
205    /// Sets `runtime_mappings`.
206    pub fn runtime_mappings(
207        mut self,
208        value: impl ::core::convert::Into<::oxsearch_mapping::RuntimeFields>,
209    ) -> Self {
210        self.runtime_mappings = ::core::option::Option::Some(value.into());
211        self
212    }
213    /// Sets `time_zone`.
214    pub fn time_zone(
215        mut self,
216        value: impl ::core::convert::Into<::oxsearch_core::TimeZone>,
217    ) -> Self {
218        self.time_zone = ::core::option::Option::Some(value.into());
219        self
220    }
221    /// Sets `wait_for_completion_timeout`.
222    pub fn wait_for_completion_timeout(
223        mut self,
224        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
225    ) -> Self {
226        self.wait_for_completion_timeout = ::core::option::Option::Some(value.into());
227        self
228    }
229}
230
231/// Get SQL search results.
232///
233/// Run an SQL request.
234#[derive(Clone, Debug, PartialEq)]
235#[non_exhaustive]
236pub struct Request {
237    // Query parameters.
238    /// The format for the response.
239    /// You can also specify a format using the `Accept` HTTP header.
240    /// If you specify both this parameter and the `Accept` HTTP header, this parameter takes precedence.
241    pub format: ::core::option::Option<crate::query::SqlFormat>,
242    /// The body.
243    pub body: ::core::option::Option<crate::query::RequestBody>,
244}
245
246impl Request {
247    /// A `Request` with its required properties set.
248    pub fn new() -> Self {
249        Self {
250            format: ::core::option::Option::None,
251            body: ::core::option::Option::None,
252        }
253    }
254}
255
256impl Request {
257    /// Sets `format`.
258    pub fn format(mut self, value: impl ::core::convert::Into<crate::query::SqlFormat>) -> Self {
259        self.format = ::core::option::Option::Some(value.into());
260        self
261    }
262    /// Sets `body`.
263    pub fn body(mut self, value: impl ::core::convert::Into<crate::query::RequestBody>) -> Self {
264        self.body = ::core::option::Option::Some(value.into());
265        self
266    }
267}
268
269#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
270#[non_exhaustive]
271pub struct Response {
272    /// Column headings for the search results. Each object is a column.
273    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
274    pub columns: ::core::option::Option<::std::vec::Vec<crate::Column>>,
275    /// The cursor for the next set of paginated results.
276    /// For CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.
277    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
278    pub cursor: ::core::option::Option<::std::string::String>,
279    /// The identifier for the search.
280    /// This value is returned only for async and saved synchronous searches.
281    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP header.
282    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
283    pub id: ::core::option::Option<::oxsearch_core::Id>,
284    /// If `true`, the search is still running.
285    /// If `false`, the search has finished.
286    /// This value is returned only for async and saved synchronous searches.
287    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
288    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
289    pub is_running: ::core::option::Option<bool>,
290    /// If `true`, the response does not contain complete search results.
291    /// If `is_partial` is `true` and `is_running` is `true`, the search is still running.
292    /// If `is_partial` is `true` but `is_running` is `false`, the results are partial due to a failure or timeout.
293    /// This value is returned only for async and saved synchronous searches.
294    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
295    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
296    pub is_partial: ::core::option::Option<bool>,
297    /// The values for the search results.
298    #[serde(default = "::core::default::Default::default")]
299    pub rows: ::std::vec::Vec<crate::Row>,
300}
301
302impl Response {
303    /// A `Response` with its required properties set.
304    pub fn new(rows: impl ::core::convert::Into<::std::vec::Vec<crate::Row>>) -> Self {
305        Self {
306            columns: ::core::option::Option::None,
307            cursor: ::core::option::Option::None,
308            id: ::core::option::Option::None,
309            is_running: ::core::option::Option::None,
310            is_partial: ::core::option::Option::None,
311            rows: rows.into(),
312        }
313    }
314}
315
316impl Response {
317    /// Sets `columns`.
318    pub fn columns(
319        mut self,
320        value: impl ::core::convert::Into<::std::vec::Vec<crate::Column>>,
321    ) -> Self {
322        self.columns = ::core::option::Option::Some(value.into());
323        self
324    }
325    /// Sets `cursor`.
326    pub fn cursor(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
327        self.cursor = ::core::option::Option::Some(value.into());
328        self
329    }
330    /// Sets `id`.
331    pub fn id(mut self, value: impl ::core::convert::Into<::oxsearch_core::Id>) -> Self {
332        self.id = ::core::option::Option::Some(value.into());
333        self
334    }
335    /// Sets `is_running`.
336    pub fn is_running(mut self, value: bool) -> Self {
337        self.is_running = ::core::option::Option::Some(value.into());
338        self
339    }
340    /// Sets `is_partial`.
341    pub fn is_partial(mut self, value: bool) -> Self {
342        self.is_partial = ::core::option::Option::Some(value.into());
343        self
344    }
345}
346
347#[derive(Clone, Debug, PartialEq, Eq, Hash)]
348#[non_exhaustive]
349pub enum SqlFormat {
350    /// `csv`
351    Csv,
352    /// `json`
353    Json,
354    /// `tsv`
355    Tsv,
356    /// `txt`
357    Txt,
358    /// `yaml`
359    Yaml,
360    /// `cbor`
361    Cbor,
362    /// `smile`
363    Smile,
364    /// A value this version of the specification doesn't list.
365    Raw(::std::string::String),
366}
367
368impl SqlFormat {
369    /// The value as Elasticsearch writes it.
370    pub fn as_str(&self) -> &str {
371        match self {
372            Self::Csv => "csv",
373            Self::Json => "json",
374            Self::Tsv => "tsv",
375            Self::Txt => "txt",
376            Self::Yaml => "yaml",
377            Self::Cbor => "cbor",
378            Self::Smile => "smile",
379            Self::Raw(value) => value,
380        }
381    }
382
383    /// The listed value with this name, if there is one.
384    pub fn from_known(value: &str) -> ::core::option::Option<Self> {
385        match value {
386            "csv" => ::core::option::Option::Some(Self::Csv),
387            "json" => ::core::option::Option::Some(Self::Json),
388            "tsv" => ::core::option::Option::Some(Self::Tsv),
389            "txt" => ::core::option::Option::Some(Self::Txt),
390            "yaml" => ::core::option::Option::Some(Self::Yaml),
391            "cbor" => ::core::option::Option::Some(Self::Cbor),
392            "smile" => ::core::option::Option::Some(Self::Smile),
393            _ => ::core::option::Option::None,
394        }
395    }
396}
397
398impl ::serde::Serialize for SqlFormat {
399    fn serialize<S__: ::serde::Serializer>(
400        &self,
401        serializer: S__,
402    ) -> ::core::result::Result<S__::Ok, S__::Error> {
403        serializer.serialize_str(self.as_str())
404    }
405}
406
407impl<'de> ::serde::Deserialize<'de> for SqlFormat {
408    fn deserialize<D__: ::serde::Deserializer<'de>>(
409        deserializer: D__,
410    ) -> ::core::result::Result<Self, D__::Error> {
411        ::oxsearch_core::__private::deserialize_string_enum(deserializer, "SqlFormat", |value| {
412            Self::from_known(value).unwrap_or_else(|| Self::Raw(value.to_owned()))
413        })
414    }
415}
416
417impl ::oxsearch_core::Endpoint for Request {
418    type Response = crate::query::Response;
419
420    fn name(&self) -> &'static str {
421        "sql.query"
422    }
423
424    fn route(&self) -> ::core::result::Result<::oxsearch_core::Route, ::oxsearch_core::Error> {
425        ::core::result::Result::Ok(::oxsearch_core::Route::new(
426            if self.body.is_some() {
427                ::oxsearch_core::Method::Post
428            } else {
429                ::oxsearch_core::Method::Get
430            },
431            "/_sql",
432        ))
433    }
434
435    fn query(
436        &self,
437    ) -> ::core::result::Result<
438        ::std::vec::Vec<(&'static str, ::std::string::String)>,
439        ::oxsearch_core::Error,
440    > {
441        let mut query = ::std::vec::Vec::new();
442        if let ::core::option::Option::Some(value) = &self.format {
443            query.push((
444                "format",
445                ::oxsearch_core::__private::query_param("format", value)?,
446            ));
447        }
448        ::core::result::Result::Ok(query)
449    }
450
451    fn body(
452        &self,
453    ) -> ::core::result::Result<::core::option::Option<::oxsearch_core::Body>, ::oxsearch_core::Error>
454    {
455        self.body
456            .as_ref()
457            .map(|body| ::oxsearch_core::__private::json_body(body))
458            .transpose()
459    }
460}