oxsearch-sql 0.2.0

SQL for oxsearch, generated from the Elasticsearch specification: queries, cursors and their translation into search requests
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
// Generated by `cargo run -p xtask -- generate` from elastic/elasticsearch-specification 9.5 at
// 84bf510a907bae62ffe29af35f516af287a79eab. Don't edit it: change the generator.

/// The request's body.
#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct RequestBody {
    /// If `true`, the response has partial results when there are shard request timeouts or shard failures.
    /// If `false`, the API returns an error with no partial results.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub allow_partial_search_results: ::core::option::Option<bool>,
    /// The default catalog (cluster) for queries.
    /// If unspecified, the queries execute on the data in the local cluster only.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub catalog: ::core::option::Option<::std::string::String>,
    /// 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.
    /// The API supports this parameter only for CBOR, JSON, SMILE, and YAML responses.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub columnar: ::core::option::Option<bool>,
    /// The cursor used to retrieve a set of paginated results.
    /// If you specify a cursor, the API only uses the `columnar` and `time_zone` request body parameters.
    /// It ignores other request body parameters.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub cursor: ::core::option::Option<::std::string::String>,
    /// The maximum number of rows (or entries) to return in one response.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub fetch_size: ::core::option::Option<i32>,
    /// If `false`, the API returns an exception when encountering multiple values for a field.
    /// If `true`, the API is lenient and returns the first value from the array with no guarantee of consistent results.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub field_multi_value_leniency: ::core::option::Option<bool>,
    /// The Elasticsearch query DSL for additional filtering.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub filter: ::core::option::Option<::oxsearch_core::query_dsl::QueryContainer>,
    /// If `true`, the search can run on frozen indices.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub index_using_frozen: ::core::option::Option<bool>,
    /// The retention period for an async or saved synchronous search.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub keep_alive: ::core::option::Option<::oxsearch_core::Duration>,
    /// If `true`, Elasticsearch stores synchronous searches if you also specify the `wait_for_completion_timeout` parameter.
    /// If `false`, Elasticsearch only stores async searches that don't finish before the `wait_for_completion_timeout`.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub keep_on_completion: ::core::option::Option<bool>,
    /// The minimum retention period for the scroll cursor.
    /// After this time period, a pagination request might fail because the scroll cursor is no longer available.
    /// Subsequent scroll requests prolong the lifetime of the scroll cursor by the duration of `page_timeout` in the scroll request.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub page_timeout: ::core::option::Option<::oxsearch_core::Duration>,
    /// The values for parameters in the query.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub params: ::core::option::Option<::std::vec::Vec<::serde_json::Value>>,
    /// The SQL query to run.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub query: ::core::option::Option<::std::string::String>,
    /// Specifies a subset of projects to target using project
    /// metadata tags in a subset of Lucene query syntax.
    /// Allowed Lucene queries: the _alias tag and a single value (possibly wildcarded).
    /// Examples:
    /// _alias:my-project
    /// _alias:_origin
    /// _alias:*pr*
    /// Supported in serverless only.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub project_routing: ::core::option::Option<::oxsearch_core::ProjectRouting>,
    /// The timeout before the request fails.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub request_timeout: ::core::option::Option<::oxsearch_core::Duration>,
    /// One or more runtime fields for the search request.
    /// These fields take precedence over mapped fields with the same name.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub runtime_mappings: ::core::option::Option<::oxsearch_mapping::RuntimeFields>,
    /// The ISO-8601 time zone ID for the search.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub time_zone: ::core::option::Option<::oxsearch_core::TimeZone>,
    /// The period to wait for complete results.
    /// It defaults to no timeout, meaning the request waits for complete search results.
    /// If the search doesn't finish within this period, the search becomes async.
    ///
    /// To save a synchronous search, you must specify this parameter and the `keep_on_completion` parameter.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub wait_for_completion_timeout: ::core::option::Option<::oxsearch_core::Duration>,
}

impl RequestBody {
    /// A `RequestBody` with its required properties set.
    pub fn new() -> Self {
        Self {
            allow_partial_search_results: ::core::option::Option::None,
            catalog: ::core::option::Option::None,
            columnar: ::core::option::Option::None,
            cursor: ::core::option::Option::None,
            fetch_size: ::core::option::Option::None,
            field_multi_value_leniency: ::core::option::Option::None,
            filter: ::core::option::Option::None,
            index_using_frozen: ::core::option::Option::None,
            keep_alive: ::core::option::Option::None,
            keep_on_completion: ::core::option::Option::None,
            page_timeout: ::core::option::Option::None,
            params: ::core::option::Option::None,
            query: ::core::option::Option::None,
            project_routing: ::core::option::Option::None,
            request_timeout: ::core::option::Option::None,
            runtime_mappings: ::core::option::Option::None,
            time_zone: ::core::option::Option::None,
            wait_for_completion_timeout: ::core::option::Option::None,
        }
    }
}

impl RequestBody {
    /// Sets `allow_partial_search_results`.
    pub fn allow_partial_search_results(mut self, value: bool) -> Self {
        self.allow_partial_search_results = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `catalog`.
    pub fn catalog(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.catalog = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `columnar`.
    pub fn columnar(mut self, value: bool) -> Self {
        self.columnar = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `cursor`.
    pub fn cursor(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.cursor = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `fetch_size`.
    pub fn fetch_size(mut self, value: i32) -> Self {
        self.fetch_size = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `field_multi_value_leniency`.
    pub fn field_multi_value_leniency(mut self, value: bool) -> Self {
        self.field_multi_value_leniency = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `filter`.
    pub fn filter(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::query_dsl::QueryContainer>,
    ) -> Self {
        self.filter = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `index_using_frozen`.
    pub fn index_using_frozen(mut self, value: bool) -> Self {
        self.index_using_frozen = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `keep_alive`.
    pub fn keep_alive(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.keep_alive = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `keep_on_completion`.
    pub fn keep_on_completion(mut self, value: bool) -> Self {
        self.keep_on_completion = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `page_timeout`.
    pub fn page_timeout(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.page_timeout = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `params`.
    pub fn params(
        mut self,
        value: impl ::core::convert::Into<::std::vec::Vec<::serde_json::Value>>,
    ) -> Self {
        self.params = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `query`.
    pub fn query(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.query = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `project_routing`.
    pub fn project_routing(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::ProjectRouting>,
    ) -> Self {
        self.project_routing = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `request_timeout`.
    pub fn request_timeout(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.request_timeout = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `runtime_mappings`.
    pub fn runtime_mappings(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_mapping::RuntimeFields>,
    ) -> Self {
        self.runtime_mappings = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `time_zone`.
    pub fn time_zone(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::TimeZone>,
    ) -> Self {
        self.time_zone = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `wait_for_completion_timeout`.
    pub fn wait_for_completion_timeout(
        mut self,
        value: impl ::core::convert::Into<::oxsearch_core::Duration>,
    ) -> Self {
        self.wait_for_completion_timeout = ::core::option::Option::Some(value.into());
        self
    }
}

/// Get SQL search results.
///
/// Run an SQL request.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct Request {
    // Query parameters.
    /// The format for the response.
    /// You can also specify a format using the `Accept` HTTP header.
    /// If you specify both this parameter and the `Accept` HTTP header, this parameter takes precedence.
    pub format: ::core::option::Option<crate::query::SqlFormat>,
    /// The body.
    pub body: ::core::option::Option<crate::query::RequestBody>,
}

impl Request {
    /// A `Request` with its required properties set.
    pub fn new() -> Self {
        Self {
            format: ::core::option::Option::None,
            body: ::core::option::Option::None,
        }
    }
}

impl Request {
    /// Sets `format`.
    pub fn format(mut self, value: impl ::core::convert::Into<crate::query::SqlFormat>) -> Self {
        self.format = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `body`.
    pub fn body(mut self, value: impl ::core::convert::Into<crate::query::RequestBody>) -> Self {
        self.body = ::core::option::Option::Some(value.into());
        self
    }
}

#[derive(Clone, Debug, PartialEq, ::serde::Serialize, ::serde::Deserialize)]
#[non_exhaustive]
pub struct Response {
    /// Column headings for the search results. Each object is a column.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub columns: ::core::option::Option<::std::vec::Vec<crate::Column>>,
    /// The cursor for the next set of paginated results.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Cursor` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub cursor: ::core::option::Option<::std::string::String>,
    /// The identifier for the search.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-ID` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub id: ::core::option::Option<::oxsearch_core::Id>,
    /// If `true`, the search is still running.
    /// If `false`, the search has finished.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub is_running: ::core::option::Option<bool>,
    /// If `true`, the response does not contain complete search results.
    /// If `is_partial` is `true` and `is_running` is `true`, the search is still running.
    /// If `is_partial` is `true` but `is_running` is `false`, the results are partial due to a failure or timeout.
    /// This value is returned only for async and saved synchronous searches.
    /// For CSV, TSV, and TXT responses, this value is returned in the `Async-partial` HTTP header.
    #[serde(skip_serializing_if = "::core::option::Option::is_none")]
    pub is_partial: ::core::option::Option<bool>,
    /// The values for the search results.
    #[serde(default = "::core::default::Default::default")]
    pub rows: ::std::vec::Vec<crate::Row>,
}

impl Response {
    /// A `Response` with its required properties set.
    pub fn new(rows: impl ::core::convert::Into<::std::vec::Vec<crate::Row>>) -> Self {
        Self {
            columns: ::core::option::Option::None,
            cursor: ::core::option::Option::None,
            id: ::core::option::Option::None,
            is_running: ::core::option::Option::None,
            is_partial: ::core::option::Option::None,
            rows: rows.into(),
        }
    }
}

impl Response {
    /// Sets `columns`.
    pub fn columns(
        mut self,
        value: impl ::core::convert::Into<::std::vec::Vec<crate::Column>>,
    ) -> Self {
        self.columns = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `cursor`.
    pub fn cursor(mut self, value: impl ::core::convert::Into<::std::string::String>) -> Self {
        self.cursor = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `id`.
    pub fn id(mut self, value: impl ::core::convert::Into<::oxsearch_core::Id>) -> Self {
        self.id = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `is_running`.
    pub fn is_running(mut self, value: bool) -> Self {
        self.is_running = ::core::option::Option::Some(value.into());
        self
    }
    /// Sets `is_partial`.
    pub fn is_partial(mut self, value: bool) -> Self {
        self.is_partial = ::core::option::Option::Some(value.into());
        self
    }
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum SqlFormat {
    /// `csv`
    Csv,
    /// `json`
    Json,
    /// `tsv`
    Tsv,
    /// `txt`
    Txt,
    /// `yaml`
    Yaml,
    /// `cbor`
    Cbor,
    /// `smile`
    Smile,
    /// A value this version of the specification doesn't list.
    Raw(::std::string::String),
}

impl SqlFormat {
    /// The value as Elasticsearch writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Csv => "csv",
            Self::Json => "json",
            Self::Tsv => "tsv",
            Self::Txt => "txt",
            Self::Yaml => "yaml",
            Self::Cbor => "cbor",
            Self::Smile => "smile",
            Self::Raw(value) => value,
        }
    }

    /// The listed value with this name, if there is one.
    pub fn from_known(value: &str) -> ::core::option::Option<Self> {
        match value {
            "csv" => ::core::option::Option::Some(Self::Csv),
            "json" => ::core::option::Option::Some(Self::Json),
            "tsv" => ::core::option::Option::Some(Self::Tsv),
            "txt" => ::core::option::Option::Some(Self::Txt),
            "yaml" => ::core::option::Option::Some(Self::Yaml),
            "cbor" => ::core::option::Option::Some(Self::Cbor),
            "smile" => ::core::option::Option::Some(Self::Smile),
            _ => ::core::option::Option::None,
        }
    }
}

impl ::serde::Serialize for SqlFormat {
    fn serialize<S__: ::serde::Serializer>(
        &self,
        serializer: S__,
    ) -> ::core::result::Result<S__::Ok, S__::Error> {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de> ::serde::Deserialize<'de> for SqlFormat {
    fn deserialize<D__: ::serde::Deserializer<'de>>(
        deserializer: D__,
    ) -> ::core::result::Result<Self, D__::Error> {
        ::oxsearch_core::__private::deserialize_string_enum(deserializer, "SqlFormat", |value| {
            Self::from_known(value).unwrap_or_else(|| Self::Raw(value.to_owned()))
        })
    }
}

impl ::oxsearch_core::Endpoint for Request {
    type Response = crate::query::Response;

    fn name(&self) -> &'static str {
        "sql.query"
    }

    fn route(&self) -> ::core::result::Result<::oxsearch_core::Route, ::oxsearch_core::Error> {
        ::core::result::Result::Ok(::oxsearch_core::Route::new(
            if self.body.is_some() {
                ::oxsearch_core::Method::Post
            } else {
                ::oxsearch_core::Method::Get
            },
            "/_sql",
        ))
    }

    fn query(
        &self,
    ) -> ::core::result::Result<
        ::std::vec::Vec<(&'static str, ::std::string::String)>,
        ::oxsearch_core::Error,
    > {
        let mut query = ::std::vec::Vec::new();
        if let ::core::option::Option::Some(value) = &self.format {
            query.push((
                "format",
                ::oxsearch_core::__private::query_param("format", value)?,
            ));
        }
        ::core::result::Result::Ok(query)
    }

    fn body(
        &self,
    ) -> ::core::result::Result<::core::option::Option<::oxsearch_core::Body>, ::oxsearch_core::Error>
    {
        self.body
            .as_ref()
            .map(|body| ::oxsearch_core::__private::json_body(body))
            .transpose()
    }
}