|
88 | 88 | //! To create a client to make API calls to Elasticsearch running on `http://localhost:9200` |
89 | 89 | //! |
90 | 90 | //! ```rust,no_run |
91 | | -//! # use elasticsearch::{Error, Elasticsearch}; |
92 | | -//! # fn run() { |
| 91 | +//! # use elasticsearch::Elasticsearch; |
93 | 92 | //! let client = Elasticsearch::default(); |
94 | | -//! # } |
95 | 93 | //! ``` |
| 94 | +//! |
96 | 95 | //! Alternatively, you can create a client to make API calls against Elasticsearch running on a |
97 | 96 | //! specific [url::Url] |
98 | 97 | //! |
|
101 | 100 | //! # Error, Elasticsearch, |
102 | 101 | //! # http::transport::{Transport, SingleNodeConnectionPool} |
103 | 102 | //! # }; |
104 | | -//! # fn run() -> Result<(), Error> { |
| 103 | +//! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
105 | 104 | //! let transport = Transport::single_node("https://example.com")?; |
106 | 105 | //! let client = Elasticsearch::new(transport); |
107 | 106 | //! # Ok(()) |
|
119 | 118 | //! # http::transport::Transport, |
120 | 119 | //! # }; |
121 | 120 | //! # use url::Url; |
122 | | -//! # fn run() -> Result<(), Error> { |
| 121 | +//! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
123 | 122 | //! let cloud_id = "cluster_name:Y2xvdWQtZW5kcG9pbnQuZXhhbXBsZSQzZGFkZjgyM2YwNTM4ODQ5N2VhNjg0MjM2ZDkxOGExYQ=="; |
124 | 123 | //! let credentials = Credentials::Basic("<username>".into(), "<password>".into()); |
125 | 124 | //! let transport = Transport::cloud(cloud_id, credentials)?; |
|
139 | 138 | //! # http::transport::{TransportBuilder,SingleNodeConnectionPool}, |
140 | 139 | //! # }; |
141 | 140 | //! # use url::Url; |
142 | | -//! # fn run() -> Result<(), Error> { |
| 141 | +//! # fn main() -> Result<(), Box<dyn std::error::Error>> { |
143 | 142 | //! let url = Url::parse("https://example.com")?; |
144 | 143 | //! let conn_pool = SingleNodeConnectionPool::new(url); |
145 | 144 | //! let transport = TransportBuilder::new(conn_pool).disable_proxy().build()?; |
|
157 | 156 | //! The following makes an API call to the cat indices API |
158 | 157 | //! |
159 | 158 | //! ```rust,no_run |
160 | | -//! # use elasticsearch; |
161 | | -//! # use elasticsearch::{Elasticsearch, Error, cat::CatIndicesParts}; |
| 159 | +//! # use elasticsearch::{auth::Credentials, Elasticsearch, Error, cat::CatIndicesParts}; |
162 | 160 | //! # use url::Url; |
163 | | -//! # use elasticsearch::auth::Credentials; |
164 | 161 | //! # use serde_json::{json, Value}; |
165 | | -//! # async fn run() -> Result<(), Error> { |
| 162 | +//! # #[tokio::main] |
| 163 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error>> { |
166 | 164 | //! # let client = Elasticsearch::default(); |
167 | 165 | //! let response = client |
168 | 166 | //! .cat() |
|
187 | 185 | //! Indexing a single document can be achieved with the index API |
188 | 186 | //! |
189 | 187 | //! ```rust,no_run |
190 | | -//! # use elasticsearch; |
191 | | -//! # use elasticsearch::{Elasticsearch, Error, SearchParts, IndexParts}; |
| 188 | +//! # use elasticsearch::{auth::Credentials, Elasticsearch, Error, SearchParts, IndexParts}; |
192 | 189 | //! # use url::Url; |
193 | | -//! # use elasticsearch::auth::Credentials; |
194 | 190 | //! # use serde_json::{json, Value}; |
195 | | -//! # async fn run() -> Result<(), Error> { |
| 191 | +//! # #[tokio::main] |
| 192 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error>> { |
196 | 193 | //! # let client = Elasticsearch::default(); |
197 | 194 | //! let response = client |
198 | 195 | //! .index(IndexParts::IndexId("tweets", "1")) |
|
214 | 211 | //! to be sent in one API call |
215 | 212 | //! |
216 | 213 | //! ```rust,no_run |
217 | | -//! # use elasticsearch; |
218 | | -//! # use elasticsearch::{Elasticsearch, Error, IndexParts, BulkParts, http::request::JsonBody}; |
| 214 | +//! # use elasticsearch::{auth::Credentials, Elasticsearch, Error, IndexParts, BulkParts, http::request::JsonBody}; |
219 | 215 | //! # use url::Url; |
220 | | -//! # use elasticsearch::auth::Credentials; |
221 | 216 | //! # use serde_json::{json, Value}; |
222 | | -//! # async fn run() -> Result<(), Error> { |
| 217 | +//! # #[tokio::main] |
| 218 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error>> { |
223 | 219 | //! # let client = Elasticsearch::default(); |
224 | 220 | //! let mut body: Vec<JsonBody<_>> = Vec::with_capacity(4); |
225 | 221 | //! |
|
258 | 254 | //! `{"query":{"match":{"message":"Elasticsearch"}}}` |
259 | 255 | //! |
260 | 256 | //! ```rust,no_run |
261 | | -//! # use elasticsearch; |
262 | | -//! # use elasticsearch::{Elasticsearch, Error, SearchParts}; |
| 257 | +//! # use elasticsearch::{auth::Credentials, Elasticsearch, Error, SearchParts}; |
263 | 258 | //! # use url::Url; |
264 | | -//! # use elasticsearch::auth::Credentials; |
265 | 259 | //! # use serde_json::{json, Value}; |
266 | | -//! # async fn run() -> Result<(), Error> { |
| 260 | +//! # #[tokio::main] |
| 261 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error>> { |
267 | 262 | //! # let client = Elasticsearch::default(); |
268 | 263 | //! let response = client |
269 | 264 | //! .search(SearchParts::Index(&["tweets"])) |
|
306 | 301 | //! [Elasticsearch::send] can be used |
307 | 302 | //! |
308 | 303 | //! ```rust,no_run |
309 | | -//! # use elasticsearch; |
310 | | -//! # use elasticsearch::{Elasticsearch, Error, SearchParts}; |
| 304 | +//! # use elasticsearch::{auth::Credentials, http::{Method,headers::HeaderMap}, Elasticsearch, Error, SearchParts}; |
311 | 305 | //! # use url::Url; |
312 | | -//! # use elasticsearch::auth::Credentials; |
313 | 306 | //! # use serde_json::{json, Value}; |
314 | | -//! # use http::HeaderMap; |
315 | | -//! # use elasticsearch::http::Method; |
316 | | -//! # async fn run() -> Result<(), Error> { |
| 307 | +//! # #[tokio::main] |
| 308 | +//! # async fn main() -> Result<(), Box<dyn std::error::Error>> { |
317 | 309 | //! # let client = Elasticsearch::default(); |
318 | 310 | //! let body = b"{\"query\":{\"match_all\":{}}}"; |
319 | 311 | //! |
|
0 commit comments