manticore_openapi/apis/
index_api.rs

1/*
2 * Manticore Search Client
3 *
4 * Сlient for Manticore Search.
5 *
6 * The version of the OpenAPI document: 3.3.1
7 * Contact: info@manticoresearch.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`bulk`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum BulkError {
20    DefaultResponse(models::ErrorResponse),
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`delete`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum DeleteError {
28    DefaultResponse(models::ErrorResponse),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`insert`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum InsertError {
36    DefaultResponse(models::ErrorResponse),
37    UnknownValue(serde_json::Value),
38}
39
40/// struct for typed errors of method [`replace`]
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum ReplaceError {
44    DefaultResponse(models::ErrorResponse),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`update`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum UpdateError {
52    DefaultResponse(models::ErrorResponse),
53    UnknownValue(serde_json::Value),
54}
55
56/// Sends multiple operatons like inserts, updates, replaces or deletes.  For each operation it's object must have same format as in their dedicated method.  The method expects a raw string as the batch in NDJSON.  Each operation object needs to be serialized to   JSON and separated by endline (\\n).      An example of raw input:      ```   {\"insert\": {\"index\": \"movies\", \"doc\": {\"plot\": \"A secret team goes to North Pole\", \"rating\": 9.5, \"language\": [2, 3], \"title\": \"This is an older movie\", \"lon\": 51.99, \"meta\": {\"keywords\":[\"travel\",\"ice\"],\"genre\":[\"adventure\"]}, \"year\": 1950, \"lat\": 60.4, \"advise\": \"PG-13\"}}}   \\n   {\"delete\": {\"index\": \"movies\",\"id\":700}}   ```      Responds with an object telling whenever any errors occured and an array with status for each operation:      ```   {     'items':     [       {         'update':{'_index':'products','_id':1,'result':'updated'}       },       {         'update':{'_index':'products','_id':2,'result':'updated'}       }     ],     'errors':false   }   ```
57pub async fn bulk(
58    configuration: &configuration::Configuration,
59    body: &str,
60) -> Result<models::BulkResponse, Error<BulkError>> {
61    let local_var_configuration = configuration;
62
63    let local_var_client = &local_var_configuration.client;
64
65    let local_var_uri_str = format!("{}/bulk", local_var_configuration.base_path);
66    let mut local_var_req_builder =
67        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
68
69    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
70        local_var_req_builder =
71            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    local_var_req_builder = local_var_req_builder.json(&body);
74
75    let local_var_req = local_var_req_builder.build()?;
76    let local_var_resp = local_var_client.execute(local_var_req).await?;
77
78    let local_var_status = local_var_resp.status();
79    let local_var_content = local_var_resp.text().await?;
80
81    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82        serde_json::from_str(&local_var_content).map_err(Error::from)
83    } else {
84        let local_var_entity: Option<BulkError> = serde_json::from_str(&local_var_content).ok();
85        let local_var_error = ResponseContent {
86            status: local_var_status,
87            content: local_var_content,
88            entity: local_var_entity,
89        };
90        Err(Error::ResponseError(local_var_error))
91    }
92}
93
94/// Delete one or several documents. The method has 2 ways of deleting: either by id, in case only one document is deleted or by using a  match query, in which case multiple documents can be delete . Example of input to delete by id:    ```   {'index':'movies','id':100}   ```  Example of input to delete using a query:    ```   {     'index':'movies',     'query':     {       'bool':       {         'must':         [           {'query_string':'new movie'}         ]       }     }   }   ```  The match query has same syntax as in for searching. Responds with an object telling how many documents got deleted:     ```   {'_index':'products','updated':1}   ```
95pub async fn delete(
96    configuration: &configuration::Configuration,
97    delete_document_request: models::DeleteDocumentRequest,
98) -> Result<models::DeleteResponse, Error<DeleteError>> {
99    let local_var_configuration = configuration;
100
101    let local_var_client = &local_var_configuration.client;
102
103    let local_var_uri_str = format!("{}/delete", local_var_configuration.base_path);
104    let mut local_var_req_builder =
105        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
106
107    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
108        local_var_req_builder =
109            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
110    }
111    local_var_req_builder = local_var_req_builder.json(&delete_document_request);
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text().await?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        serde_json::from_str(&local_var_content).map_err(Error::from)
121    } else {
122        let local_var_entity: Option<DeleteError> = serde_json::from_str(&local_var_content).ok();
123        let local_var_error = ResponseContent {
124            status: local_var_status,
125            content: local_var_content,
126            entity: local_var_entity,
127        };
128        Err(Error::ResponseError(local_var_error))
129    }
130}
131
132/// Insert a document.  Expects an object like:     ```   {     'index':'movies',     'id':701,     'doc':     {       'title':'This is an old movie',       'plot':'A secret team goes to North Pole',       'year':1950,       'rating':9.5,       'lat':60.4,       'lon':51.99,       'advise':'PG-13',       'meta':'{\"keywords\":{\"travel\",\"ice\"},\"genre\":{\"adventure\"}}',       'language':[2,3]     }   }   ```   The document id can also be missing, in which case an autogenerated one will be used:             ```   {     'index':'movies',     'doc':     {       'title':'This is a new movie',       'plot':'A secret team goes to North Pole',       'year':2020,       'rating':9.5,       'lat':60.4,       'lon':51.99,       'advise':'PG-13',       'meta':'{\"keywords\":{\"travel\",\"ice\"},\"genre\":{\"adventure\"}}',       'language':[2,3]     }   }   ```   It responds with an object in format:      ```   {'_index':'products','_id':701,'created':true,'result':'created','status':201}   ```
133pub async fn insert(
134    configuration: &configuration::Configuration,
135    insert_document_request: models::InsertDocumentRequest,
136) -> Result<models::SuccessResponse, Error<InsertError>> {
137    let local_var_configuration = configuration;
138
139    let local_var_client = &local_var_configuration.client;
140
141    let local_var_uri_str = format!("{}/insert", local_var_configuration.base_path);
142    let mut local_var_req_builder =
143        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
144
145    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146        local_var_req_builder =
147            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
148    }
149    println!(
150        "request = {}",
151        serde_json::to_string(&insert_document_request)?
152    );
153    local_var_req_builder = local_var_req_builder.json(&insert_document_request);
154
155    let local_var_req = local_var_req_builder.build()?;
156    let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158    let local_var_status = local_var_resp.status();
159    let local_var_content = local_var_resp.text().await?;
160    println!("response = {}", local_var_content);
161
162    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
163        serde_json::from_str(&local_var_content).map_err(Error::from)
164    } else {
165        let local_var_entity: Option<InsertError> = serde_json::from_str(&local_var_content).ok();
166        let local_var_error = ResponseContent {
167            status: local_var_status,
168            content: local_var_content,
169            entity: local_var_entity,
170        };
171        Err(Error::ResponseError(local_var_error))
172    }
173}
174
175/// Replace an existing document. Input has same format as `insert` operation. <br/> Responds with an object in format: <br/>    ```   {'_index':'products','_id':1,'created':false,'result':'updated','status':200}   ```
176pub async fn replace(
177    configuration: &configuration::Configuration,
178    insert_document_request: models::InsertDocumentRequest,
179) -> Result<models::SuccessResponse, Error<ReplaceError>> {
180    let local_var_configuration = configuration;
181
182    let local_var_client = &local_var_configuration.client;
183
184    let local_var_uri_str = format!("{}/replace", local_var_configuration.base_path);
185    let mut local_var_req_builder =
186        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
187
188    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
189        local_var_req_builder =
190            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
191    }
192    local_var_req_builder = local_var_req_builder.json(&insert_document_request);
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<ReplaceError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent {
205            status: local_var_status,
206            content: local_var_content,
207            entity: local_var_entity,
208        };
209        Err(Error::ResponseError(local_var_error))
210    }
211}
212
213/// Update one or several documents. The update can be made by passing the id or by using a match query in case multiple documents can be updated.  For example update a document using document id:    ```   {'index':'movies','doc':{'rating':9.49},'id':100}   ```  And update by using a match query:    ```   {     'index':'movies',     'doc':{'rating':9.49},     'query':     {       'bool':       {         'must':         [           {'query_string':'new movie'}         ]       }     }   }   ```   The match query has same syntax as for searching. Responds with an object that tells how many documents where updated in format:     ```   {'_index':'products','updated':1}   ```
214pub async fn update(
215    configuration: &configuration::Configuration,
216    update_document_request: models::UpdateDocumentRequest,
217) -> Result<models::UpdateResponse, Error<UpdateError>> {
218    let local_var_configuration = configuration;
219
220    let local_var_client = &local_var_configuration.client;
221
222    let local_var_uri_str = format!("{}/update", local_var_configuration.base_path);
223    let mut local_var_req_builder =
224        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
225
226    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227        local_var_req_builder =
228            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229    }
230    local_var_req_builder = local_var_req_builder.json(&update_document_request);
231
232    let local_var_req = local_var_req_builder.build()?;
233    let local_var_resp = local_var_client.execute(local_var_req).await?;
234
235    let local_var_status = local_var_resp.status();
236    let local_var_content = local_var_resp.text().await?;
237
238    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
239        serde_json::from_str(&local_var_content).map_err(Error::from)
240    } else {
241        let local_var_entity: Option<UpdateError> = serde_json::from_str(&local_var_content).ok();
242        let local_var_error = ResponseContent {
243            status: local_var_status,
244            content: local_var_content,
245            entity: local_var_entity,
246        };
247        Err(Error::ResponseError(local_var_error))
248    }
249}