elasticsearch/
features.rs

1/*
2 * Licensed to Elasticsearch B.V. under one or more contributor
3 * license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright
5 * ownership. Elasticsearch B.V. licenses this file to you under
6 * the Apache License, Version 2.0 (the "License"); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *	http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20// -----------------------------------------------
21// This file is generated, Please do not edit it manually.
22// Run the following in the root of the repo to regenerate:
23//
24// cargo make generate-api
25// -----------------------------------------------
26
27//! Features APIs
28//!
29//! Allows [introspecting and managing features](https://www.elastic.co/guide/en/elasticsearch/reference/current/features-apis.html) provided by Elasticsearch and Elasticsearch plugins.
30
31#![allow(unused_imports)]
32use crate::{
33    client::Elasticsearch,
34    error::Error,
35    http::{
36        self,
37        headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
38        request::{Body, JsonBody, NdBody, PARTS_ENCODED},
39        response::Response,
40        transport::Transport,
41    },
42    params::*,
43};
44use percent_encoding::percent_encode;
45use serde::Serialize;
46use std::{borrow::Cow, time::Duration};
47#[derive(Debug, Clone, PartialEq, Eq)]
48#[doc = "API parts for the Features Get Features API"]
49pub enum FeaturesGetFeaturesParts {
50    #[doc = "No parts"]
51    None,
52}
53impl FeaturesGetFeaturesParts {
54    #[doc = "Builds a relative URL path to the Features Get Features API"]
55    pub fn url(self) -> Cow<'static, str> {
56        match self {
57            FeaturesGetFeaturesParts::None => "/_features".into(),
58        }
59    }
60}
61#[doc = "Builder for the [Features Get Features API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/get-features-api.html)\n\nGets a list of features which can be included in snapshots using the feature_states field when creating a snapshot"]
62#[derive(Clone, Debug)]
63pub struct FeaturesGetFeatures<'a, 'b> {
64    transport: &'a Transport,
65    parts: FeaturesGetFeaturesParts,
66    error_trace: Option<bool>,
67    filter_path: Option<&'b [&'b str]>,
68    headers: HeaderMap,
69    human: Option<bool>,
70    master_timeout: Option<&'b str>,
71    pretty: Option<bool>,
72    request_timeout: Option<Duration>,
73    source: Option<&'b str>,
74}
75impl<'a, 'b> FeaturesGetFeatures<'a, 'b> {
76    #[doc = "Creates a new instance of [FeaturesGetFeatures]"]
77    pub fn new(transport: &'a Transport) -> Self {
78        let headers = HeaderMap::new();
79        FeaturesGetFeatures {
80            transport,
81            parts: FeaturesGetFeaturesParts::None,
82            headers,
83            error_trace: None,
84            filter_path: None,
85            human: None,
86            master_timeout: None,
87            pretty: None,
88            request_timeout: None,
89            source: None,
90        }
91    }
92    #[doc = "Include the stack trace of returned errors."]
93    pub fn error_trace(mut self, error_trace: bool) -> Self {
94        self.error_trace = Some(error_trace);
95        self
96    }
97    #[doc = "A comma-separated list of filters used to reduce the response."]
98    pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
99        self.filter_path = Some(filter_path);
100        self
101    }
102    #[doc = "Adds a HTTP header"]
103    pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
104        self.headers.insert(key, value);
105        self
106    }
107    #[doc = "Return human readable values for statistics."]
108    pub fn human(mut self, human: bool) -> Self {
109        self.human = Some(human);
110        self
111    }
112    #[doc = "Explicit operation timeout for connection to master node"]
113    pub fn master_timeout(mut self, master_timeout: &'b str) -> Self {
114        self.master_timeout = Some(master_timeout);
115        self
116    }
117    #[doc = "Pretty format the returned JSON response."]
118    pub fn pretty(mut self, pretty: bool) -> Self {
119        self.pretty = Some(pretty);
120        self
121    }
122    #[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
123    pub fn request_timeout(mut self, timeout: Duration) -> Self {
124        self.request_timeout = Some(timeout);
125        self
126    }
127    #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
128    pub fn source(mut self, source: &'b str) -> Self {
129        self.source = Some(source);
130        self
131    }
132    #[doc = "Creates an asynchronous call to the Features Get Features API that can be awaited"]
133    pub async fn send(self) -> Result<Response, Error> {
134        let path = self.parts.url();
135        let method = http::Method::Get;
136        let headers = self.headers;
137        let timeout = self.request_timeout;
138        let query_string = {
139            #[serde_with::skip_serializing_none]
140            #[derive(Serialize)]
141            struct QueryParams<'b> {
142                error_trace: Option<bool>,
143                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
144                filter_path: Option<&'b [&'b str]>,
145                human: Option<bool>,
146                master_timeout: Option<&'b str>,
147                pretty: Option<bool>,
148                source: Option<&'b str>,
149            }
150            let query_params = QueryParams {
151                error_trace: self.error_trace,
152                filter_path: self.filter_path,
153                human: self.human,
154                master_timeout: self.master_timeout,
155                pretty: self.pretty,
156                source: self.source,
157            };
158            Some(query_params)
159        };
160        let body = Option::<()>::None;
161        let response = self
162            .transport
163            .send(method, &path, headers, query_string.as_ref(), body, timeout)
164            .await?;
165        Ok(response)
166    }
167}
168#[cfg(feature = "experimental-apis")]
169#[derive(Debug, Clone, PartialEq, Eq)]
170#[doc = "API parts for the Features Reset Features API"]
171pub enum FeaturesResetFeaturesParts {
172    #[doc = "No parts"]
173    None,
174}
175#[cfg(feature = "experimental-apis")]
176impl FeaturesResetFeaturesParts {
177    #[doc = "Builds a relative URL path to the Features Reset Features API"]
178    pub fn url(self) -> Cow<'static, str> {
179        match self {
180            FeaturesResetFeaturesParts::None => "/_features/_reset".into(),
181        }
182    }
183}
184#[doc = "Builder for the [Features Reset Features API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/modules-snapshots.html)\n\nResets the internal state of features, usually by deleting system indices"]
185#[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
186#[cfg(feature = "experimental-apis")]
187#[derive(Clone, Debug)]
188pub struct FeaturesResetFeatures<'a, 'b, B> {
189    transport: &'a Transport,
190    parts: FeaturesResetFeaturesParts,
191    body: Option<B>,
192    error_trace: Option<bool>,
193    filter_path: Option<&'b [&'b str]>,
194    headers: HeaderMap,
195    human: Option<bool>,
196    master_timeout: Option<&'b str>,
197    pretty: Option<bool>,
198    request_timeout: Option<Duration>,
199    source: Option<&'b str>,
200}
201#[cfg(feature = "experimental-apis")]
202impl<'a, 'b, B> FeaturesResetFeatures<'a, 'b, B>
203where
204    B: Body,
205{
206    #[doc = "Creates a new instance of [FeaturesResetFeatures]"]
207    pub fn new(transport: &'a Transport) -> Self {
208        let headers = HeaderMap::new();
209        FeaturesResetFeatures {
210            transport,
211            parts: FeaturesResetFeaturesParts::None,
212            headers,
213            body: None,
214            error_trace: None,
215            filter_path: None,
216            human: None,
217            master_timeout: None,
218            pretty: None,
219            request_timeout: None,
220            source: None,
221        }
222    }
223    #[doc = "The body for the API call"]
224    pub fn body<T>(self, body: T) -> FeaturesResetFeatures<'a, 'b, JsonBody<T>>
225    where
226        T: Serialize,
227    {
228        FeaturesResetFeatures {
229            transport: self.transport,
230            parts: self.parts,
231            body: Some(body.into()),
232            error_trace: self.error_trace,
233            filter_path: self.filter_path,
234            headers: self.headers,
235            human: self.human,
236            master_timeout: self.master_timeout,
237            pretty: self.pretty,
238            request_timeout: self.request_timeout,
239            source: self.source,
240        }
241    }
242    #[doc = "Include the stack trace of returned errors."]
243    pub fn error_trace(mut self, error_trace: bool) -> Self {
244        self.error_trace = Some(error_trace);
245        self
246    }
247    #[doc = "A comma-separated list of filters used to reduce the response."]
248    pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
249        self.filter_path = Some(filter_path);
250        self
251    }
252    #[doc = "Adds a HTTP header"]
253    pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
254        self.headers.insert(key, value);
255        self
256    }
257    #[doc = "Return human readable values for statistics."]
258    pub fn human(mut self, human: bool) -> Self {
259        self.human = Some(human);
260        self
261    }
262    #[doc = "Explicit operation timeout for connection to master node"]
263    pub fn master_timeout(mut self, master_timeout: &'b str) -> Self {
264        self.master_timeout = Some(master_timeout);
265        self
266    }
267    #[doc = "Pretty format the returned JSON response."]
268    pub fn pretty(mut self, pretty: bool) -> Self {
269        self.pretty = Some(pretty);
270        self
271    }
272    #[doc = "Sets a request timeout for this API call.\n\nThe timeout is applied from when the request starts connecting until the response body has finished."]
273    pub fn request_timeout(mut self, timeout: Duration) -> Self {
274        self.request_timeout = Some(timeout);
275        self
276    }
277    #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
278    pub fn source(mut self, source: &'b str) -> Self {
279        self.source = Some(source);
280        self
281    }
282    #[doc = "Creates an asynchronous call to the Features Reset Features API that can be awaited"]
283    pub async fn send(self) -> Result<Response, Error> {
284        let path = self.parts.url();
285        let method = http::Method::Post;
286        let headers = self.headers;
287        let timeout = self.request_timeout;
288        let query_string = {
289            #[serde_with::skip_serializing_none]
290            #[derive(Serialize)]
291            struct QueryParams<'b> {
292                error_trace: Option<bool>,
293                #[serde(serialize_with = "crate::client::serialize_coll_qs")]
294                filter_path: Option<&'b [&'b str]>,
295                human: Option<bool>,
296                master_timeout: Option<&'b str>,
297                pretty: Option<bool>,
298                source: Option<&'b str>,
299            }
300            let query_params = QueryParams {
301                error_trace: self.error_trace,
302                filter_path: self.filter_path,
303                human: self.human,
304                master_timeout: self.master_timeout,
305                pretty: self.pretty,
306                source: self.source,
307            };
308            Some(query_params)
309        };
310        let body = self.body;
311        let response = self
312            .transport
313            .send(method, &path, headers, query_string.as_ref(), body, timeout)
314            .await?;
315        Ok(response)
316    }
317}
318#[doc = "Namespace client for Features APIs"]
319pub struct Features<'a> {
320    transport: &'a Transport,
321}
322impl<'a> Features<'a> {
323    #[doc = "Creates a new instance of [Features]"]
324    pub fn new(transport: &'a Transport) -> Self {
325        Self { transport }
326    }
327    pub fn transport(&self) -> &Transport {
328        self.transport
329    }
330    #[doc = "[Features Get Features API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/get-features-api.html)\n\nGets a list of features which can be included in snapshots using the feature_states field when creating a snapshot"]
331    pub fn get_features<'b>(&'a self) -> FeaturesGetFeatures<'a, 'b> {
332        FeaturesGetFeatures::new(self.transport())
333    }
334    #[doc = "[Features Reset Features API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/modules-snapshots.html)\n\nResets the internal state of features, usually by deleting system indices"]
335    #[doc = "&nbsp;\n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n        "]
336    #[cfg(feature = "experimental-apis")]
337    pub fn reset_features<'b>(&'a self) -> FeaturesResetFeatures<'a, 'b, ()> {
338        FeaturesResetFeatures::new(self.transport())
339    }
340}
341impl Elasticsearch {
342    #[doc = "Creates a namespace client for Features APIs"]
343    pub fn features(&self) -> Features {
344        Features::new(self.transport())
345    }
346}