1#![allow(unused_imports)]
34use crate::{
35 client::Elasticsearch,
36 error::Error,
37 http::{
38 self,
39 headers::{HeaderMap, HeaderName, HeaderValue, ACCEPT, CONTENT_TYPE},
40 request::{Body, JsonBody, NdBody, PARTS_ENCODED},
41 response::Response,
42 transport::Transport,
43 },
44 params::*,
45};
46use percent_encoding::percent_encode;
47use serde::Serialize;
48use std::{borrow::Cow, time::Duration};
49#[derive(Debug, Clone, PartialEq, Eq)]
50#[doc = "API parts for the Graph Explore API"]
51pub enum GraphExploreParts<'b> {
52 #[doc = "Index"]
53 Index(&'b [&'b str]),
54}
55impl<'b> GraphExploreParts<'b> {
56 #[doc = "Builds a relative URL path to the Graph Explore API"]
57 pub fn url(self) -> Cow<'static, str> {
58 match self {
59 GraphExploreParts::Index(index) => {
60 let index_str = index.join(",");
61 let encoded_index: Cow<str> =
62 percent_encode(index_str.as_bytes(), PARTS_ENCODED).into();
63 let mut p = String::with_capacity(16usize + encoded_index.len());
64 p.push('/');
65 p.push_str(encoded_index.as_ref());
66 p.push_str("/_graph/explore");
67 p.into()
68 }
69 }
70 }
71}
72#[doc = "Builder for the [Graph Explore API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/graph-explore-api.html)\n\nExplore extracted and summarized information about the documents and terms in an index."]
73#[derive(Clone, Debug)]
74pub struct GraphExplore<'a, 'b, B> {
75 transport: &'a Transport,
76 parts: GraphExploreParts<'b>,
77 body: Option<B>,
78 error_trace: Option<bool>,
79 filter_path: Option<&'b [&'b str]>,
80 headers: HeaderMap,
81 human: Option<bool>,
82 pretty: Option<bool>,
83 request_timeout: Option<Duration>,
84 routing: Option<&'b str>,
85 source: Option<&'b str>,
86 timeout: Option<&'b str>,
87}
88impl<'a, 'b, B> GraphExplore<'a, 'b, B>
89where
90 B: Body,
91{
92 #[doc = "Creates a new instance of [GraphExplore] with the specified API parts"]
93 pub fn new(transport: &'a Transport, parts: GraphExploreParts<'b>) -> Self {
94 let headers = HeaderMap::new();
95 GraphExplore {
96 transport,
97 parts,
98 headers,
99 body: None,
100 error_trace: None,
101 filter_path: None,
102 human: None,
103 pretty: None,
104 request_timeout: None,
105 routing: None,
106 source: None,
107 timeout: None,
108 }
109 }
110 #[doc = "The body for the API call"]
111 pub fn body<T>(self, body: T) -> GraphExplore<'a, 'b, JsonBody<T>>
112 where
113 T: Serialize,
114 {
115 GraphExplore {
116 transport: self.transport,
117 parts: self.parts,
118 body: Some(body.into()),
119 error_trace: self.error_trace,
120 filter_path: self.filter_path,
121 headers: self.headers,
122 human: self.human,
123 pretty: self.pretty,
124 request_timeout: self.request_timeout,
125 routing: self.routing,
126 source: self.source,
127 timeout: self.timeout,
128 }
129 }
130 #[doc = "Include the stack trace of returned errors."]
131 pub fn error_trace(mut self, error_trace: bool) -> Self {
132 self.error_trace = Some(error_trace);
133 self
134 }
135 #[doc = "A comma-separated list of filters used to reduce the response."]
136 pub fn filter_path(mut self, filter_path: &'b [&'b str]) -> Self {
137 self.filter_path = Some(filter_path);
138 self
139 }
140 #[doc = "Adds a HTTP header"]
141 pub fn header(mut self, key: HeaderName, value: HeaderValue) -> Self {
142 self.headers.insert(key, value);
143 self
144 }
145 #[doc = "Return human readable values for statistics."]
146 pub fn human(mut self, human: bool) -> Self {
147 self.human = Some(human);
148 self
149 }
150 #[doc = "Pretty format the returned JSON response."]
151 pub fn pretty(mut self, pretty: bool) -> Self {
152 self.pretty = Some(pretty);
153 self
154 }
155 #[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."]
156 pub fn request_timeout(mut self, timeout: Duration) -> Self {
157 self.request_timeout = Some(timeout);
158 self
159 }
160 #[doc = "Specific routing value"]
161 pub fn routing(mut self, routing: &'b str) -> Self {
162 self.routing = Some(routing);
163 self
164 }
165 #[doc = "The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests."]
166 pub fn source(mut self, source: &'b str) -> Self {
167 self.source = Some(source);
168 self
169 }
170 #[doc = "Explicit operation timeout"]
171 pub fn timeout(mut self, timeout: &'b str) -> Self {
172 self.timeout = Some(timeout);
173 self
174 }
175 #[doc = "Creates an asynchronous call to the Graph Explore API that can be awaited"]
176 pub async fn send(self) -> Result<Response, Error> {
177 let path = self.parts.url();
178 let method = match self.body {
179 Some(_) => http::Method::Post,
180 None => http::Method::Get,
181 };
182 let headers = self.headers;
183 let timeout = self.request_timeout;
184 let query_string = {
185 #[serde_with::skip_serializing_none]
186 #[derive(Serialize)]
187 struct QueryParams<'b> {
188 error_trace: Option<bool>,
189 #[serde(serialize_with = "crate::client::serialize_coll_qs")]
190 filter_path: Option<&'b [&'b str]>,
191 human: Option<bool>,
192 pretty: Option<bool>,
193 routing: Option<&'b str>,
194 source: Option<&'b str>,
195 timeout: Option<&'b str>,
196 }
197 let query_params = QueryParams {
198 error_trace: self.error_trace,
199 filter_path: self.filter_path,
200 human: self.human,
201 pretty: self.pretty,
202 routing: self.routing,
203 source: self.source,
204 timeout: self.timeout,
205 };
206 Some(query_params)
207 };
208 let body = self.body;
209 let response = self
210 .transport
211 .send(method, &path, headers, query_string.as_ref(), body, timeout)
212 .await?;
213 Ok(response)
214 }
215}
216#[doc = "Namespace client for Graph APIs"]
217pub struct Graph<'a> {
218 transport: &'a Transport,
219}
220impl<'a> Graph<'a> {
221 #[doc = "Creates a new instance of [Graph]"]
222 pub fn new(transport: &'a Transport) -> Self {
223 Self { transport }
224 }
225 pub fn transport(&self) -> &Transport {
226 self.transport
227 }
228 #[doc = "[Graph Explore API](https://www.elastic.co/guide/en/elasticsearch/reference/9.0/graph-explore-api.html)\n\nExplore extracted and summarized information about the documents and terms in an index."]
229 pub fn explore<'b>(&'a self, parts: GraphExploreParts<'b>) -> GraphExplore<'a, 'b, ()> {
230 GraphExplore::new(self.transport(), parts)
231 }
232}
233impl Elasticsearch {
234 #[doc = "Creates a namespace client for Graph APIs"]
235 pub fn graph(&self) -> Graph {
236 Graph::new(self.transport())
237 }
238}