1#![cfg(feature = "experimental-apis")]
32#![doc = " \n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n "]
33#![allow(unused_imports)]
34use crate::{
35 client::OpenSearch,
36 error::Error,
37 http::{
38 headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
39 request::{Body, JsonBody, NdBody, PARTS_ENCODED},
40 response::Response,
41 transport::Transport,
42 Method,
43 },
44 params::*,
45};
46use percent_encoding::percent_encode;
47use serde::Serialize;
48use std::{borrow::Cow, time::Duration};
49#[cfg(feature = "experimental-apis")]
50#[derive(Debug, Clone, PartialEq)]
51#[doc = "API parts for the Text Structure Find Structure API"]
52pub enum TextStructureFindStructureParts {
53 #[doc = "No parts"]
54 None,
55}
56#[cfg(feature = "experimental-apis")]
57impl TextStructureFindStructureParts {
58 #[doc = "Builds a relative URL path to the Text Structure Find Structure API"]
59 pub fn url(self) -> Cow<'static, str> {
60 match self {
61 TextStructureFindStructureParts::None => "/_text_structure/find_structure".into(),
62 }
63 }
64}
65#[doc = "Builder for the [Text Structure Find Structure API](https://opensearch.org/docs/)\n\nFinds the structure of a text file. The text file must contain data that is suitable to be ingested into Elasticsearch."]
66#[doc = " \n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n "]
67#[cfg(feature = "experimental-apis")]
68#[derive(Clone, Debug)]
69pub struct TextStructureFindStructure<'a, 'b, B> {
70 transport: &'a Transport,
71 parts: TextStructureFindStructureParts,
72 body: Option<B>,
73 charset: Option<&'b str>,
74 column_names: Option<&'b [&'b str]>,
75 delimiter: Option<&'b str>,
76 error_trace: Option<bool>,
77 explain: Option<bool>,
78 filter_path: Option<&'b [&'b str]>,
79 format: Option<Format>,
80 grok_pattern: Option<&'b str>,
81 has_header_row: Option<bool>,
82 headers: HeaderMap,
83 human: Option<bool>,
84 line_merge_size_limit: Option<i32>,
85 lines_to_sample: Option<i32>,
86 pretty: Option<bool>,
87 quote: Option<&'b str>,
88 request_timeout: Option<Duration>,
89 should_trim_fields: Option<bool>,
90 source: Option<&'b str>,
91 timeout: Option<&'b str>,
92 timestamp_field: Option<&'b str>,
93 timestamp_format: Option<&'b str>,
94}
95#[cfg(feature = "experimental-apis")]
96impl<'a, 'b, B> TextStructureFindStructure<'a, 'b, B>
97where
98 B: Body,
99{
100 #[doc = "Creates a new instance of [TextStructureFindStructure]"]
101 pub fn new(transport: &'a Transport) -> Self {
102 let headers = HeaderMap::new();
103 TextStructureFindStructure {
104 transport,
105 parts: TextStructureFindStructureParts::None,
106 headers,
107 body: None,
108 charset: None,
109 column_names: None,
110 delimiter: None,
111 error_trace: None,
112 explain: None,
113 filter_path: None,
114 format: None,
115 grok_pattern: None,
116 has_header_row: None,
117 human: None,
118 line_merge_size_limit: None,
119 lines_to_sample: None,
120 pretty: None,
121 quote: None,
122 request_timeout: None,
123 should_trim_fields: None,
124 source: None,
125 timeout: None,
126 timestamp_field: None,
127 timestamp_format: None,
128 }
129 }
130 #[doc = "The body for the API call"]
131 pub fn body<T>(self, body: Vec<T>) -> TextStructureFindStructure<'a, 'b, NdBody<T>>
132 where
133 T: Body,
134 {
135 TextStructureFindStructure {
136 transport: self.transport,
137 parts: self.parts,
138 body: Some(NdBody(body)),
139 charset: self.charset,
140 column_names: self.column_names,
141 delimiter: self.delimiter,
142 error_trace: self.error_trace,
143 explain: self.explain,
144 filter_path: self.filter_path,
145 format: self.format,
146 grok_pattern: self.grok_pattern,
147 has_header_row: self.has_header_row,
148 headers: self.headers,
149 human: self.human,
150 line_merge_size_limit: self.line_merge_size_limit,
151 lines_to_sample: self.lines_to_sample,
152 pretty: self.pretty,
153 quote: self.quote,
154 request_timeout: self.request_timeout,
155 should_trim_fields: self.should_trim_fields,
156 source: self.source,
157 timeout: self.timeout,
158 timestamp_field: self.timestamp_field,
159 timestamp_format: self.timestamp_format,
160 }
161 }
162 #[doc = "Optional parameter to specify the character set of the file"]
163 pub fn charset(mut self, charset: &'b str) -> Self {
164 self.charset = Some(charset);
165 self
166 }
167 #[doc = "Optional parameter containing a comma separated list of the column names for a delimited file"]
168 pub fn column_names(mut self, column_names: &'b [&'b str]) -> Self {
169 self.column_names = Some(column_names);
170 self
171 }
172 #[doc = "Optional parameter to specify the delimiter character for a delimited file - must be a single character"]
173 pub fn delimiter(mut self, delimiter: &'b str) -> Self {
174 self.delimiter = Some(delimiter);
175 self
176 }
177 #[doc = "Include the stack trace of returned errors."]
178 pub fn error_trace(mut self, error_trace: bool) -> Self {
179 self.error_trace = Some(error_trace);
180 self
181 }
182 #[doc = "Whether to include a commentary on how the structure was derived"]
183 pub fn explain(mut self, explain: bool) -> Self {
184 self.explain = Some(explain);
185 self
186 }
187 #[doc = "A comma-separated list of filters used to reduce the response."]
188 pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
189 self.filter_path = Some(filter_path);
190 self
191 }
192 #[doc = "Optional parameter to specify the high level file format"]
193 pub fn format(mut self, format: Format) -> Self {
194 self.format = Some(format);
195 self
196 }
197 #[doc = "Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file"]
198 pub fn grok_pattern(mut self, grok_pattern: &'b str) -> Self {
199 self.grok_pattern = Some(grok_pattern);
200 self
201 }
202 #[doc = "Optional parameter to specify whether a delimited file includes the column names in its first row"]
203 pub fn has_header_row(mut self, has_header_row: bool) -> Self {
204 self.has_header_row = Some(has_header_row);
205 self
206 }
207 #[doc = "Adds a HTTP header"]
208 pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
209 self.headers.insert(key, value);
210 self
211 }
212 #[doc = "Return human readable values for statistics."]
213 pub fn human(mut self, human: bool) -> Self {
214 self.human = Some(human);
215 self
216 }
217 #[doc = "Maximum number of characters permitted in a single message when lines are merged to create messages."]
218 pub fn line_merge_size_limit(mut self, line_merge_size_limit: i32) -> Self {
219 self.line_merge_size_limit = Some(line_merge_size_limit);
220 self
221 }
222 #[doc = "How many lines of the file should be included in the analysis"]
223 pub fn lines_to_sample(mut self, lines_to_sample: i32) -> Self {
224 self.lines_to_sample = Some(lines_to_sample);
225 self
226 }
227 #[doc = "Pretty format the returned JSON response."]
228 pub fn pretty(mut self, pretty: bool) -> Self {
229 self.pretty = Some(pretty);
230 self
231 }
232 #[doc = "Optional parameter to specify the quote character for a delimited file - must be a single character"]
233 pub fn quote(mut self, quote: &'b str) -> Self {
234 self.quote = Some(quote);
235 self
236 }
237 #[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."]
238 pub fn request_timeout(mut self, timeout: Duration) -> Self {
239 self.request_timeout = Some(timeout);
240 self
241 }
242 #[doc = "Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them"]
243 pub fn should_trim_fields(mut self, should_trim_fields: bool) -> Self {
244 self.should_trim_fields = Some(should_trim_fields);
245 self
246 }
247 #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
248 pub fn source(mut self, source: &'b str) -> Self {
249 self.source = Some(source);
250 self
251 }
252 #[doc = "Timeout after which the analysis will be aborted"]
253 pub fn timeout(mut self, timeout: &'b str) -> Self {
254 self.timeout = Some(timeout);
255 self
256 }
257 #[doc = "Optional parameter to specify the timestamp field in the file"]
258 pub fn timestamp_field(mut self, timestamp_field: &'b str) -> Self {
259 self.timestamp_field = Some(timestamp_field);
260 self
261 }
262 #[doc = "Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format"]
263 pub fn timestamp_format(mut self, timestamp_format: &'b str) -> Self {
264 self.timestamp_format = Some(timestamp_format);
265 self
266 }
267 #[doc = "Creates an asynchronous call to the Text Structure Find Structure API that can be awaited"]
268 pub async fn send(self) -> Result<Response, Error> {
269 let path = self.parts.url();
270 let method = Method::Post;
271 let headers = self.headers;
272 let timeout = self.request_timeout;
273 let query_string = {
274 #[serde_with::skip_serializing_none]
275 #[derive(Serialize)]
276 struct QueryParams<'b> {
277 charset: Option<&'b str>,
278 #[serde(serialize_with = "crate::client::serialize_coll_qs")]
279 column_names: Option<&'b [&'b str]>,
280 delimiter: Option<&'b str>,
281 error_trace: Option<bool>,
282 explain: Option<bool>,
283 #[serde(serialize_with = "crate::client::serialize_coll_qs")]
284 filter_path: Option<&'b [&'b str]>,
285 format: Option<Format>,
286 grok_pattern: Option<&'b str>,
287 has_header_row: Option<bool>,
288 human: Option<bool>,
289 line_merge_size_limit: Option<i32>,
290 lines_to_sample: Option<i32>,
291 pretty: Option<bool>,
292 quote: Option<&'b str>,
293 should_trim_fields: Option<bool>,
294 source: Option<&'b str>,
295 timeout: Option<&'b str>,
296 timestamp_field: Option<&'b str>,
297 timestamp_format: Option<&'b str>,
298 }
299 let query_params = QueryParams {
300 charset: self.charset,
301 column_names: self.column_names,
302 delimiter: self.delimiter,
303 error_trace: self.error_trace,
304 explain: self.explain,
305 filter_path: self.filter_path,
306 format: self.format,
307 grok_pattern: self.grok_pattern,
308 has_header_row: self.has_header_row,
309 human: self.human,
310 line_merge_size_limit: self.line_merge_size_limit,
311 lines_to_sample: self.lines_to_sample,
312 pretty: self.pretty,
313 quote: self.quote,
314 should_trim_fields: self.should_trim_fields,
315 source: self.source,
316 timeout: self.timeout,
317 timestamp_field: self.timestamp_field,
318 timestamp_format: self.timestamp_format,
319 };
320 Some(query_params)
321 };
322 let body = self.body;
323 let response = self
324 .transport
325 .send(method, &path, headers, query_string.as_ref(), body, timeout)
326 .await?;
327 Ok(response)
328 }
329}
330#[doc = "Namespace client for TextStructure APIs"]
331#[doc = " \n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n "]
332#[cfg(feature = "experimental-apis")]
333pub struct TextStructure<'a> {
334 transport: &'a Transport,
335}
336#[cfg(feature = "experimental-apis")]
337impl<'a> TextStructure<'a> {
338 #[doc = "Creates a new instance of [TextStructure]"]
339 pub fn new(transport: &'a Transport) -> Self {
340 Self { transport }
341 }
342 pub fn transport(&self) -> &Transport {
343 self.transport
344 }
345 #[doc = "[Text Structure Find Structure API](https://opensearch.org/docs/)\n\nFinds the structure of a text file. The text file must contain data that is suitable to be ingested into Elasticsearch."]
346 #[doc = " \n# Optional, experimental\nThis requires the `experimental-apis` feature. Can have breaking changes in future\nversions or might even be removed entirely.\n "]
347 #[cfg(feature = "experimental-apis")]
348 pub fn find_structure<'b>(&'a self) -> TextStructureFindStructure<'a, 'b, ()> {
349 TextStructureFindStructure::new(self.transport())
350 }
351}
352#[cfg(feature = "experimental-apis")]
353impl OpenSearch {
354 #[doc = "Creates a namespace client for TextStructure APIs"]
355 pub fn text_structure(&self) -> TextStructure {
356 TextStructure::new(self.transport())
357 }
358}