From c75354bcc4e1cf8dfc445efb1abd607fab86b94f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 18 Sep 2016 18:47:33 +1000 Subject: [PATCH 001/127] initial port --- .gitattributes | 63 ++++++ .gitignore | 18 ++ Cargo.toml | 21 ++ codegen/.gitignore | 2 + codegen/Cargo.toml | 13 ++ codegen/README.md | 8 + codegen/src/main.rs | 312 ++++++++++++++++++++++++++ elastic_hyper.rsproj | 39 ++++ samples/README.md | 3 + samples/basic/.gitignore | 2 + samples/basic/Cargo.toml | 12 + samples/basic/src/main.rs | 43 ++++ samples/typed/.gitignore | 2 + samples/typed/Cargo.toml | 17 ++ samples/typed/src/main.rs | 130 +++++++++++ samples/typed/src/response.rs | 66 ++++++ src/api/bulk/mod.rs | 124 ++++++++++ src/api/cat/aliases.rs | 35 +++ src/api/cat/allocation.rs | 36 +++ src/api/cat/count.rs | 35 +++ src/api/cat/fielddata.rs | 35 +++ src/api/cat/health.rs | 20 ++ src/api/cat/help.rs | 20 ++ src/api/cat/indices.rs | 35 +++ src/api/cat/master.rs | 20 ++ src/api/cat/mod.rs | 19 ++ src/api/cat/nodeattrs.rs | 20 ++ src/api/cat/nodes.rs | 20 ++ src/api/cat/pending_tasks.rs | 20 ++ src/api/cat/plugins.rs | 20 ++ src/api/cat/recovery.rs | 35 +++ src/api/cat/repositories.rs | 20 ++ src/api/cat/segments.rs | 35 +++ src/api/cat/shards.rs | 35 +++ src/api/cat/snapshots.rs | 24 ++ src/api/cat/tasks.rs | 20 ++ src/api/cat/thread_pool.rs | 20 ++ src/api/clear_scroll/mod.rs | 37 +++ src/api/cluster/allocation_explain.rs | 35 +++ src/api/cluster/get_settings.rs | 20 ++ src/api/cluster/health.rs | 35 +++ src/api/cluster/mod.rs | 8 + src/api/cluster/pending_tasks.rs | 20 ++ src/api/cluster/put_settings.rs | 23 ++ src/api/cluster/reroute.rs | 23 ++ src/api/cluster/state.rs | 53 +++++ src/api/cluster/stats.rs | 36 +++ src/api/count/mod.rs | 114 ++++++++++ src/api/count_percolate/mod.rs | 98 ++++++++ src/api/delete/mod.rs | 29 +++ src/api/delete_by_query/mod.rs | 51 +++++ src/api/delete_script/mod.rs | 26 +++ src/api/delete_template/mod.rs | 23 ++ src/api/exists/mod.rs | 29 +++ src/api/explain/mod.rs | 56 +++++ src/api/field_stats/mod.rs | 72 ++++++ src/api/get/mod.rs | 29 +++ src/api/get_script/mod.rs | 26 +++ src/api/get_source/mod.rs | 30 +++ src/api/get_template/mod.rs | 23 ++ src/api/index/mod.rs | 102 +++++++++ src/api/indices/analyze.rs | 72 ++++++ src/api/indices/clear_cache.rs | 72 ++++++ src/api/indices/close.rs | 28 +++ src/api/indices/create.rs | 44 ++++ src/api/indices/delete.rs | 23 ++ src/api/indices/delete_alias.rs | 26 +++ src/api/indices/delete_template.rs | 23 ++ src/api/indices/exists.rs | 23 ++ src/api/indices/exists_alias.rs | 58 +++++ src/api/indices/exists_template.rs | 23 ++ src/api/indices/exists_type.rs | 26 +++ src/api/indices/flush.rs | 72 ++++++ src/api/indices/flush_synced.rs | 72 ++++++ src/api/indices/forcemerge.rs | 43 ++++ src/api/indices/get.rs | 41 ++++ src/api/indices/get_alias.rs | 70 ++++++ src/api/indices/get_field_mapping.rs | 80 +++++++ src/api/indices/get_mapping.rs | 70 ++++++ src/api/indices/get_settings.rs | 70 ++++++ src/api/indices/get_template.rs | 35 +++ src/api/indices/get_upgrade.rs | 37 +++ src/api/indices/mod.rs | 36 +++ src/api/indices/open.rs | 28 +++ src/api/indices/put_alias.rs | 52 +++++ src/api/indices/put_mapping.rs | 87 +++++++ src/api/indices/put_settings.rs | 43 ++++ src/api/indices/put_template.rs | 43 ++++ src/api/indices/recovery.rs | 37 +++ src/api/indices/refresh.rs | 72 ++++++ src/api/indices/rollover.rs | 50 +++++ src/api/indices/segments.rs | 37 +++ src/api/indices/shard_stores.rs | 37 +++ src/api/indices/shrink.rs | 52 +++++ src/api/indices/stats.rs | 70 ++++++ src/api/indices/update_aliases.rs | 23 ++ src/api/indices/upgrade.rs | 43 ++++ src/api/indices/validate_query.rs | 114 ++++++++++ src/api/info/mod.rs | 20 ++ src/api/ingest/delete_pipeline.rs | 23 ++ src/api/ingest/get_pipeline.rs | 23 ++ src/api/ingest/mod.rs | 4 + src/api/ingest/put_pipeline.rs | 25 +++ src/api/ingest/simulate.rs | 71 ++++++ src/api/mget/mod.rs | 114 ++++++++++ src/api/mod.rs | 43 ++++ src/api/mpercolate/mod.rs | 114 ++++++++++ src/api/msearch/mod.rs | 114 ++++++++++ src/api/msearch_template/mod.rs | 114 ++++++++++ src/api/mtermvectors/mod.rs | 114 ++++++++++ src/api/nodes/hot_threads.rs | 37 +++ src/api/nodes/info.rs | 69 ++++++ src/api/nodes/mod.rs | 3 + src/api/nodes/stats.rs | 114 ++++++++++ src/api/percolate/mod.rs | 98 ++++++++ src/api/ping/mod.rs | 21 ++ src/api/put_script/mod.rs | 50 +++++ src/api/put_template/mod.rs | 42 ++++ src/api/reindex/mod.rs | 24 ++ src/api/reindex/rethrottle.rs | 28 +++ src/api/render_search_template/mod.rs | 67 ++++++ src/api/scroll/mod.rs | 71 ++++++ src/api/search/mod.rs | 114 ++++++++++ src/api/search_shards/mod.rs | 114 ++++++++++ src/api/search_template/mod.rs | 114 ++++++++++ src/api/snapshot/create.rs | 54 +++++ src/api/snapshot/create_repository.rs | 48 ++++ src/api/snapshot/delete.rs | 27 +++ src/api/snapshot/delete_repository.rs | 24 ++ src/api/snapshot/get.rs | 27 +++ src/api/snapshot/get_repository.rs | 36 +++ src/api/snapshot/mod.rs | 9 + src/api/snapshot/restore.rs | 32 +++ src/api/snapshot/status.rs | 57 +++++ src/api/snapshot/verify_repository.rs | 29 +++ src/api/suggest/mod.rs | 72 ++++++ src/api/tasks/cancel.rs | 43 ++++ src/api/tasks/get.rs | 23 ++ src/api/tasks/list.rs | 20 ++ src/api/tasks/mod.rs | 3 + src/api/termvectors/mod.rs | 98 ++++++++ src/api/update/mod.rs | 34 +++ src/api/update_by_query/mod.rs | 51 +++++ src/lib.rs | 265 ++++++++++++++++++++++ tests/mod.rs | 38 ++++ 145 files changed, 6964 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 codegen/.gitignore create mode 100644 codegen/Cargo.toml create mode 100644 codegen/README.md create mode 100644 codegen/src/main.rs create mode 100644 elastic_hyper.rsproj create mode 100644 samples/README.md create mode 100644 samples/basic/.gitignore create mode 100644 samples/basic/Cargo.toml create mode 100644 samples/basic/src/main.rs create mode 100644 samples/typed/.gitignore create mode 100644 samples/typed/Cargo.toml create mode 100644 samples/typed/src/main.rs create mode 100644 samples/typed/src/response.rs create mode 100644 src/api/bulk/mod.rs create mode 100644 src/api/cat/aliases.rs create mode 100644 src/api/cat/allocation.rs create mode 100644 src/api/cat/count.rs create mode 100644 src/api/cat/fielddata.rs create mode 100644 src/api/cat/health.rs create mode 100644 src/api/cat/help.rs create mode 100644 src/api/cat/indices.rs create mode 100644 src/api/cat/master.rs create mode 100644 src/api/cat/mod.rs create mode 100644 src/api/cat/nodeattrs.rs create mode 100644 src/api/cat/nodes.rs create mode 100644 src/api/cat/pending_tasks.rs create mode 100644 src/api/cat/plugins.rs create mode 100644 src/api/cat/recovery.rs create mode 100644 src/api/cat/repositories.rs create mode 100644 src/api/cat/segments.rs create mode 100644 src/api/cat/shards.rs create mode 100644 src/api/cat/snapshots.rs create mode 100644 src/api/cat/tasks.rs create mode 100644 src/api/cat/thread_pool.rs create mode 100644 src/api/clear_scroll/mod.rs create mode 100644 src/api/cluster/allocation_explain.rs create mode 100644 src/api/cluster/get_settings.rs create mode 100644 src/api/cluster/health.rs create mode 100644 src/api/cluster/mod.rs create mode 100644 src/api/cluster/pending_tasks.rs create mode 100644 src/api/cluster/put_settings.rs create mode 100644 src/api/cluster/reroute.rs create mode 100644 src/api/cluster/state.rs create mode 100644 src/api/cluster/stats.rs create mode 100644 src/api/count/mod.rs create mode 100644 src/api/count_percolate/mod.rs create mode 100644 src/api/delete/mod.rs create mode 100644 src/api/delete_by_query/mod.rs create mode 100644 src/api/delete_script/mod.rs create mode 100644 src/api/delete_template/mod.rs create mode 100644 src/api/exists/mod.rs create mode 100644 src/api/explain/mod.rs create mode 100644 src/api/field_stats/mod.rs create mode 100644 src/api/get/mod.rs create mode 100644 src/api/get_script/mod.rs create mode 100644 src/api/get_source/mod.rs create mode 100644 src/api/get_template/mod.rs create mode 100644 src/api/index/mod.rs create mode 100644 src/api/indices/analyze.rs create mode 100644 src/api/indices/clear_cache.rs create mode 100644 src/api/indices/close.rs create mode 100644 src/api/indices/create.rs create mode 100644 src/api/indices/delete.rs create mode 100644 src/api/indices/delete_alias.rs create mode 100644 src/api/indices/delete_template.rs create mode 100644 src/api/indices/exists.rs create mode 100644 src/api/indices/exists_alias.rs create mode 100644 src/api/indices/exists_template.rs create mode 100644 src/api/indices/exists_type.rs create mode 100644 src/api/indices/flush.rs create mode 100644 src/api/indices/flush_synced.rs create mode 100644 src/api/indices/forcemerge.rs create mode 100644 src/api/indices/get.rs create mode 100644 src/api/indices/get_alias.rs create mode 100644 src/api/indices/get_field_mapping.rs create mode 100644 src/api/indices/get_mapping.rs create mode 100644 src/api/indices/get_settings.rs create mode 100644 src/api/indices/get_template.rs create mode 100644 src/api/indices/get_upgrade.rs create mode 100644 src/api/indices/mod.rs create mode 100644 src/api/indices/open.rs create mode 100644 src/api/indices/put_alias.rs create mode 100644 src/api/indices/put_mapping.rs create mode 100644 src/api/indices/put_settings.rs create mode 100644 src/api/indices/put_template.rs create mode 100644 src/api/indices/recovery.rs create mode 100644 src/api/indices/refresh.rs create mode 100644 src/api/indices/rollover.rs create mode 100644 src/api/indices/segments.rs create mode 100644 src/api/indices/shard_stores.rs create mode 100644 src/api/indices/shrink.rs create mode 100644 src/api/indices/stats.rs create mode 100644 src/api/indices/update_aliases.rs create mode 100644 src/api/indices/upgrade.rs create mode 100644 src/api/indices/validate_query.rs create mode 100644 src/api/info/mod.rs create mode 100644 src/api/ingest/delete_pipeline.rs create mode 100644 src/api/ingest/get_pipeline.rs create mode 100644 src/api/ingest/mod.rs create mode 100644 src/api/ingest/put_pipeline.rs create mode 100644 src/api/ingest/simulate.rs create mode 100644 src/api/mget/mod.rs create mode 100644 src/api/mod.rs create mode 100644 src/api/mpercolate/mod.rs create mode 100644 src/api/msearch/mod.rs create mode 100644 src/api/msearch_template/mod.rs create mode 100644 src/api/mtermvectors/mod.rs create mode 100644 src/api/nodes/hot_threads.rs create mode 100644 src/api/nodes/info.rs create mode 100644 src/api/nodes/mod.rs create mode 100644 src/api/nodes/stats.rs create mode 100644 src/api/percolate/mod.rs create mode 100644 src/api/ping/mod.rs create mode 100644 src/api/put_script/mod.rs create mode 100644 src/api/put_template/mod.rs create mode 100644 src/api/reindex/mod.rs create mode 100644 src/api/reindex/rethrottle.rs create mode 100644 src/api/render_search_template/mod.rs create mode 100644 src/api/scroll/mod.rs create mode 100644 src/api/search/mod.rs create mode 100644 src/api/search_shards/mod.rs create mode 100644 src/api/search_template/mod.rs create mode 100644 src/api/snapshot/create.rs create mode 100644 src/api/snapshot/create_repository.rs create mode 100644 src/api/snapshot/delete.rs create mode 100644 src/api/snapshot/delete_repository.rs create mode 100644 src/api/snapshot/get.rs create mode 100644 src/api/snapshot/get_repository.rs create mode 100644 src/api/snapshot/mod.rs create mode 100644 src/api/snapshot/restore.rs create mode 100644 src/api/snapshot/status.rs create mode 100644 src/api/snapshot/verify_repository.rs create mode 100644 src/api/suggest/mod.rs create mode 100644 src/api/tasks/cancel.rs create mode 100644 src/api/tasks/get.rs create mode 100644 src/api/tasks/list.rs create mode 100644 src/api/tasks/mod.rs create mode 100644 src/api/termvectors/mod.rs create mode 100644 src/api/update/mod.rs create mode 100644 src/api/update_by_query/mod.rs create mode 100644 src/lib.rs create mode 100644 tests/mod.rs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..1ff0c4230 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..b7f386575 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Compiled files +*.o +*.so +*.rlib +*.dll +*.rs.bk + +# Executables +*.exe + +Cargo.lock + +# Visual Studio +*.user +*.suo + +/target/ +/obj/ \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..13a8b211e --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "elastic_hyper" +version = "0.3.1" +authors = ["Ashley Mannix "] +license = "Apache-2.0" +description = "A lightweight implementation of the Elasticsearch API based on Hyper." +documentation = "https://docs.rs/elastic_types/0.3.1/elastic_hyper/" +repository = "https://github.com/elastic-rs/elastic-hyper" +exclude = [ "samples", "codegen" ] + +[features] +default = [ "ssl" ] +ssl = [ "hyper/ssl" ] +nightly-testing = [ ] + +[dependencies] +hyper = { version = "~0.9.0", default-features = false } +url = "~1.1.0" + +[dev-dependencies] +json_str = "^0.*" diff --git a/codegen/.gitignore b/codegen/.gitignore new file mode 100644 index 000000000..ab22063e1 --- /dev/null +++ b/codegen/.gitignore @@ -0,0 +1,2 @@ +/target/ +/obj/ \ No newline at end of file diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml new file mode 100644 index 000000000..67c8a1919 --- /dev/null +++ b/codegen/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "elastic_hyper_codegen" +version = "0.1.0" +authors = ["Ashley Mannix "] + +[features] +nightly-testing = [] + +[dependencies] +error-chain = "*" +aster = { version = "*" } +elastic_codegen = { version = "*", path = "../../codegen" } +walkdir = { version = "*" } diff --git a/codegen/README.md b/codegen/README.md new file mode 100644 index 000000000..7e7688f34 --- /dev/null +++ b/codegen/README.md @@ -0,0 +1,8 @@ +# `elastic_hyper` codegen + +This is the utility that takes the Elasticsearch API spec and generates `rust` source for `hyper`. +To generate source, build this crate and run: + +``` +target/release/elastic_hyper_codegen ../../codegen/spec/api ../src/api +``` diff --git a/codegen/src/main.rs b/codegen/src/main.rs new file mode 100644 index 000000000..2a13aadf6 --- /dev/null +++ b/codegen/src/main.rs @@ -0,0 +1,312 @@ +#![feature(rustc_private, quote)] + +#[macro_use] +extern crate error_chain; +extern crate syntax; +extern crate aster; +extern crate elastic_codegen; +extern crate walkdir; + +use std::io::Read; +use std::fs; +use std::fs::{ File, OpenOptions }; +use std::collections::HashMap; +use syntax::ast::*; +use syntax::ext::base::{ ExtCtxt, DummyMacroLoader }; +use syntax::parse::token; +use syntax::codemap::DUMMY_SP; +use syntax::parse::token::intern; +use elastic_codegen::api::ast::*; +use elastic_codegen::api::parse::*; +use elastic_codegen::api::gen::rust::*; +use elastic_codegen::gen::rust::*; +use elastic_codegen::api::gen::parse::{ parse_path_parts, parse_path_params }; +use elastic_codegen::emit::*; +use elastic_codegen::emit::rust::*; +use walkdir::WalkDir; +use std::env; + +error_chain! { + types { + Error, ErrorKind, ChainErr, Result; + } + + links { } + + foreign_links { + elastic_codegen::api::parse::ParseError, ApiParse; + elastic_codegen::api::gen::rust::ApiGenError, GenParse; + elastic_codegen::emit::EmitError, Emit; + std::io::Error, Io; + } + + errors { } +} + +fn main() { + let mut args = env::args(); + let _ = args.next().unwrap(); + let indir = args.next().unwrap(); + let outdir = args.next().unwrap(); + + println!("spec: {}", indir); + println!("output: {}", outdir); + + gen_from_source(&indir, &outdir).unwrap(); +} + +fn gen_from_source(source_dir: &str, dest_dir: &str) -> Result<()> { + //Clear out the contents of the dest_dir + println!("clearing destination dir..."); + let _ = try!(fs::remove_dir_all(dest_dir)); + let _ = try!(fs::create_dir_all(dest_dir)); + + //Create an emitter and Execution Context + let ps = syntax::parse::ParseSess::new(); + let mut mc = DummyMacroLoader; + + let mut cx = ExtCtxt::new( + &ps, vec![], + syntax::ext::expand::ExpansionConfig::default("qquote".to_string()), + &mut mc + ); + cx.bt_push(syntax::codemap::ExpnInfo { + call_site: DUMMY_SP, + callee: syntax::codemap::NameAndSpan { + format: syntax::codemap::MacroBang(intern("")), + allow_internal_unstable: false, + span: None, + } + }); + + let emitter = RustEmitter::new(); + + //Get the spec source + println!("parsing source spec files..."); + let parsed = try!(from_dir(source_dir)); + + for endpoint in parsed { + //1. Get the path for the generated source + println!("building path for {}...", endpoint.get_name()); + let mut path = try!(endpoint.get_mod_path()); + let (file, file_is_mod) = match path.len() { + 0 => ("mod".to_string(), true), + 1 => ("mod".to_string(), true), + _ => (try!(path.pop().ok_or(format!("Error parsing path filename for {}", endpoint.get_name()))), false) + }; + + let dir_path = format!("{}/{}", dest_dir, path.join("/")); + let file_path = format!("{}/{}.rs", dir_path, file); + + //Ensure the path exists + try!(fs::create_dir_all(&dir_path)); + + //2. Open the source file + let (mut src_file, is_new) = match OpenOptions::new().read(true).write(true).append(true).open(&file_path) { + Ok(mut f) => { + println!("Opened file..."); + + let mut s = String::new(); + try!(f.read_to_string(&mut s)); + + let contains_uses = &s[..].contains("use"); + + (f, !contains_uses) + }, + Err(_) => { + println!("Creating file..."); + (try!(File::create(&file_path)), true) + } + }; + + //4. Emit file header for new files or those without uses + if is_new { + println!("emitting header for {}...", endpoint.get_name()); + + try!(emitter.emit("e_stmt!(&mut cx, use hyper::client::Client;), &cx, &mut src_file)); + try!(emitter.emit_str(&"\n", &mut src_file)); + + try!(emitter.emit("e_stmt!(&mut cx, + #[allow(unused_imports)] + use hyper::client::Body; + ), &cx, &mut src_file)); + try!(emitter.emit_str(&"\n", &mut src_file)); + + try!(emitter.emit("e_stmt!(&mut cx, use hyper::client::response::Response;), &cx, &mut src_file)); + try!(emitter.emit_str(&"\n", &mut src_file)); + + try!(emitter.emit("e_stmt!(&mut cx, use hyper::error::Result;), &cx, &mut src_file)); + try!(emitter.emit_str(&"\n\n", &mut src_file)); + + try!(emitter.emit("e_stmt!(&mut cx, use ::RequestParams;), &cx, &mut src_file)); + try!(emitter.emit_str(&"\n\n", &mut src_file)); + + try!(src_file.sync_all()); + } + + //5. Generate and emit source functions + let fun_sigs = try!(endpoint.get_fns()); + let mut fun_sigs_distinct = HashMap::with_capacity(fun_sigs.len()); + for fun in fun_sigs { + fun_sigs_distinct.insert(fun.name.clone(), fun); + } + + for (_, fun) in fun_sigs_distinct { + println!("emitting fn {}", &fun.name); + + //The base url argument + let client = "client"; + let generic = "I"; + + let req = token::str_to_ident("req"); + let base = token::str_to_ident("base"); + let body = token::str_to_ident("body"); + let qry = token::str_to_ident("url_qry"); + + let lifetime = lifetime("'a"); + + let mut params: Vec = parse_path_params(&fun.path) + .unwrap().iter() + .map(|p| token::str_to_ident(match p.as_str() { + "type" => "_type", + s => s + })) + .collect(); + + //Add the query string param so it's included when building full url + params.push(qry); + + let parts = parse_path_parts(&fun.path).unwrap(); + + //Get the push statements + let (url_ident, url_stmts) = url_push_decl(base, parts.iter().map(|p| p.as_str()), params.to_vec()); + + //Remove the query string param so it's not included in fn signature + let _ = params.pop(); + + //Function signature from params + let mut rs_fun = build_fn(&fun.name, vec![ + build_arg(client, build_ty_ptr("Client", Mutability::Mutable, Some(lifetime))), + build_arg_ident(req, build_ty_ptr("RequestParams", Mutability::Immutable, Some(lifetime))) + ]) + .add_args(params + .iter() + .map(|p: &Ident| build_arg_ident(p.clone(), build_ty_ptr("str", Mutability::Immutable, Some(lifetime)))) + ) + .add_lifetime(lifetime) + .set_return_ty(build_ty("Result")) + .add_body_stmts(vec![ + quote_stmt!(&mut cx, let $qry = &$req.get_url_qry();).unwrap(), + quote_stmt!(&mut cx, let $base = &$req.base_url;).unwrap() + ]) + .add_body_stmts(url_stmts); + + match *fun.method { + HttpVerb::Head => { + rs_fun = block(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.head", client)), + url_ident, req + ); + }, + HttpVerb::Get => { + rs_fun = block(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.get", client)), + url_ident, req + ); + }, + HttpVerb::Delete => { + rs_fun = block(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.delete", client)), + url_ident, req + ); + }, + HttpVerb::Post => { + rs_fun = block_with_body(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.post", client)), + url_ident, req, generic, body + ); + }, + HttpVerb::Put => { + rs_fun = block_with_body(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.put", client)), + url_ident, req, generic, body + ); + }, + HttpVerb::Patch => { + rs_fun = block_with_body(rs_fun, &mut cx, + token::str_to_ident(&format!("{}.patch", client)), + url_ident, req, generic, body + ); + } + }; + + try!(emitter.emit_str(&format!("/// {}\n", endpoint.documentation), &mut src_file)); + try!(emitter.emit(&rs_fun, &cx, &mut src_file)); + try!(emitter.emit_str(&"\n", &mut src_file)); + try!(src_file.sync_all()); + try!(emitter.emit_str(&"\n", &mut src_file)); + } + + //6. Emit mod header if file isn't mod + if !file_is_mod { + let mod_path = format!("{}/{}.rs", dir_path, "mod"); + let mut mod_file = match OpenOptions::new().write(true).append(true).open(&mod_path) { + Ok(f) => f, + Err(_) => File::create(&mod_path).unwrap() + }; + + try!(emitter.emit_str(&format!("pub mod {};\n", file), &mut mod_file)); + try!(mod_file.sync_all()); + } + } + + //7. Build up the mod structure + let mut mod_paths = Vec::new(); + for entry in WalkDir::new(dest_dir).min_depth(1).max_open(1).into_iter().filter_map(|e| e.ok()) { + let meta = entry.metadata().unwrap(); + if meta.is_dir() { + if let Some(parent) = entry.path().parent() { + let name = entry.file_name(); + + mod_paths.push(( + (format!("{}/{}.rs", parent.to_str().unwrap().to_string(), "mod")), + name.to_str().unwrap().to_string() + )); + } + } + } + + for (path, name) in mod_paths { + let mut mod_file = match OpenOptions::new().write(true).append(true).open(&path) { + Ok(f) => f, + Err(_) => File::create(&path).unwrap() + }; + + try!(emitter.emit_str(&format!("pub mod {};\n", name), &mut mod_file)); + try!(mod_file.sync_all()); + } + + Ok(()) +} + +fn block(rs_fun: Fn, cx: &mut ExtCtxt, call: Ident, url_ident: Ident, req: Ident) -> Fn { + rs_fun + .add_body_stmts(vec![ + quote_stmt!(cx, let res = $call(&$url_ident).headers($req.headers.to_owned());).unwrap(), + quote_stmt!(cx, res.send()).unwrap() + ]) +} + +fn block_with_body(rs_fun: Fn, cx: &mut ExtCtxt, call: Ident, url_ident: Ident, req: Ident, generic: &str, body: Ident) -> Fn { + rs_fun + .set_generic_params(vec![ + build_ty_param(generic, vec![ + "Into>" + ]) + ]) + .add_arg(build_arg_ident(body, build_ty(generic))) + .add_body_stmts(vec![ + quote_stmt!(cx, let res = $call(&$url_ident).headers($req.headers.to_owned()).body($body.into());).unwrap(), + quote_stmt!(cx, res.send()).unwrap() + ]) +} diff --git a/elastic_hyper.rsproj b/elastic_hyper.rsproj new file mode 100644 index 000000000..3c80c65f3 --- /dev/null +++ b/elastic_hyper.rsproj @@ -0,0 +1,39 @@ + + + + Debug + default + {e7571d90-a65d-43a6-acf7-52d62fccf1c9} + library + elastic_hyper + elastic_hyper + elastic_hyper + + + false + true + 0 + default + + + false + false + 2 + default + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 000000000..fddd6c9f3 --- /dev/null +++ b/samples/README.md @@ -0,0 +1,3 @@ +# `elastic_hyper` samples + +This repo contains a few samples for the `elastic_hyper` crate. diff --git a/samples/basic/.gitignore b/samples/basic/.gitignore new file mode 100644 index 000000000..ab22063e1 --- /dev/null +++ b/samples/basic/.gitignore @@ -0,0 +1,2 @@ +/target/ +/obj/ \ No newline at end of file diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml new file mode 100644 index 000000000..4d32086ac --- /dev/null +++ b/samples/basic/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "elastic_hyper_samples" +version = "0.1.0" +authors = ["Ashley Mannix "] + +[features] +nightly-testing = [] + +[dependencies] +elastic_hyper = "~0.3.0" +json_str = "*" +hyper = "~0.9.0" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs new file mode 100644 index 000000000..8ab5df07e --- /dev/null +++ b/samples/basic/src/main.rs @@ -0,0 +1,43 @@ +//! Elasticsearch Hyper Client Samples +//! +//! This sample assumes you have a node running on `localhost`. +//! +//! This minimal sample executes a simple search request against all indices. +//! To make things readable, the `pretty` url param is provided. + +#[macro_use] +extern crate json_str; +extern crate hyper; +extern crate elastic_hyper as elastic; + +use hyper::client::Client; +use std::io::Read; + +fn main() { + //Create a hyper client. + //We specify `pretty` on requests to make them more readable. + let mut client = Client::new(); + let params = elastic::RequestParams::default() + .url_params(vec![ + ("pretty", "true".to_owned()) + ]); + + //Execute a HTTP Post search request. + //Other variants include post_index, post_index_type. + let mut res = elastic::search::post( + &mut client, ¶ms, + &json_str!({ + query: { + query_string: { + query: "*" + } + } + }) + ).unwrap(); + + //Deserialisation goes here. + let mut message = String::new(); + let _ = res.read_to_string(&mut message); + + println!("Got response: {}", message); +} diff --git a/samples/typed/.gitignore b/samples/typed/.gitignore new file mode 100644 index 000000000..ab22063e1 --- /dev/null +++ b/samples/typed/.gitignore @@ -0,0 +1,2 @@ +/target/ +/obj/ \ No newline at end of file diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml new file mode 100644 index 000000000..fe0744408 --- /dev/null +++ b/samples/typed/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "elastic_hyper_samples" +version = "0.1.0" +authors = ["Ashley Mannix "] + +[features] +nightly-testing = [] + +[dependencies] +elastic_hyper = { version = "*", path = "../../" } +json_str = { version = "*", features = ["nightly"]} +hyper = "~0.9.0" +elastic_types = { version = "*", path = "../../../types", features = ["nightly"]} +elastic_types_macros = { version = "*", path = "../../../macros/types" } +serde = "~0.8.0" +serde_macros = "~0.8.0" +serde_json = "~0.8.0" diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs new file mode 100644 index 000000000..dc7ff3f30 --- /dev/null +++ b/samples/typed/src/main.rs @@ -0,0 +1,130 @@ +//! Elasticsearch Hyper Client Samples +//! +//! This sample assumes you have a node running on `localhost`. +//! +//! This sample executes a simple search request against some indexed data. +//! The data is provided by a struct with mapping generated by `elastic_types`. + +#![feature(plugin, custom_derive)] +#![plugin(serde_macros, elastic_types_macros, json_str)] + +extern crate serde; +extern crate serde_json; +#[macro_use] +extern crate elastic_types; +extern crate hyper; +extern crate elastic_hyper as elastic; + +use std::net::Ipv4Addr; +use std::{ thread, time }; +use hyper::Client; +use elastic::RequestParams; +use elastic_types::prelude::*; + +mod response; +use response::*; + +//The type we want to index in Elasticsearch +#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] +pub struct MyStruct { + pub id: i32, + pub title: String, + pub timestamp: Date, + pub geo: GeoLocation +} + +#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] +pub struct GeoLocation { + pub ip: Ipv4Addr, + pub loc: GeoPoint +} + +const INDEX: &'static str = "testidx"; + +fn main() { + //Create a hyper client + let (mut client, params) = elastic::default(); + + //Create an index and map our type + create_index(&mut client, ¶ms); + + //Index some objects. For lots of data, prefer the `bulk` mod + for t in get_data() { + index_datum(&mut client, ¶ms, &t); + } + + //NOTE: Elasticsearch is _near_ realtime, so results aren't guaranteed to show up right away + thread::sleep(time::Duration::from_secs(2)); + + //Perform a search request and deserialise to `SearchResponse` + let res = query(&mut client, ¶ms); + + println!("results: {}", res.hits.total); + for hit in res.hits.hits { + if let Some(hit) = hit.source { + println!("hit: {:?}", hit); + } + } +} + +fn create_index(client: &mut Client, params: &RequestParams) { + //Create index + let _ = elastic::indices::create::put_index(client, ¶ms, INDEX, "").unwrap(); + + //Put mapping for MyStruct + let _ = elastic::indices::put_mapping::put_index_type(client, ¶ms, + //Index and type + INDEX, MyStruct::name(), + //Serialised mapping + &TypeMapper::to_string(MyStruct::mapping()).unwrap() + ).unwrap(); +} + +fn get_data() -> Vec { + vec![ + MyStruct { + id: 1, + title: String::from("Some Title"), + timestamp: Date::now(), + geo: GeoLocation { + ip: Ipv4Addr::new(10, 0, 0, 1), + loc: GeoPoint::build(-71.34, 41.12) + } + }, + MyStruct { + id: 2, + title: String::from("Some Other Title"), + timestamp: Date::now(), + geo: GeoLocation { + ip: Ipv4Addr::new(10, 0, 0, 2), + loc: GeoPoint::build(-71.34, 41.12) + } + } + ] +} + +fn index_datum(client: &mut Client, params: &RequestParams, datum: &MyStruct) { + let _ = elastic::index::put_index_type_id(client, ¶ms, + //Index, type and id + INDEX, MyStruct::name(), &datum.id.to_string(), + //Serialised data + &serde_json::to_string(&datum).unwrap() + ).unwrap(); +} + +fn query(client: &mut Client, params: &RequestParams) -> SearchResponse { + serde_json::de::from_reader( + elastic::search::post_index_type(client, ¶ms, + //Index and type + INDEX, MyStruct::name(), + //Query + json_lit!({ + query: { + query_string: { + query: "*" + } + } + }) + ).unwrap() + ).unwrap() +} diff --git a/samples/typed/src/response.rs b/samples/typed/src/response.rs new file mode 100644 index 000000000..e904020ef --- /dev/null +++ b/samples/typed/src/response.rs @@ -0,0 +1,66 @@ +//NOTE: This module lives here until we have a proper crate for Elasticsearch responses + +use serde::Deserialize; + +/// A successful response from a Query DSL query. +#[derive(Debug, Deserialize)] +pub struct SearchResponse where +T: Deserialize { + /// The time taken to complete a query in ms. + pub took: u64, + /// Whether or not the query timed out. + pub timed_out: bool, + /// Metadata on shard activity. + #[serde(rename="_shards")] + pub shards: Shards, + /// Document results. + pub hits: SearchHits +} + +/// Metadata on shard activity for a Query DSL query. +#[derive(Debug, Deserialize)] +pub struct Shards { + /// The total number of shards involved in this query. + pub total: u64, + /// The total number of shards that successfully executed the query. + pub successful: u64, + /// The total number of shards that failed to execute the query. + pub failed: u64 +} + +/// A collection of hits for a Query DSL query. +#[derive(Debug, Deserialize)] +pub struct SearchHits where +T: Deserialize { + /// The total number of hits. + pub total: u64, + /// Document results. + pub hits: Vec> +} + +/// An individual hit for a Query DSL query. +#[derive(Debug, Deserialize)] +pub struct Hit where +T: Deserialize { + /// The index of the hit. + #[serde(rename="_index")] + pub index: String, + /// The type of the hit. + #[serde(rename="_type")] + pub doc_type: String, + /// The id of the hit. + #[serde(rename="_id")] + pub id: String, + /// The relevance score of the hit. + #[serde(rename="_score")] + pub score: Option, + /// The source document data. + #[serde(rename="_source")] + pub source: Option, + /// The index timestamp of the hit. + #[serde(rename="_timestamp")] + pub timestamp: Option, + /// The routing value of the hit. + #[serde(rename="_routing")] + pub routing: Option +} \ No newline at end of file diff --git a/src/api/bulk/mod.rs b/src/api/bulk/mod.rs new file mode 100644 index 000000000..cbeb8c5fb --- /dev/null +++ b/src/api/bulk/mod.rs @@ -0,0 +1,124 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn put<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn put_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 6 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html +pub fn put_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 6 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_bulk"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/cat/aliases.rs b/src/api/cat/aliases.rs new file mode 100644 index 000000000..9c0b42db8 --- /dev/null +++ b/src/api/cat/aliases.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/aliases"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html +pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 14 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/aliases/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/allocation.rs b/src/api/cat/allocation.rs new file mode 100644 index 000000000..c4ae45237 --- /dev/null +++ b/src/api/cat/allocation.rs @@ -0,0 +1,36 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/allocation"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html +pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 17 + node_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/allocation/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/count.rs b/src/api/cat/count.rs new file mode 100644 index 000000000..ac435f9f1 --- /dev/null +++ b/src/api/cat/count.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 12 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/count/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/fielddata.rs b/src/api/cat/fielddata.rs new file mode 100644 index 000000000..4bca96031 --- /dev/null +++ b/src/api/cat/fielddata.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/fielddata"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html +pub fn get_fields<'a>(client: &'a mut Client, req: &'a RequestParams, + fields: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + fields.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/fielddata/"); + url_fmtd.push_str(fields); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/health.rs b/src/api/cat/health.rs new file mode 100644 index 000000000..f850fdce2 --- /dev/null +++ b/src/api/cat/health.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/health"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/help.rs b/src/api/cat/help.rs new file mode 100644 index 000000000..ba0529af0 --- /dev/null +++ b/src/api/cat/help.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 5 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/indices.rs b/src/api/cat/indices.rs new file mode 100644 index 000000000..bc47fea23 --- /dev/null +++ b/src/api/cat/indices.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/indices"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 14 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/indices/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/master.rs b/src/api/cat/master.rs new file mode 100644 index 000000000..f9939a795 --- /dev/null +++ b/src/api/cat/master.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/master"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/mod.rs b/src/api/cat/mod.rs new file mode 100644 index 000000000..4ebdf3637 --- /dev/null +++ b/src/api/cat/mod.rs @@ -0,0 +1,19 @@ +pub mod thread_pool; +pub mod repositories; +pub mod nodeattrs; +pub mod allocation; +pub mod help; +pub mod aliases; +pub mod pending_tasks; +pub mod shards; +pub mod segments; +pub mod recovery; +pub mod health; +pub mod count; +pub mod snapshots; +pub mod nodes; +pub mod indices; +pub mod plugins; +pub mod tasks; +pub mod fielddata; +pub mod master; diff --git a/src/api/cat/nodeattrs.rs b/src/api/cat/nodeattrs.rs new file mode 100644 index 000000000..14e40652e --- /dev/null +++ b/src/api/cat/nodeattrs.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/nodeattrs"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/nodes.rs b/src/api/cat/nodes.rs new file mode 100644 index 000000000..be5970968 --- /dev/null +++ b/src/api/cat/nodes.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/nodes"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/pending_tasks.rs b/src/api/cat/pending_tasks.rs new file mode 100644 index 000000000..8726c3bce --- /dev/null +++ b/src/api/cat/pending_tasks.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 19 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/pending_tasks"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/plugins.rs b/src/api/cat/plugins.rs new file mode 100644 index 000000000..63cdb9fca --- /dev/null +++ b/src/api/cat/plugins.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/plugins"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/recovery.rs b/src/api/cat/recovery.rs new file mode 100644 index 000000000..ae0216586 --- /dev/null +++ b/src/api/cat/recovery.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/recovery"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 15 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/recovery/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/repositories.rs b/src/api/cat/repositories.rs new file mode 100644 index 000000000..5ef749f0a --- /dev/null +++ b/src/api/cat/repositories.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/repositories"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/segments.rs b/src/api/cat/segments.rs new file mode 100644 index 000000000..7fbdb4090 --- /dev/null +++ b/src/api/cat/segments.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/segments"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 15 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/segments/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/shards.rs b/src/api/cat/shards.rs new file mode 100644 index 000000000..cbd506d82 --- /dev/null +++ b/src/api/cat/shards.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/shards"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 13 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/shards/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/snapshots.rs b/src/api/cat/snapshots.rs new file mode 100644 index 000000000..c8c9027cc --- /dev/null +++ b/src/api/cat/snapshots.rs @@ -0,0 +1,24 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html +pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/snapshots/"); + url_fmtd.push_str(repository); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/tasks.rs b/src/api/cat/tasks.rs new file mode 100644 index 000000000..91050eadc --- /dev/null +++ b/src/api/cat/tasks.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/tasks"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cat/thread_pool.rs b/src/api/cat/thread_pool.rs new file mode 100644 index 000000000..86e4f2dd3 --- /dev/null +++ b/src/api/cat/thread_pool.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cat/thread_pool"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/clear_scroll/mod.rs b/src/api/clear_scroll/mod.rs new file mode 100644 index 000000000..2cd7a44bb --- /dev/null +++ b/src/api/clear_scroll/mod.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn delete<'a>(client: &'a mut Client, req: &'a RequestParams) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll"); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn delete_scroll_id<'a>(client: &'a mut Client, req: &'a RequestParams, + scroll_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + scroll_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll/"); + url_fmtd.push_str(scroll_id); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cluster/allocation_explain.rs b/src/api/cluster/allocation_explain.rs new file mode 100644 index 000000000..8e2dc5431 --- /dev/null +++ b/src/api/cluster/allocation_explain.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 28 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/allocation/explain"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 28 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/allocation/explain"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/cluster/get_settings.rs b/src/api/cluster/get_settings.rs new file mode 100644 index 000000000..f9b416eb2 --- /dev/null +++ b/src/api/cluster/get_settings.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/settings"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cluster/health.rs b/src/api/cluster/health.rs new file mode 100644 index 000000000..a44a1fdae --- /dev/null +++ b/src/api/cluster/health.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/health"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 17 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/health/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cluster/mod.rs b/src/api/cluster/mod.rs new file mode 100644 index 000000000..c8f023df7 --- /dev/null +++ b/src/api/cluster/mod.rs @@ -0,0 +1,8 @@ +pub mod allocation_explain; +pub mod state; +pub mod health; +pub mod pending_tasks; +pub mod stats; +pub mod reroute; +pub mod put_settings; +pub mod get_settings; diff --git a/src/api/cluster/pending_tasks.rs b/src/api/cluster/pending_tasks.rs new file mode 100644 index 000000000..b85c597bb --- /dev/null +++ b/src/api/cluster/pending_tasks.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 23 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/pending_tasks"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cluster/put_settings.rs b/src/api/cluster/put_settings.rs new file mode 100644 index 000000000..775ad7db3 --- /dev/null +++ b/src/api/cluster/put_settings.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html +pub fn put<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/settings"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/cluster/reroute.rs b/src/api/cluster/reroute.rs new file mode 100644 index 000000000..f0263ade5 --- /dev/null +++ b/src/api/cluster/reroute.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/reroute"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/cluster/state.rs b/src/api/cluster/state.rs new file mode 100644 index 000000000..a39dadfab --- /dev/null +++ b/src/api/cluster/state.rs @@ -0,0 +1,53 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html +pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/state/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html +pub fn get_metric_index<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str, index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + 1 + metric.len() + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/state/"); + url_fmtd.push_str(metric); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/state"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/cluster/stats.rs b/src/api/cluster/stats.rs new file mode 100644 index 000000000..002dbf5ce --- /dev/null +++ b/src/api/cluster/stats.rs @@ -0,0 +1,36 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html +pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 22 + node_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cluster/stats/nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/count/mod.rs b/src/api/count/mod.rs new file mode 100644 index 000000000..1d22f3c5b --- /dev/null +++ b/src/api/count/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 7 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 7 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/count_percolate/mod.rs b/src/api/count_percolate/mod.rs new file mode 100644 index 000000000..63e790b33 --- /dev/null +++ b/src/api/count_percolate/mod.rs @@ -0,0 +1,98 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 17 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_percolate/count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_percolate/count"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 17 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_percolate/count"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_percolate/count"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/delete/mod.rs b/src/api/delete/mod.rs new file mode 100644 index 000000000..2d9c9e39e --- /dev/null +++ b/src/api/delete/mod.rs @@ -0,0 +1,29 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html +pub fn delete_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/delete_by_query/mod.rs b/src/api/delete_by_query/mod.rs new file mode 100644 index 000000000..5055897a9 --- /dev/null +++ b/src/api/delete_by_query/mod.rs @@ -0,0 +1,51 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_delete_by_query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 17 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_delete_by_query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/delete_script/mod.rs b/src/api/delete_script/mod.rs new file mode 100644 index 000000000..30d4f1612 --- /dev/null +++ b/src/api/delete_script/mod.rs @@ -0,0 +1,26 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html +pub fn delete_lang_id<'a>(client: &'a mut Client, req: &'a RequestParams, + lang: &'a str, id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_scripts/"); + url_fmtd.push_str(lang); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/delete_template/mod.rs b/src/api/delete_template/mod.rs new file mode 100644 index 000000000..fa479ebea --- /dev/null +++ b/src/api/delete_template/mod.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html +pub fn delete_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/exists/mod.rs b/src/api/exists/mod.rs new file mode 100644 index 000000000..4fc58e907 --- /dev/null +++ b/src/api/exists/mod.rs @@ -0,0 +1,29 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html +pub fn head_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/explain/mod.rs b/src/api/explain/mod.rs new file mode 100644 index 000000000..a8d7a2831 --- /dev/null +++ b/src/api/explain/mod.rs @@ -0,0 +1,56 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 9 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_explain"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 9 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_explain"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/field_stats/mod.rs b/src/api/field_stats/mod.rs new file mode 100644 index 000000000..d6f760766 --- /dev/null +++ b/src/api/field_stats/mod.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_field_stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 13 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_field_stats"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_field_stats"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 13 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_field_stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/get/mod.rs b/src/api/get/mod.rs new file mode 100644 index 000000000..d4e840cd7 --- /dev/null +++ b/src/api/get/mod.rs @@ -0,0 +1,29 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/get_script/mod.rs b/src/api/get_script/mod.rs new file mode 100644 index 000000000..6f21142e6 --- /dev/null +++ b/src/api/get_script/mod.rs @@ -0,0 +1,26 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html +pub fn get_lang_id<'a>(client: &'a mut Client, req: &'a RequestParams, + lang: &'a str, id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_scripts/"); + url_fmtd.push_str(lang); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/get_source/mod.rs b/src/api/get_source/mod.rs new file mode 100644 index 000000000..e06932d39 --- /dev/null +++ b/src/api/get_source/mod.rs @@ -0,0 +1,30 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 8 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_source"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/get_template/mod.rs b/src/api/get_template/mod.rs new file mode 100644 index 000000000..26dc955e0 --- /dev/null +++ b/src/api/get_template/mod.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html +pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/index/mod.rs b/src/api/index/mod.rs new file mode 100644 index 000000000..e00e943cd --- /dev/null +++ b/src/api/index/mod.rs @@ -0,0 +1,102 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html +pub fn put_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html +pub fn put_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/analyze.rs b/src/api/indices/analyze.rs new file mode 100644 index 000000000..91b45def8 --- /dev/null +++ b/src/api/indices/analyze.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_analyze"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_analyze"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_analyze"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_analyze"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/clear_cache.rs b/src/api/indices/clear_cache.rs new file mode 100644 index 000000000..b90bcddb0 --- /dev/null +++ b/src/api/indices/clear_cache.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cache/clear"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 13 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_cache/clear"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_cache/clear"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 13 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_cache/clear"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/close.rs b/src/api/indices/close.rs new file mode 100644 index 000000000..ff81a3593 --- /dev/null +++ b/src/api/indices/close.rs @@ -0,0 +1,28 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_close"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/create.rs b/src/api/indices/create.rs new file mode 100644 index 000000000..106e360b6 --- /dev/null +++ b/src/api/indices/create.rs @@ -0,0 +1,44 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html +pub fn put_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/delete.rs b/src/api/indices/delete.rs new file mode 100644 index 000000000..52651b776 --- /dev/null +++ b/src/api/indices/delete.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html +pub fn delete_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/delete_alias.rs b/src/api/indices/delete_alias.rs new file mode 100644 index 000000000..74a747015 --- /dev/null +++ b/src/api/indices/delete_alias.rs @@ -0,0 +1,26 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn delete_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_aliases/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/delete_template.rs b/src/api/indices/delete_template.rs new file mode 100644 index 000000000..68a4ae138 --- /dev/null +++ b/src/api/indices/delete_template.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn delete_name<'a>(client: &'a mut Client, req: &'a RequestParams, + name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/exists.rs b/src/api/indices/exists.rs new file mode 100644 index 000000000..319abe10c --- /dev/null +++ b/src/api/indices/exists.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html +pub fn head_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/exists_alias.rs b/src/api/indices/exists_alias.rs new file mode 100644 index 000000000..ae8ec37a2 --- /dev/null +++ b/src/api/indices/exists_alias.rs @@ -0,0 +1,58 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn head_name<'a>(client: &'a mut Client, req: &'a RequestParams, + name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_alias/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn head_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 8 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_alias/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn head_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_alias"); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/exists_template.rs b/src/api/indices/exists_template.rs new file mode 100644 index 000000000..f8ecb3917 --- /dev/null +++ b/src/api/indices/exists_template.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn head_name<'a>(client: &'a mut Client, req: &'a RequestParams, + name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/exists_type.rs b/src/api/indices/exists_type.rs new file mode 100644 index 000000000..fb3da81d7 --- /dev/null +++ b/src/api/indices/exists_type.rs @@ -0,0 +1,26 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html +pub fn head_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/flush.rs b/src/api/indices/flush.rs new file mode 100644 index 000000000..61ef173f9 --- /dev/null +++ b/src/api/indices/flush.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_flush"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_flush"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_flush"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_flush"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/flush_synced.rs b/src/api/indices/flush_synced.rs new file mode 100644 index 000000000..bba4bfc20 --- /dev/null +++ b/src/api/indices/flush_synced.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_flush/synced"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 14 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_flush/synced"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_flush/synced"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 14 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_flush/synced"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/forcemerge.rs b/src/api/indices/forcemerge.rs new file mode 100644 index 000000000..b7e3f51b5 --- /dev/null +++ b/src/api/indices/forcemerge.rs @@ -0,0 +1,43 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 12 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_forcemerge"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_forcemerge"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/get.rs b/src/api/indices/get.rs new file mode 100644 index 000000000..0c6a85f39 --- /dev/null +++ b/src/api/indices/get.rs @@ -0,0 +1,41 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html +pub fn get_index_feature<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, feature: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + index.len() + feature.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(feature); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_alias.rs b/src/api/indices/get_alias.rs new file mode 100644 index 000000000..8d5551bc0 --- /dev/null +++ b/src/api/indices/get_alias.rs @@ -0,0 +1,70 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn get_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 8 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_alias/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_alias"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_alias/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_alias"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_field_mapping.rs b/src/api/indices/get_field_mapping.rs new file mode 100644 index 000000000..944d6ded2 --- /dev/null +++ b/src/api/indices/get_field_mapping.rs @@ -0,0 +1,80 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html +pub fn get_index_type_fields<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, fields: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + 7 + index.len() + + _type.len() + fields.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mapping/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/field/"); + url_fmtd.push_str(fields); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html +pub fn get_index_fields<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, fields: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 16 + index.len() + fields.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mapping/field/"); + url_fmtd.push_str(fields); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html +pub fn get_fields<'a>(client: &'a mut Client, req: &'a RequestParams, + fields: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + fields.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mapping/field/"); + url_fmtd.push_str(fields); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html +pub fn get_type_fields<'a>(client: &'a mut Client, req: &'a RequestParams, + _type: &'a str, fields: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + 7 + _type.len() + fields.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mapping/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/field/"); + url_fmtd.push_str(fields); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_mapping.rs b/src/api/indices/get_mapping.rs new file mode 100644 index 000000000..96039ba2d --- /dev/null +++ b/src/api/indices/get_mapping.rs @@ -0,0 +1,70 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mapping"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mapping/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html +pub fn get_type<'a>(client: &'a mut Client, req: &'a RequestParams, + _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mapping/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mapping"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_settings.rs b/src/api/indices/get_settings.rs new file mode 100644 index 000000000..d5be5f0fe --- /dev/null +++ b/src/api/indices/get_settings.rs @@ -0,0 +1,70 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html +pub fn get_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, name: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 11 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_settings/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_settings"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html +pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_settings/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_settings"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_template.rs b/src/api/indices/get_template.rs new file mode 100644 index 000000000..09f436624 --- /dev/null +++ b/src/api/indices/get_template.rs @@ -0,0 +1,35 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/get_upgrade.rs b/src/api/indices/get_upgrade.rs new file mode 100644 index 000000000..6d31aff66 --- /dev/null +++ b/src/api/indices/get_upgrade.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_upgrade"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_upgrade"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/mod.rs b/src/api/indices/mod.rs new file mode 100644 index 000000000..e97e9a366 --- /dev/null +++ b/src/api/indices/mod.rs @@ -0,0 +1,36 @@ +pub mod close; +pub mod get_settings; +pub mod put_template; +pub mod get_template; +pub mod stats; +pub mod forcemerge; +pub mod exists; +pub mod flush_synced; +pub mod delete; +pub mod create; +pub mod flush; +pub mod refresh; +pub mod exists_alias; +pub mod get_field_mapping; +pub mod get_alias; +pub mod recovery; +pub mod clear_cache; +pub mod put_mapping; +pub mod validate_query; +pub mod shard_stores; +pub mod update_aliases; +pub mod open; +pub mod get_mapping; +pub mod exists_template; +pub mod get_upgrade; +pub mod delete_template; +pub mod put_settings; +pub mod put_alias; +pub mod upgrade; +pub mod delete_alias; +pub mod rollover; +pub mod get; +pub mod analyze; +pub mod segments; +pub mod shrink; +pub mod exists_type; diff --git a/src/api/indices/open.rs b/src/api/indices/open.rs new file mode 100644 index 000000000..92dca5717 --- /dev/null +++ b/src/api/indices/open.rs @@ -0,0 +1,28 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 6 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_open"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/put_alias.rs b/src/api/indices/put_alias.rs new file mode 100644 index 000000000..bdfdd14b2 --- /dev/null +++ b/src/api/indices/put_alias.rs @@ -0,0 +1,52 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn post_index_name<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + name: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_aliases/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn put_index_name<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + name: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_aliases/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/put_mapping.rs b/src/api/indices/put_mapping.rs new file mode 100644 index 000000000..b9d65492d --- /dev/null +++ b/src/api/indices/put_mapping.rs @@ -0,0 +1,87 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 11 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mappings/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html +pub fn put_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 11 + index.len() + _type.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mappings/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html +pub fn post_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, _type: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mappings/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html +pub fn put_type<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + _type: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mappings/"); + url_fmtd.push_str(_type); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/put_settings.rs b/src/api/indices/put_settings.rs new file mode 100644 index 000000000..f110cbebd --- /dev/null +++ b/src/api/indices/put_settings.rs @@ -0,0 +1,43 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html +pub fn put<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_settings"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html +pub fn put_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_settings"); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/put_template.rs b/src/api/indices/put_template.rs new file mode 100644 index 000000000..534f4ba74 --- /dev/null +++ b/src/api/indices/put_template.rs @@ -0,0 +1,43 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn post_name<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, name: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html +pub fn put_name<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + name: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_template/"); + url_fmtd.push_str(name); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/recovery.rs b/src/api/indices/recovery.rs new file mode 100644 index 000000000..0744b3f22 --- /dev/null +++ b/src/api/indices/recovery.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_recovery"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_recovery"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/refresh.rs b/src/api/indices/refresh.rs new file mode 100644 index 000000000..e5fa06371 --- /dev/null +++ b/src/api/indices/refresh.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_refresh"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_refresh"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_refresh"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_refresh"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/rollover.rs b/src/api/indices/rollover.rs new file mode 100644 index 000000000..e4c0dfe3b --- /dev/null +++ b/src/api/indices/rollover.rs @@ -0,0 +1,50 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html +pub fn post_alias<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, alias: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + alias.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(alias); + url_fmtd.push_str("/_rollover"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html +pub fn post_alias_new_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + alias: &'a str, new_index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 11 + alias.len() + + new_index.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(alias); + url_fmtd.push_str("/_rollover/"); + url_fmtd.push_str(new_index); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/segments.rs b/src/api/indices/segments.rs new file mode 100644 index 000000000..79d2c806b --- /dev/null +++ b/src/api/indices/segments.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_segments"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 10 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_segments"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/shard_stores.rs b/src/api/indices/shard_stores.rs new file mode 100644 index 000000000..22a7cf75d --- /dev/null +++ b/src/api/indices/shard_stores.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_shard_stores"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 14 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_shard_stores"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/shrink.rs b/src/api/indices/shrink.rs new file mode 100644 index 000000000..5adc98817 --- /dev/null +++ b/src/api/indices/shrink.rs @@ -0,0 +1,52 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html +pub fn put_index_target<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + target: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + target.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_shrink/"); + url_fmtd.push_str(target); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html +pub fn post_index_target<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, target: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + target.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_shrink/"); + url_fmtd.push_str(target); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/stats.rs b/src/api/indices/stats.rs new file mode 100644 index 000000000..71b7976cd --- /dev/null +++ b/src/api/indices/stats.rs @@ -0,0 +1,70 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html +pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html +pub fn get_index_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, metric: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 8 + index.len() + metric.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 7 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/indices/update_aliases.rs b/src/api/indices/update_aliases.rs new file mode 100644 index 000000000..8c8cdbc06 --- /dev/null +++ b/src/api/indices/update_aliases.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_aliases"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/upgrade.rs b/src/api/indices/upgrade.rs new file mode 100644 index 000000000..0d322544d --- /dev/null +++ b/src/api/indices/upgrade.rs @@ -0,0 +1,43 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_upgrade"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_upgrade"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/indices/validate_query.rs b/src/api/indices/validate_query.rs new file mode 100644 index 000000000..291d36b71 --- /dev/null +++ b/src/api/indices/validate_query.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 16 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 16 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 16 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 16 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_validate/query"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/info/mod.rs b/src/api/info/mod.rs new file mode 100644 index 000000000..f1713e232 --- /dev/null +++ b/src/api/info/mod.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/ +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 1 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/ingest/delete_pipeline.rs b/src/api/ingest/delete_pipeline.rs new file mode 100644 index 000000000..4064863f8 --- /dev/null +++ b/src/api/ingest/delete_pipeline.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn delete_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/ingest/get_pipeline.rs b/src/api/ingest/get_pipeline.rs new file mode 100644 index 000000000..0a59a0554 --- /dev/null +++ b/src/api/ingest/get_pipeline.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/ingest/mod.rs b/src/api/ingest/mod.rs new file mode 100644 index 000000000..e52407664 --- /dev/null +++ b/src/api/ingest/mod.rs @@ -0,0 +1,4 @@ +pub mod put_pipeline; +pub mod simulate; +pub mod delete_pipeline; +pub mod get_pipeline; diff --git a/src/api/ingest/put_pipeline.rs b/src/api/ingest/put_pipeline.rs new file mode 100644 index 000000000..2982d5022 --- /dev/null +++ b/src/api/ingest/put_pipeline.rs @@ -0,0 +1,25 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn put_id<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/ingest/simulate.rs b/src/api/ingest/simulate.rs new file mode 100644 index 000000000..033d335fd --- /dev/null +++ b/src/api/ingest/simulate.rs @@ -0,0 +1,71 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn post_id<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + 10 + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_simulate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 27 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/_simulate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + 10 + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_simulate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 27 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_ingest/pipeline/_simulate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/mget/mod.rs b/src/api/mget/mod.rs new file mode 100644 index 000000000..05e86528b --- /dev/null +++ b/src/api/mget/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 6 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 6 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mget"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 000000000..e3c0240cb --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1,43 @@ +pub mod index; +pub mod exists; +pub mod tasks; +pub mod ingest; +pub mod clear_scroll; +pub mod termvectors; +pub mod field_stats; +pub mod cat; +pub mod nodes; +pub mod snapshot; +pub mod suggest; +pub mod delete_script; +pub mod msearch_template; +pub mod scroll; +pub mod indices; +pub mod put_template; +pub mod ping; +pub mod update; +pub mod mtermvectors; +pub mod search; +pub mod get_template; +pub mod cluster; +pub mod get_script; +pub mod reindex; +pub mod mget; +pub mod count_percolate; +pub mod render_search_template; +pub mod get; +pub mod delete_template; +pub mod explain; +pub mod count; +pub mod get_source; +pub mod delete; +pub mod percolate; +pub mod info; +pub mod search_template; +pub mod update_by_query; +pub mod search_shards; +pub mod delete_by_query; +pub mod mpercolate; +pub mod put_script; +pub mod bulk; +pub mod msearch; diff --git a/src/api/mpercolate/mod.rs b/src/api/mpercolate/mod.rs new file mode 100644 index 000000000..a856dd606 --- /dev/null +++ b/src/api/mpercolate/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 12 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 12 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 12 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 12 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mpercolate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/msearch/mod.rs b/src/api/msearch/mod.rs new file mode 100644 index 000000000..16c8d2abd --- /dev/null +++ b/src/api/msearch/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 9 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 9 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_msearch"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/msearch_template/mod.rs b/src/api/msearch_template/mod.rs new file mode 100644 index 000000000..a8c58d6e8 --- /dev/null +++ b/src/api/msearch_template/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 18 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 18 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 18 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 18 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_msearch/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/mtermvectors/mod.rs b/src/api/mtermvectors/mod.rs new file mode 100644 index 000000000..cb52a1deb --- /dev/null +++ b/src/api/mtermvectors/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 14 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 14 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 14 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 14 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_mtermvectors"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/nodes/hot_threads.rs b/src/api/nodes/hot_threads.rs new file mode 100644 index 000000000..21986c4cc --- /dev/null +++ b/src/api/nodes/hot_threads.rs @@ -0,0 +1,37 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 19 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/hot_threads"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html +pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 12 + node_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str("/hot_threads"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/nodes/info.rs b/src/api/nodes/info.rs new file mode 100644 index 000000000..c3c5e0665 --- /dev/null +++ b/src/api/nodes/info.rs @@ -0,0 +1,69 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html +pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html +pub fn get_node_id_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str, metric: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 1 + node_id.len() + + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str("/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html +pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + node_id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/nodes/mod.rs b/src/api/nodes/mod.rs new file mode 100644 index 000000000..a94b5634c --- /dev/null +++ b/src/api/nodes/mod.rs @@ -0,0 +1,3 @@ +pub mod hot_threads; +pub mod stats; +pub mod info; diff --git a/src/api/nodes/stats.rs b/src/api/nodes/stats.rs new file mode 100644 index 000000000..44a605cbb --- /dev/null +++ b/src/api/nodes/stats.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get_metric_index_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str, index_metric: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 14 + 1 + metric.len() + + index_metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str("/"); + url_fmtd.push_str(index_metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + metric: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 14 + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get_node_id_metric_index_metric<'a>(client: &'a mut Client, + req: &'a RequestParams, + node_id: &'a str, metric: &'a str, + index_metric: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 7 + 1 + node_id.len() + + metric.len() + index_metric.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str("/stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str("/"); + url_fmtd.push_str(index_metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get_node_id_metric<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str, metric: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 7 + node_id.len() + + metric.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str("/stats/"); + url_fmtd.push_str(metric); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html +pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, + node_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 6 + node_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_nodes/"); + url_fmtd.push_str(node_id); + url_fmtd.push_str("/stats"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/percolate/mod.rs b/src/api/percolate/mod.rs new file mode 100644 index 000000000..ceaff6cec --- /dev/null +++ b/src/api/percolate/mod.rs @@ -0,0 +1,98 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 11 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_percolate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 11 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_percolate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 11 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_percolate"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 11 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_percolate"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/ping/mod.rs b/src/api/ping/mod.rs new file mode 100644 index 000000000..508a28f41 --- /dev/null +++ b/src/api/ping/mod.rs @@ -0,0 +1,21 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/ +pub fn head<'a>(client: &'a mut Client, req: &'a RequestParams) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 1 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(url_qry); + let res = client.head(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/put_script/mod.rs b/src/api/put_script/mod.rs new file mode 100644 index 000000000..ec0883cdd --- /dev/null +++ b/src/api/put_script/mod.rs @@ -0,0 +1,50 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html +pub fn put_lang_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, lang: &'a str, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_scripts/"); + url_fmtd.push_str(lang); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html +pub fn post_lang_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, lang: &'a str, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_scripts/"); + url_fmtd.push_str(lang); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/put_template/mod.rs b/src/api/put_template/mod.rs new file mode 100644 index 000000000..8ed261579 --- /dev/null +++ b/src/api/put_template/mod.rs @@ -0,0 +1,42 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html +pub fn put_id<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html +pub fn post_id<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/reindex/mod.rs b/src/api/reindex/mod.rs new file mode 100644 index 000000000..d04e7ce7c --- /dev/null +++ b/src/api/reindex/mod.rs @@ -0,0 +1,24 @@ +pub mod rethrottle; +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_reindex"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/reindex/rethrottle.rs b/src/api/reindex/rethrottle.rs new file mode 100644 index 000000000..513225776 --- /dev/null +++ b/src/api/reindex/rethrottle.rs @@ -0,0 +1,28 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html +pub fn post_task_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, task_id: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + 12 + task_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_delete_by_query/"); + url_fmtd.push_str(task_id); + url_fmtd.push_str("/_rethrottle"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/render_search_template/mod.rs b/src/api/render_search_template/mod.rs new file mode 100644 index 000000000..0a6040bd4 --- /dev/null +++ b/src/api/render_search_template/mod.rs @@ -0,0 +1,67 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html +pub fn post_id<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + id: &'a str, body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_render/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_render/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html +pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_render/template/"); + url_fmtd.push_str(id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_render/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/scroll/mod.rs b/src/api/scroll/mod.rs new file mode 100644 index 000000000..682132342 --- /dev/null +++ b/src/api/scroll/mod.rs @@ -0,0 +1,71 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn get_scroll_id<'a>(client: &'a mut Client, req: &'a RequestParams, + scroll_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + scroll_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll/"); + url_fmtd.push_str(scroll_id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn post_scroll_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + scroll_id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 16 + scroll_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll/"); + url_fmtd.push_str(scroll_id); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/scroll"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/search/mod.rs b/src/api/search/mod.rs new file mode 100644 index 000000000..302cc85d0 --- /dev/null +++ b/src/api/search/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 8 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 8 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 8 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 8 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 8 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 8 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/search_shards/mod.rs b/src/api/search_shards/mod.rs new file mode 100644 index 000000000..138f8a776 --- /dev/null +++ b/src/api/search_shards/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 15 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 15 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 15 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 15 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search_shards"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/search_template/mod.rs b/src/api/search_template/mod.rs new file mode 100644 index 000000000..e56d7731c --- /dev/null +++ b/src/api/search_template/mod.rs @@ -0,0 +1,114 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 17 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 17 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_search/template"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/create.rs b/src/api/snapshot/create.rs new file mode 100644 index 000000000..d275462ee --- /dev/null +++ b/src/api/snapshot/create.rs @@ -0,0 +1,54 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn put_repository_snapshot<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, + snapshot: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn post_repository_snapshot<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, + snapshot: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/snapshot/create_repository.rs b/src/api/snapshot/create_repository.rs new file mode 100644 index 000000000..6cc72e2fc --- /dev/null +++ b/src/api/snapshot/create_repository.rs @@ -0,0 +1,48 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn post_repository<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn put_repository<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str(url_qry); + let res = + client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/snapshot/delete.rs b/src/api/snapshot/delete.rs new file mode 100644 index 000000000..c781730b3 --- /dev/null +++ b/src/api/snapshot/delete.rs @@ -0,0 +1,27 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn delete_repository_snapshot<'a>(client: &'a mut Client, + req: &'a RequestParams, repository: &'a str, + snapshot: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/delete_repository.rs b/src/api/snapshot/delete_repository.rs new file mode 100644 index 000000000..4bb65a474 --- /dev/null +++ b/src/api/snapshot/delete_repository.rs @@ -0,0 +1,24 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn delete_repository<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str(url_qry); + let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/get.rs b/src/api/snapshot/get.rs new file mode 100644 index 000000000..eeb35612e --- /dev/null +++ b/src/api/snapshot/get.rs @@ -0,0 +1,27 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get_repository_snapshot<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str, snapshot: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/get_repository.rs b/src/api/snapshot/get_repository.rs new file mode 100644 index 000000000..af887fcf3 --- /dev/null +++ b/src/api/snapshot/get_repository.rs @@ -0,0 +1,36 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/mod.rs b/src/api/snapshot/mod.rs new file mode 100644 index 000000000..59606b5c6 --- /dev/null +++ b/src/api/snapshot/mod.rs @@ -0,0 +1,9 @@ +pub mod delete; +pub mod delete_repository; +pub mod get_repository; +pub mod verify_repository; +pub mod restore; +pub mod get; +pub mod create; +pub mod status; +pub mod create_repository; diff --git a/src/api/snapshot/restore.rs b/src/api/snapshot/restore.rs new file mode 100644 index 000000000..c014dd136 --- /dev/null +++ b/src/api/snapshot/restore.rs @@ -0,0 +1,32 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn post_repository_snapshot<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, + snapshot: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + 9 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str("/_restore"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/snapshot/status.rs b/src/api/snapshot/status.rs new file mode 100644 index 000000000..5595ceb08 --- /dev/null +++ b/src/api/snapshot/status.rs @@ -0,0 +1,57 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 8 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/_status"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get_repository_snapshot<'a>(client: &'a mut Client, req: &'a RequestParams, + repository: &'a str, snapshot: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 1 + 8 + repository.len() + + snapshot.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/"); + url_fmtd.push_str(snapshot); + url_fmtd.push_str("/_status"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/_status"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/snapshot/verify_repository.rs b/src/api/snapshot/verify_repository.rs new file mode 100644 index 000000000..e71b5cf27 --- /dev/null +++ b/src/api/snapshot/verify_repository.rs @@ -0,0 +1,29 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html +pub fn post_repository<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + repository: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 11 + 8 + repository.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_snapshot/"); + url_fmtd.push_str(repository); + url_fmtd.push_str("/_verify"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/suggest/mod.rs b/src/api/suggest/mod.rs new file mode 100644 index 000000000..19c3009e2 --- /dev/null +++ b/src/api/suggest/mod.rs @@ -0,0 +1,72 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_suggest"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_suggest"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_suggest"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html +pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 9 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_suggest"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/tasks/cancel.rs b/src/api/tasks/cancel.rs new file mode 100644 index 000000000..1ed71568d --- /dev/null +++ b/src/api/tasks/cancel.rs @@ -0,0 +1,43 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html +pub fn post_task_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, task_id: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + 8 + task_id.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_tasks/"); + url_fmtd.push_str(task_id); + url_fmtd.push_str("/_cancel"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html +pub fn post<'a, + I: Into>>(client: &'a mut Client, req: &'a RequestParams, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_tasks/_cancel"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/tasks/get.rs b/src/api/tasks/get.rs new file mode 100644 index 000000000..359101ad3 --- /dev/null +++ b/src/api/tasks/get.rs @@ -0,0 +1,23 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html +pub fn get_task_id<'a>(client: &'a mut Client, req: &'a RequestParams, + task_id: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 8 + task_id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_tasks/"); + url_fmtd.push_str(task_id); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/tasks/list.rs b/src/api/tasks/list.rs new file mode 100644 index 000000000..e3fb50ac1 --- /dev/null +++ b/src/api/tasks/list.rs @@ -0,0 +1,20 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html +pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/_tasks"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/tasks/mod.rs b/src/api/tasks/mod.rs new file mode 100644 index 000000000..c5a94f8c8 --- /dev/null +++ b/src/api/tasks/mod.rs @@ -0,0 +1,3 @@ +pub mod get; +pub mod cancel; +pub mod list; diff --git a/src/api/termvectors/mod.rs b/src/api/termvectors/mod.rs new file mode 100644 index 000000000..f1ce2dbc8 --- /dev/null +++ b/src/api/termvectors/mod.rs @@ -0,0 +1,98 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html +pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str, id: &'a str) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 13 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_termvectors"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 13 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_termvectors"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 13 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_termvectors"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html +pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, + index: &'a str, _type: &'a str) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 13 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_termvectors"); + url_fmtd.push_str(url_qry); + let res = client.get(&url_fmtd).headers(req.headers.to_owned()); + res.send() +} + diff --git a/src/api/update/mod.rs b/src/api/update/mod.rs new file mode 100644 index 000000000..c8165f192 --- /dev/null +++ b/src/api/update/mod.rs @@ -0,0 +1,34 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html +pub fn post_index_type_id<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, + index: &'a str, _type: &'a str, + id: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 1 + 8 + index.len() + + _type.len() + id.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/"); + url_fmtd.push_str(id); + url_fmtd.push_str("/_update"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/api/update_by_query/mod.rs b/src/api/update_by_query/mod.rs new file mode 100644 index 000000000..ac3859eb3 --- /dev/null +++ b/src/api/update_by_query/mod.rs @@ -0,0 +1,51 @@ +use hyper::client::Client; +#[allow(unused_imports)] +use hyper::client::Body; +use hyper::client::response::Response; +use hyper::error::Result; + +use ::RequestParams; + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html +pub fn post_index_type<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + _type: &'a str, body: I) + -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + + _type.len() + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/"); + url_fmtd.push_str(_type); + url_fmtd.push_str("/_update_by_query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + +/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html +pub fn post_index<'a, + I: Into>>(client: &'a mut Client, + req: &'a RequestParams, index: &'a str, + body: I) -> Result{ + let url_qry = &req.get_url_qry(); + let base = &req.base_url; + let mut url_fmtd = + String::with_capacity(base.len() + 1 + 17 + index.len() + + url_qry.len()); + url_fmtd.push_str(base); + url_fmtd.push_str("/"); + url_fmtd.push_str(index); + url_fmtd.push_str("/_update_by_query"); + url_fmtd.push_str(url_qry); + let res = + client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); + res.send() +} + diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 000000000..02d9c229e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,265 @@ +//! Elasticsearch REST API Client +//! +//! A lightweight implementation of the Elasticsearch API based on the +//! [`hyper`](http://hyper.rs/hyper/) HTTP client. +//! +//! Each API endpoint is represented as its own function, so each possible http route gets its own function. +//! This library makes very few assumptions, leaving it up to you to decide what to invest your +//! precious CPU cycles into. +//! +//! The entire API is generated from the official Elasticsearch spec, so it's always current. +//! +//! # Supported Versions +//! +//! `elastic_types` | Elasticsearch +//! --------------- | ------------- +//! `0.x` | `5.x` +//! +//! # Usage +//! +//! This crate is on [crates.io](https://crates.io/crates/elastic_hyper). +//! To get started, add `elastic_hyper` and `hyper` to your `Cargo.toml`: +//! +//! ```ignore +//! [dependencies] +//! elastic_hyper = "*" +//! hyper = "*" +//! ``` +//! +//! For `Windows`, you may need to exclude `openssl` or the build can fail: +//! +//! ```ignore +//! [dependencies] +//! elastic_hyper = { version = "*", default-features = false } +//! hyper = { version = "*", default-features = false } +//! ``` +//! +//! Then reference in your crate root: +//! +//! ```ignore +//! extern crate elastic_hyper as elastic; +//! extern crate hyper; +//! ``` +//! +//! ## Minimal Example +//! +//! Ping the availability of your cluster: +//! +//! ```no_run +//! //HTTP HEAD / +//! +//! # extern crate hyper; +//! # extern crate elastic_hyper as elastic; +//! # fn main() { +//! let (mut client, params) = elastic::default(); +//! +//! elastic::ping::head(&mut client, ¶ms).unwrap(); +//! # } +//! ``` +//! +//! ## Search Request with Url Param +//! +//! Execute a search query with a url parameter: +//! +//! ```no_run +//! //HTTP GET /myindex/mytype/_search?q='my string' +//! +//! # extern crate hyper; +//! # extern crate elastic_hyper as elastic; +//! # fn main() { +//! let mut client = hyper::Client::new(); +//! let mut params = elastic::RequestParams::default() +//! .url_params(vec![ +//! ("q", "'my string'".to_owned()), +//! ("pretty", "true".to_owned()) +//! ]); +//! +//! elastic::search::get_index_type(&mut client, ¶ms, "myindex", "mytype").unwrap(); +//! # } +//! ``` +//! +//! ## Search Request with Json +//! +//! Using the [`json_str`](http://kodraus.github.io/rustdoc/json_str/) crate, you can execute +//! queries using pure json: +//! +//! ```no_run +//! //HTTP POST /myindex/mytype/_search +//! +//! # #[macro_use] +//! # extern crate json_str; +//! # extern crate hyper; +//! # extern crate elastic_hyper as elastic; +//! # fn main() { +//! let (mut client, params) = elastic::default(); +//! +//! elastic::search::post_index_type(&mut client, ¶ms, +//! "myindex", "mytype", &json_str!({ +//! "query": { +//! "filtered": { +//! "query": { +//! "match_all": {} +//! }, +//! "filter": { +//! "geo_distance": { +//! "distance": "20km", +//! "location": { +//! "lat": 37.776, +//! "lon": -122.41 +//! } +//! } +//! } +//! } +//! } +//! }) +//! ).unwrap(); +//! # } +//! ``` +//! +//! See more [examples](https://github.com/KodrAus/elasticsearch-rs/tree/master/hyper/samples). +//! +//! # See Also +//! +//! ## [`rs-es`](http://benashford.github.io/rs-es/rs_es/index.html) +//! +//! An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL. +//! +//! ## [`elastic_types`](http://kodraus.github.io/rustdoc/elastic_types/) +//! +//! A library that implements the core datatypes in Elasticsearch documents and automatically generates +//! a json mapping from your Rust structures. +//! +//! ## [`json_str`](http://kodraus.github.io/rustdoc/json_str/) +//! +//! A library for generating minified json strings from Rust syntax. +//! +//! # Links +//! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) +//! - [Github](https://github.com/elastic-rs/elastic-hyper) + +extern crate hyper; +extern crate url; + +use std::collections::BTreeMap; +use hyper::header::Headers; +use hyper::header::ContentType; +use url::form_urlencoded::Serializer; + +/// Misc parameters for any request. +/// +/// The `RequestParams` struct allows you to set headers and url parameters for your requests. +/// By default, the `ContentType::json` header will always be added. +/// Url parameters are added as simple key-value pairs, and serialised by [rust-url](http://servo.github.io/rust-url/url/index.html). +/// +/// # Examples +/// +/// With default query parameters: +/// +/// ``` +/// extern crate hyper; +/// extern crate elastic_hyper as elastic; +/// +/// let params = elastic::RequestParams::default(); +/// ``` +/// +/// With custom headers: +/// +/// ``` +/// extern crate hyper; +/// extern crate elastic_hyper as elastic; +/// +/// let mut params = elastic::RequestParams::default(); +/// +/// //Add your own headers +/// params.headers.set(hyper::header::Authorization("let me in".to_owned())); +/// ``` +/// +/// Add url query parameters to the request: +/// +/// ``` +/// extern crate hyper; +/// extern crate elastic_hyper as elastic; +/// +/// let params = elastic::RequestParams::default() +/// .url_params(vec![ +/// ("pretty", "true".to_owned()), +/// ("q", "*".to_owned()) +/// ]); +/// ``` +/// +/// With a custom base url: +/// +/// ``` +/// extern crate hyper; +/// extern crate elastic_hyper as elastic; +/// +/// let params = elastic::RequestParams::new("http://mybaseurl:9200", hyper::header::Headers::new()); +/// ``` +#[derive(Debug, Clone)] +pub struct RequestParams { + /// Base url for Elasticsearch + pub base_url: String, + /// Simple key-value store for url query params. + pub url_params: BTreeMap<&'static str, String>, + /// The complete set of headers that will be sent with the request. + pub headers: Headers +} + +impl RequestParams { + /// Create a new container for request parameters. + /// + /// Attempts to add `ContentType::json` to the passed in `headers` param. + pub fn new>(base: T, mut headers: Headers) -> Self { + headers.set(ContentType::json()); + + RequestParams { + base_url: base.into(), + headers: headers, + url_params: BTreeMap::new() + } + } + + /// Add a collection of url params. + pub fn url_params(mut self, url_params: I) -> Self + where I: IntoIterator { + for (k, v) in url_params { + self.url_params.insert(k, v); + } + + self + } + + /// Get the url params as a formatted string. + /// + /// Follows the `application/x-www-form-urlencoded` format. + pub fn get_url_qry(&self) -> String { + if self.url_params.len() > 0 { + let qry: String = Serializer::new(String::new()) + .extend_pairs(self.url_params.iter()) + .finish(); + let mut url_qry = String::with_capacity(qry.len() + 1); + + url_qry.push('?'); + url_qry.push_str(&qry); + + url_qry + } + else { + String::with_capacity(0) + } + } +} + +impl Default for RequestParams { + fn default() -> Self { + RequestParams::new("http://localhost:9200", Headers::new()) + } +} + +mod api; +pub use api::*; + +/// Get a default `Client` and `RequestParams`. +pub fn default() -> (hyper::Client, RequestParams) { + (hyper::Client::new(), RequestParams::default()) +} diff --git a/tests/mod.rs b/tests/mod.rs new file mode 100644 index 000000000..a10a84890 --- /dev/null +++ b/tests/mod.rs @@ -0,0 +1,38 @@ +extern crate hyper; +extern crate url; +extern crate elastic_hyper; + +use hyper::header::*; +use elastic_hyper::RequestParams; + +#[test] +fn request_params_has_default_content_type() { + let req = RequestParams::default(); + + assert_eq!(Some(&ContentType::json()), req.headers.get::()); +} + +#[test] +fn request_params_has_default_base_url() { + let req = RequestParams::default(); + + assert_eq!("http://localhost:9200", req.base_url); +} + +#[test] +fn request_params_has_url_query() { + let req = RequestParams::default() + .url_params(vec![ + ("pretty", "true".to_owned()), + ("q", "*".to_owned()) + ]); + + assert_eq!("?pretty=true&q=*", &req.get_url_qry()); +} + +#[test] +fn empty_request_params_returns_empty_string() { + let req = RequestParams::default(); + + assert_eq!("", &req.get_url_qry()); +} \ No newline at end of file From 92b0d53463a7cf731b203f9b19b5a0c986135b54 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 18 Sep 2016 18:57:12 +1000 Subject: [PATCH 002/127] add initial readme --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..78b34843e --- /dev/null +++ b/README.md @@ -0,0 +1,68 @@ +# [`elastic_hyper`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_types.svg)](https://crates.io/crates/elastic_hyper) + +Provides a synchronous [`hyper`](https://github.com/hyperium/hyper) implementation of the Elasticsearch REST API. The `hyper` client is simple to use; there's basically no setup needed besides creating a `hyper::Client` object to use for requests. The `hyper` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. + +If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). + +## Build Status +Platform | Channel | Status +------------- | ------------- | ------------- +Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-types.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-types) +Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/2x2cmfi6hku72nmk?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-types) + +## Documentation + +Version | Docs +------------- | ------------- +`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-types/elastic_types/) +`current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_types/*/elastic_types/) + +## Example + +The `elastic_hyper` client is a thin layer over `hyper`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. +- For query serialisation, the [`json_str`](https://github.com/KodrAus/json_str) crate provides the `json_str!` macro for creating ad-hoc API queries. +- For type serialisation / deserialisation, see [`elastic_types`](https://github.com/elastic-rs/elastic-types). + +Currently targeting the `master` Elasticsearch branch, aiming for `5.x`. +This will be stabilised through features in the future. + +Add `elastic_hyper` and `json_str` to your `Cargo.toml`: + +``` +[dependencies] +elastic_hyper = "*" +json_str = "*" +``` + +Ping the availability of your cluster: + +```rust +#[macro_use] +extern crate json_str; +extern crate elastic_hyper as elastic; + +let (mut client, params) = elastic::default(); + +elastic::ping::head(&mut client, ¶ms).unwrap(); +``` + +A simple `query_string` query: + +```rust +#[macro_use] +extern crate json_str; +extern crate elastic_hyper as elastic; + +let (mut client, params) = elastic::default(); + +let response = elastic::search::post( + &mut client, ¶ms, + &json_str!({ + query: { + query_string: { + query: "*" + } + } + }) +).unwrap(); +``` \ No newline at end of file From 6875e11a5eab3fc1b1921ab261b04bed3339fe3a Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 18 Sep 2016 19:00:21 +1000 Subject: [PATCH 003/127] add travis build --- .travis.yml | 27 +++++++++++++++++++++++++++ Cargo.toml | 1 - 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..3503dc432 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,27 @@ +sudo: false +language: rust +addons: + apt: + packages: + - libcurl4-openssl-dev + - libelf-dev + - libdw-dev + - binutils-dev # optional: only required for the --verify flag of coveralls + +rust: + - nightly + - stable + +before_script: + - | + pip install 'travis-cargo<0.2' --user && + export PATH=$HOME/.local/bin:$PATH + +script: + - | + travis-cargo build && + travis-cargo test && + travis-cargo bench && + travis-cargo --only stable doc +after_success: + - travis-cargo --only stable doc-upload \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 13a8b211e..1e4e95921 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ exclude = [ "samples", "codegen" ] [features] default = [ "ssl" ] ssl = [ "hyper/ssl" ] -nightly-testing = [ ] [dependencies] hyper = { version = "~0.9.0", default-features = false } From f027f0cfabf844afaf56d779d41a8461638140f3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 18 Sep 2016 19:08:26 +1000 Subject: [PATCH 004/127] update ci info --- README.md | 10 +++++----- appveyor.yml | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 appveyor.yml diff --git a/README.md b/README.md index 78b34843e..929a7da15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [`elastic_hyper`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_types.svg)](https://crates.io/crates/elastic_hyper) +# [`elastic_hyper`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_hyper.svg)](https://crates.io/crates/elastic_hyper) Provides a synchronous [`hyper`](https://github.com/hyperium/hyper) implementation of the Elasticsearch REST API. The `hyper` client is simple to use; there's basically no setup needed besides creating a `hyper::Client` object to use for requests. The `hyper` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. @@ -7,15 +7,15 @@ If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, ## Build Status Platform | Channel | Status ------------- | ------------- | ------------- -Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-types.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-types) -Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/2x2cmfi6hku72nmk?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-types) +Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-hyper.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-hyper) +Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-hyper) ## Documentation Version | Docs ------------- | ------------- -`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-types/elastic_types/) -`current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_types/*/elastic_types/) +`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-hyper/elastic_hyper/) +`current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_hyper/*/elastic_hyper/) ## Example diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..3d249e9f5 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,15 @@ +environment: + matrix: + - TARGET: x86_64-pc-windows-msvc + - TARGET: i686-pc-windows-msvc + - TARGET: x86_64-pc-windows-gnu + - TARGET: i686-pc-windows-gnu +install: + - ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-nightly-${env:TARGET}.exe" -FileName "rust-nightly.exe" + - ps: .\rust-nightly.exe /VERYSILENT /NORESTART /DIR="C:\rust" | Out-Null + - ps: $env:PATH="$env:PATH;C:\rust\bin" + - rustc -vV + - cargo -vV +build: false +test_script: + - cargo test --verbose --no-default-features From 2ed760b20f16f94912e6e52cbde975d972a34dff Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 18 Sep 2016 19:11:38 +1000 Subject: [PATCH 005/127] fix ci --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3503dc432..e9467c1d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,10 @@ rust: - nightly - stable +env: + global: + - TRAVIS_CARGO_NIGHTLY_FEATURE="" + before_script: - | pip install 'travis-cargo<0.2' --user && From f15192d2d9b26a30158e2675cde6122219ef70c5 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 22 Sep 2016 16:58:35 +1000 Subject: [PATCH 006/127] cargo/0.3.2 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e4e95921..b6910dd41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elastic_hyper" -version = "0.3.1" +version = "0.3.2" authors = ["Ashley Mannix "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on Hyper." -documentation = "https://docs.rs/elastic_types/0.3.1/elastic_hyper/" +documentation = "https://docs.rs/elastic_types/0.3.2/elastic_hyper/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples", "codegen" ] From fb8f7014026cced5ea3fe644c0ecbbb976835d6f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 22 Sep 2016 17:00:23 +1000 Subject: [PATCH 007/127] update docs --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 02d9c229e..965929d19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,21 +120,21 @@ //! //! # See Also //! -//! ## [`rs-es`](http://benashford.github.io/rs-es/rs_es/index.html) +//! ## [`rs-es`](https://github.com/benashford/rs-es) //! //! An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL. //! -//! ## [`elastic_types`](http://kodraus.github.io/rustdoc/elastic_types/) +//! ## [`elastic_types`](https://github.com/elastic-rs/elastic-types) //! //! A library that implements the core datatypes in Elasticsearch documents and automatically generates //! a json mapping from your Rust structures. //! -//! ## [`json_str`](http://kodraus.github.io/rustdoc/json_str/) +//! ## [`json_str`](https://github.com/KodrAus/json_str) //! //! A library for generating minified json strings from Rust syntax. //! //! # Links -//! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html) +//! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) //! - [Github](https://github.com/elastic-rs/elastic-hyper) extern crate hyper; From 9ed4271f4489382ed5ab6078d0356974743b4c44 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 12 Dec 2016 19:53:37 +1000 Subject: [PATCH 008/127] work on using elastic_requests --- Cargo.toml | 3 +- codegen/.gitignore | 2 - codegen/Cargo.toml | 13 -- codegen/README.md | 8 - codegen/src/main.rs | 312 -------------------------- rustfmt.toml | 1 + src/api/bulk/mod.rs | 124 ---------- src/api/cat/aliases.rs | 35 --- src/api/cat/allocation.rs | 36 --- src/api/cat/count.rs | 35 --- src/api/cat/fielddata.rs | 35 --- src/api/cat/health.rs | 20 -- src/api/cat/help.rs | 20 -- src/api/cat/indices.rs | 35 --- src/api/cat/master.rs | 20 -- src/api/cat/mod.rs | 19 -- src/api/cat/nodeattrs.rs | 20 -- src/api/cat/nodes.rs | 20 -- src/api/cat/pending_tasks.rs | 20 -- src/api/cat/plugins.rs | 20 -- src/api/cat/recovery.rs | 35 --- src/api/cat/repositories.rs | 20 -- src/api/cat/segments.rs | 35 --- src/api/cat/shards.rs | 35 --- src/api/cat/snapshots.rs | 24 -- src/api/cat/tasks.rs | 20 -- src/api/cat/thread_pool.rs | 20 -- src/api/clear_scroll/mod.rs | 37 --- src/api/cluster/allocation_explain.rs | 35 --- src/api/cluster/get_settings.rs | 20 -- src/api/cluster/health.rs | 35 --- src/api/cluster/mod.rs | 8 - src/api/cluster/pending_tasks.rs | 20 -- src/api/cluster/put_settings.rs | 23 -- src/api/cluster/reroute.rs | 23 -- src/api/cluster/state.rs | 53 ----- src/api/cluster/stats.rs | 36 --- src/api/count/mod.rs | 114 ---------- src/api/count_percolate/mod.rs | 98 -------- src/api/delete/mod.rs | 29 --- src/api/delete_by_query/mod.rs | 51 ----- src/api/delete_script/mod.rs | 26 --- src/api/delete_template/mod.rs | 23 -- src/api/exists/mod.rs | 29 --- src/api/explain/mod.rs | 56 ----- src/api/field_stats/mod.rs | 72 ------ src/api/get/mod.rs | 29 --- src/api/get_script/mod.rs | 26 --- src/api/get_source/mod.rs | 30 --- src/api/get_template/mod.rs | 23 -- src/api/index/mod.rs | 102 --------- src/api/indices/analyze.rs | 72 ------ src/api/indices/clear_cache.rs | 72 ------ src/api/indices/close.rs | 28 --- src/api/indices/create.rs | 44 ---- src/api/indices/delete.rs | 23 -- src/api/indices/delete_alias.rs | 26 --- src/api/indices/delete_template.rs | 23 -- src/api/indices/exists.rs | 23 -- src/api/indices/exists_alias.rs | 58 ----- src/api/indices/exists_template.rs | 23 -- src/api/indices/exists_type.rs | 26 --- src/api/indices/flush.rs | 72 ------ src/api/indices/flush_synced.rs | 72 ------ src/api/indices/forcemerge.rs | 43 ---- src/api/indices/get.rs | 41 ---- src/api/indices/get_alias.rs | 70 ------ src/api/indices/get_field_mapping.rs | 80 ------- src/api/indices/get_mapping.rs | 70 ------ src/api/indices/get_settings.rs | 70 ------ src/api/indices/get_template.rs | 35 --- src/api/indices/get_upgrade.rs | 37 --- src/api/indices/mod.rs | 36 --- src/api/indices/open.rs | 28 --- src/api/indices/put_alias.rs | 52 ----- src/api/indices/put_mapping.rs | 87 ------- src/api/indices/put_settings.rs | 43 ---- src/api/indices/put_template.rs | 43 ---- src/api/indices/recovery.rs | 37 --- src/api/indices/refresh.rs | 72 ------ src/api/indices/rollover.rs | 50 ----- src/api/indices/segments.rs | 37 --- src/api/indices/shard_stores.rs | 37 --- src/api/indices/shrink.rs | 52 ----- src/api/indices/stats.rs | 70 ------ src/api/indices/update_aliases.rs | 23 -- src/api/indices/upgrade.rs | 43 ---- src/api/indices/validate_query.rs | 114 ---------- src/api/info/mod.rs | 20 -- src/api/ingest/delete_pipeline.rs | 23 -- src/api/ingest/get_pipeline.rs | 23 -- src/api/ingest/mod.rs | 4 - src/api/ingest/put_pipeline.rs | 25 --- src/api/ingest/simulate.rs | 71 ------ src/api/mget/mod.rs | 114 ---------- src/api/mod.rs | 43 ---- src/api/mpercolate/mod.rs | 114 ---------- src/api/msearch/mod.rs | 114 ---------- src/api/msearch_template/mod.rs | 114 ---------- src/api/mtermvectors/mod.rs | 114 ---------- src/api/nodes/hot_threads.rs | 37 --- src/api/nodes/info.rs | 69 ------ src/api/nodes/mod.rs | 3 - src/api/nodes/stats.rs | 114 ---------- src/api/percolate/mod.rs | 98 -------- src/api/ping/mod.rs | 21 -- src/api/put_script/mod.rs | 50 ----- src/api/put_template/mod.rs | 42 ---- src/api/reindex/mod.rs | 24 -- src/api/reindex/rethrottle.rs | 28 --- src/api/render_search_template/mod.rs | 67 ------ src/api/scroll/mod.rs | 71 ------ src/api/search/mod.rs | 114 ---------- src/api/search_shards/mod.rs | 114 ---------- src/api/search_template/mod.rs | 114 ---------- src/api/snapshot/create.rs | 54 ----- src/api/snapshot/create_repository.rs | 48 ---- src/api/snapshot/delete.rs | 27 --- src/api/snapshot/delete_repository.rs | 24 -- src/api/snapshot/get.rs | 27 --- src/api/snapshot/get_repository.rs | 36 --- src/api/snapshot/mod.rs | 9 - src/api/snapshot/restore.rs | 32 --- src/api/snapshot/status.rs | 57 ----- src/api/snapshot/verify_repository.rs | 29 --- src/api/suggest/mod.rs | 72 ------ src/api/tasks/cancel.rs | 43 ---- src/api/tasks/get.rs | 23 -- src/api/tasks/list.rs | 20 -- src/api/tasks/mod.rs | 3 - src/api/termvectors/mod.rs | 98 -------- src/api/update/mod.rs | 34 --- src/api/update_by_query/mod.rs | 51 ----- src/lib.rs | 208 ++++++++++------- 134 files changed, 129 insertions(+), 6328 deletions(-) delete mode 100644 codegen/.gitignore delete mode 100644 codegen/Cargo.toml delete mode 100644 codegen/README.md delete mode 100644 codegen/src/main.rs create mode 100644 rustfmt.toml delete mode 100644 src/api/bulk/mod.rs delete mode 100644 src/api/cat/aliases.rs delete mode 100644 src/api/cat/allocation.rs delete mode 100644 src/api/cat/count.rs delete mode 100644 src/api/cat/fielddata.rs delete mode 100644 src/api/cat/health.rs delete mode 100644 src/api/cat/help.rs delete mode 100644 src/api/cat/indices.rs delete mode 100644 src/api/cat/master.rs delete mode 100644 src/api/cat/mod.rs delete mode 100644 src/api/cat/nodeattrs.rs delete mode 100644 src/api/cat/nodes.rs delete mode 100644 src/api/cat/pending_tasks.rs delete mode 100644 src/api/cat/plugins.rs delete mode 100644 src/api/cat/recovery.rs delete mode 100644 src/api/cat/repositories.rs delete mode 100644 src/api/cat/segments.rs delete mode 100644 src/api/cat/shards.rs delete mode 100644 src/api/cat/snapshots.rs delete mode 100644 src/api/cat/tasks.rs delete mode 100644 src/api/cat/thread_pool.rs delete mode 100644 src/api/clear_scroll/mod.rs delete mode 100644 src/api/cluster/allocation_explain.rs delete mode 100644 src/api/cluster/get_settings.rs delete mode 100644 src/api/cluster/health.rs delete mode 100644 src/api/cluster/mod.rs delete mode 100644 src/api/cluster/pending_tasks.rs delete mode 100644 src/api/cluster/put_settings.rs delete mode 100644 src/api/cluster/reroute.rs delete mode 100644 src/api/cluster/state.rs delete mode 100644 src/api/cluster/stats.rs delete mode 100644 src/api/count/mod.rs delete mode 100644 src/api/count_percolate/mod.rs delete mode 100644 src/api/delete/mod.rs delete mode 100644 src/api/delete_by_query/mod.rs delete mode 100644 src/api/delete_script/mod.rs delete mode 100644 src/api/delete_template/mod.rs delete mode 100644 src/api/exists/mod.rs delete mode 100644 src/api/explain/mod.rs delete mode 100644 src/api/field_stats/mod.rs delete mode 100644 src/api/get/mod.rs delete mode 100644 src/api/get_script/mod.rs delete mode 100644 src/api/get_source/mod.rs delete mode 100644 src/api/get_template/mod.rs delete mode 100644 src/api/index/mod.rs delete mode 100644 src/api/indices/analyze.rs delete mode 100644 src/api/indices/clear_cache.rs delete mode 100644 src/api/indices/close.rs delete mode 100644 src/api/indices/create.rs delete mode 100644 src/api/indices/delete.rs delete mode 100644 src/api/indices/delete_alias.rs delete mode 100644 src/api/indices/delete_template.rs delete mode 100644 src/api/indices/exists.rs delete mode 100644 src/api/indices/exists_alias.rs delete mode 100644 src/api/indices/exists_template.rs delete mode 100644 src/api/indices/exists_type.rs delete mode 100644 src/api/indices/flush.rs delete mode 100644 src/api/indices/flush_synced.rs delete mode 100644 src/api/indices/forcemerge.rs delete mode 100644 src/api/indices/get.rs delete mode 100644 src/api/indices/get_alias.rs delete mode 100644 src/api/indices/get_field_mapping.rs delete mode 100644 src/api/indices/get_mapping.rs delete mode 100644 src/api/indices/get_settings.rs delete mode 100644 src/api/indices/get_template.rs delete mode 100644 src/api/indices/get_upgrade.rs delete mode 100644 src/api/indices/mod.rs delete mode 100644 src/api/indices/open.rs delete mode 100644 src/api/indices/put_alias.rs delete mode 100644 src/api/indices/put_mapping.rs delete mode 100644 src/api/indices/put_settings.rs delete mode 100644 src/api/indices/put_template.rs delete mode 100644 src/api/indices/recovery.rs delete mode 100644 src/api/indices/refresh.rs delete mode 100644 src/api/indices/rollover.rs delete mode 100644 src/api/indices/segments.rs delete mode 100644 src/api/indices/shard_stores.rs delete mode 100644 src/api/indices/shrink.rs delete mode 100644 src/api/indices/stats.rs delete mode 100644 src/api/indices/update_aliases.rs delete mode 100644 src/api/indices/upgrade.rs delete mode 100644 src/api/indices/validate_query.rs delete mode 100644 src/api/info/mod.rs delete mode 100644 src/api/ingest/delete_pipeline.rs delete mode 100644 src/api/ingest/get_pipeline.rs delete mode 100644 src/api/ingest/mod.rs delete mode 100644 src/api/ingest/put_pipeline.rs delete mode 100644 src/api/ingest/simulate.rs delete mode 100644 src/api/mget/mod.rs delete mode 100644 src/api/mod.rs delete mode 100644 src/api/mpercolate/mod.rs delete mode 100644 src/api/msearch/mod.rs delete mode 100644 src/api/msearch_template/mod.rs delete mode 100644 src/api/mtermvectors/mod.rs delete mode 100644 src/api/nodes/hot_threads.rs delete mode 100644 src/api/nodes/info.rs delete mode 100644 src/api/nodes/mod.rs delete mode 100644 src/api/nodes/stats.rs delete mode 100644 src/api/percolate/mod.rs delete mode 100644 src/api/ping/mod.rs delete mode 100644 src/api/put_script/mod.rs delete mode 100644 src/api/put_template/mod.rs delete mode 100644 src/api/reindex/mod.rs delete mode 100644 src/api/reindex/rethrottle.rs delete mode 100644 src/api/render_search_template/mod.rs delete mode 100644 src/api/scroll/mod.rs delete mode 100644 src/api/search/mod.rs delete mode 100644 src/api/search_shards/mod.rs delete mode 100644 src/api/search_template/mod.rs delete mode 100644 src/api/snapshot/create.rs delete mode 100644 src/api/snapshot/create_repository.rs delete mode 100644 src/api/snapshot/delete.rs delete mode 100644 src/api/snapshot/delete_repository.rs delete mode 100644 src/api/snapshot/get.rs delete mode 100644 src/api/snapshot/get_repository.rs delete mode 100644 src/api/snapshot/mod.rs delete mode 100644 src/api/snapshot/restore.rs delete mode 100644 src/api/snapshot/status.rs delete mode 100644 src/api/snapshot/verify_repository.rs delete mode 100644 src/api/suggest/mod.rs delete mode 100644 src/api/tasks/cancel.rs delete mode 100644 src/api/tasks/get.rs delete mode 100644 src/api/tasks/list.rs delete mode 100644 src/api/tasks/mod.rs delete mode 100644 src/api/termvectors/mod.rs delete mode 100644 src/api/update/mod.rs delete mode 100644 src/api/update_by_query/mod.rs diff --git a/Cargo.toml b/Cargo.toml index b6910dd41..502b09ffc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_hyper" -version = "0.3.2" +version = "0.4.0" authors = ["Ashley Mannix "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on Hyper." @@ -13,6 +13,7 @@ default = [ "ssl" ] ssl = [ "hyper/ssl" ] [dependencies] +elastic_requests = { version = "*", git = "https://github.com/elastic-rs/elastic-requests" } hyper = { version = "~0.9.0", default-features = false } url = "~1.1.0" diff --git a/codegen/.gitignore b/codegen/.gitignore deleted file mode 100644 index ab22063e1..000000000 --- a/codegen/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/obj/ \ No newline at end of file diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml deleted file mode 100644 index 67c8a1919..000000000 --- a/codegen/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "elastic_hyper_codegen" -version = "0.1.0" -authors = ["Ashley Mannix "] - -[features] -nightly-testing = [] - -[dependencies] -error-chain = "*" -aster = { version = "*" } -elastic_codegen = { version = "*", path = "../../codegen" } -walkdir = { version = "*" } diff --git a/codegen/README.md b/codegen/README.md deleted file mode 100644 index 7e7688f34..000000000 --- a/codegen/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# `elastic_hyper` codegen - -This is the utility that takes the Elasticsearch API spec and generates `rust` source for `hyper`. -To generate source, build this crate and run: - -``` -target/release/elastic_hyper_codegen ../../codegen/spec/api ../src/api -``` diff --git a/codegen/src/main.rs b/codegen/src/main.rs deleted file mode 100644 index 2a13aadf6..000000000 --- a/codegen/src/main.rs +++ /dev/null @@ -1,312 +0,0 @@ -#![feature(rustc_private, quote)] - -#[macro_use] -extern crate error_chain; -extern crate syntax; -extern crate aster; -extern crate elastic_codegen; -extern crate walkdir; - -use std::io::Read; -use std::fs; -use std::fs::{ File, OpenOptions }; -use std::collections::HashMap; -use syntax::ast::*; -use syntax::ext::base::{ ExtCtxt, DummyMacroLoader }; -use syntax::parse::token; -use syntax::codemap::DUMMY_SP; -use syntax::parse::token::intern; -use elastic_codegen::api::ast::*; -use elastic_codegen::api::parse::*; -use elastic_codegen::api::gen::rust::*; -use elastic_codegen::gen::rust::*; -use elastic_codegen::api::gen::parse::{ parse_path_parts, parse_path_params }; -use elastic_codegen::emit::*; -use elastic_codegen::emit::rust::*; -use walkdir::WalkDir; -use std::env; - -error_chain! { - types { - Error, ErrorKind, ChainErr, Result; - } - - links { } - - foreign_links { - elastic_codegen::api::parse::ParseError, ApiParse; - elastic_codegen::api::gen::rust::ApiGenError, GenParse; - elastic_codegen::emit::EmitError, Emit; - std::io::Error, Io; - } - - errors { } -} - -fn main() { - let mut args = env::args(); - let _ = args.next().unwrap(); - let indir = args.next().unwrap(); - let outdir = args.next().unwrap(); - - println!("spec: {}", indir); - println!("output: {}", outdir); - - gen_from_source(&indir, &outdir).unwrap(); -} - -fn gen_from_source(source_dir: &str, dest_dir: &str) -> Result<()> { - //Clear out the contents of the dest_dir - println!("clearing destination dir..."); - let _ = try!(fs::remove_dir_all(dest_dir)); - let _ = try!(fs::create_dir_all(dest_dir)); - - //Create an emitter and Execution Context - let ps = syntax::parse::ParseSess::new(); - let mut mc = DummyMacroLoader; - - let mut cx = ExtCtxt::new( - &ps, vec![], - syntax::ext::expand::ExpansionConfig::default("qquote".to_string()), - &mut mc - ); - cx.bt_push(syntax::codemap::ExpnInfo { - call_site: DUMMY_SP, - callee: syntax::codemap::NameAndSpan { - format: syntax::codemap::MacroBang(intern("")), - allow_internal_unstable: false, - span: None, - } - }); - - let emitter = RustEmitter::new(); - - //Get the spec source - println!("parsing source spec files..."); - let parsed = try!(from_dir(source_dir)); - - for endpoint in parsed { - //1. Get the path for the generated source - println!("building path for {}...", endpoint.get_name()); - let mut path = try!(endpoint.get_mod_path()); - let (file, file_is_mod) = match path.len() { - 0 => ("mod".to_string(), true), - 1 => ("mod".to_string(), true), - _ => (try!(path.pop().ok_or(format!("Error parsing path filename for {}", endpoint.get_name()))), false) - }; - - let dir_path = format!("{}/{}", dest_dir, path.join("/")); - let file_path = format!("{}/{}.rs", dir_path, file); - - //Ensure the path exists - try!(fs::create_dir_all(&dir_path)); - - //2. Open the source file - let (mut src_file, is_new) = match OpenOptions::new().read(true).write(true).append(true).open(&file_path) { - Ok(mut f) => { - println!("Opened file..."); - - let mut s = String::new(); - try!(f.read_to_string(&mut s)); - - let contains_uses = &s[..].contains("use"); - - (f, !contains_uses) - }, - Err(_) => { - println!("Creating file..."); - (try!(File::create(&file_path)), true) - } - }; - - //4. Emit file header for new files or those without uses - if is_new { - println!("emitting header for {}...", endpoint.get_name()); - - try!(emitter.emit("e_stmt!(&mut cx, use hyper::client::Client;), &cx, &mut src_file)); - try!(emitter.emit_str(&"\n", &mut src_file)); - - try!(emitter.emit("e_stmt!(&mut cx, - #[allow(unused_imports)] - use hyper::client::Body; - ), &cx, &mut src_file)); - try!(emitter.emit_str(&"\n", &mut src_file)); - - try!(emitter.emit("e_stmt!(&mut cx, use hyper::client::response::Response;), &cx, &mut src_file)); - try!(emitter.emit_str(&"\n", &mut src_file)); - - try!(emitter.emit("e_stmt!(&mut cx, use hyper::error::Result;), &cx, &mut src_file)); - try!(emitter.emit_str(&"\n\n", &mut src_file)); - - try!(emitter.emit("e_stmt!(&mut cx, use ::RequestParams;), &cx, &mut src_file)); - try!(emitter.emit_str(&"\n\n", &mut src_file)); - - try!(src_file.sync_all()); - } - - //5. Generate and emit source functions - let fun_sigs = try!(endpoint.get_fns()); - let mut fun_sigs_distinct = HashMap::with_capacity(fun_sigs.len()); - for fun in fun_sigs { - fun_sigs_distinct.insert(fun.name.clone(), fun); - } - - for (_, fun) in fun_sigs_distinct { - println!("emitting fn {}", &fun.name); - - //The base url argument - let client = "client"; - let generic = "I"; - - let req = token::str_to_ident("req"); - let base = token::str_to_ident("base"); - let body = token::str_to_ident("body"); - let qry = token::str_to_ident("url_qry"); - - let lifetime = lifetime("'a"); - - let mut params: Vec = parse_path_params(&fun.path) - .unwrap().iter() - .map(|p| token::str_to_ident(match p.as_str() { - "type" => "_type", - s => s - })) - .collect(); - - //Add the query string param so it's included when building full url - params.push(qry); - - let parts = parse_path_parts(&fun.path).unwrap(); - - //Get the push statements - let (url_ident, url_stmts) = url_push_decl(base, parts.iter().map(|p| p.as_str()), params.to_vec()); - - //Remove the query string param so it's not included in fn signature - let _ = params.pop(); - - //Function signature from params - let mut rs_fun = build_fn(&fun.name, vec![ - build_arg(client, build_ty_ptr("Client", Mutability::Mutable, Some(lifetime))), - build_arg_ident(req, build_ty_ptr("RequestParams", Mutability::Immutable, Some(lifetime))) - ]) - .add_args(params - .iter() - .map(|p: &Ident| build_arg_ident(p.clone(), build_ty_ptr("str", Mutability::Immutable, Some(lifetime)))) - ) - .add_lifetime(lifetime) - .set_return_ty(build_ty("Result")) - .add_body_stmts(vec![ - quote_stmt!(&mut cx, let $qry = &$req.get_url_qry();).unwrap(), - quote_stmt!(&mut cx, let $base = &$req.base_url;).unwrap() - ]) - .add_body_stmts(url_stmts); - - match *fun.method { - HttpVerb::Head => { - rs_fun = block(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.head", client)), - url_ident, req - ); - }, - HttpVerb::Get => { - rs_fun = block(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.get", client)), - url_ident, req - ); - }, - HttpVerb::Delete => { - rs_fun = block(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.delete", client)), - url_ident, req - ); - }, - HttpVerb::Post => { - rs_fun = block_with_body(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.post", client)), - url_ident, req, generic, body - ); - }, - HttpVerb::Put => { - rs_fun = block_with_body(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.put", client)), - url_ident, req, generic, body - ); - }, - HttpVerb::Patch => { - rs_fun = block_with_body(rs_fun, &mut cx, - token::str_to_ident(&format!("{}.patch", client)), - url_ident, req, generic, body - ); - } - }; - - try!(emitter.emit_str(&format!("/// {}\n", endpoint.documentation), &mut src_file)); - try!(emitter.emit(&rs_fun, &cx, &mut src_file)); - try!(emitter.emit_str(&"\n", &mut src_file)); - try!(src_file.sync_all()); - try!(emitter.emit_str(&"\n", &mut src_file)); - } - - //6. Emit mod header if file isn't mod - if !file_is_mod { - let mod_path = format!("{}/{}.rs", dir_path, "mod"); - let mut mod_file = match OpenOptions::new().write(true).append(true).open(&mod_path) { - Ok(f) => f, - Err(_) => File::create(&mod_path).unwrap() - }; - - try!(emitter.emit_str(&format!("pub mod {};\n", file), &mut mod_file)); - try!(mod_file.sync_all()); - } - } - - //7. Build up the mod structure - let mut mod_paths = Vec::new(); - for entry in WalkDir::new(dest_dir).min_depth(1).max_open(1).into_iter().filter_map(|e| e.ok()) { - let meta = entry.metadata().unwrap(); - if meta.is_dir() { - if let Some(parent) = entry.path().parent() { - let name = entry.file_name(); - - mod_paths.push(( - (format!("{}/{}.rs", parent.to_str().unwrap().to_string(), "mod")), - name.to_str().unwrap().to_string() - )); - } - } - } - - for (path, name) in mod_paths { - let mut mod_file = match OpenOptions::new().write(true).append(true).open(&path) { - Ok(f) => f, - Err(_) => File::create(&path).unwrap() - }; - - try!(emitter.emit_str(&format!("pub mod {};\n", name), &mut mod_file)); - try!(mod_file.sync_all()); - } - - Ok(()) -} - -fn block(rs_fun: Fn, cx: &mut ExtCtxt, call: Ident, url_ident: Ident, req: Ident) -> Fn { - rs_fun - .add_body_stmts(vec![ - quote_stmt!(cx, let res = $call(&$url_ident).headers($req.headers.to_owned());).unwrap(), - quote_stmt!(cx, res.send()).unwrap() - ]) -} - -fn block_with_body(rs_fun: Fn, cx: &mut ExtCtxt, call: Ident, url_ident: Ident, req: Ident, generic: &str, body: Ident) -> Fn { - rs_fun - .set_generic_params(vec![ - build_ty_param(generic, vec![ - "Into>" - ]) - ]) - .add_arg(build_arg_ident(body, build_ty(generic))) - .add_body_stmts(vec![ - quote_stmt!(cx, let res = $call(&$url_ident).headers($req.headers.to_owned()).body($body.into());).unwrap(), - quote_stmt!(cx, res.send()).unwrap() - ]) -} diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000..2ad57bd25 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 250 \ No newline at end of file diff --git a/src/api/bulk/mod.rs b/src/api/bulk/mod.rs deleted file mode 100644 index cbeb8c5fb..000000000 --- a/src/api/bulk/mod.rs +++ /dev/null @@ -1,124 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn put<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn put_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 6 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html -pub fn put_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 6 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_bulk"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/cat/aliases.rs b/src/api/cat/aliases.rs deleted file mode 100644 index 9c0b42db8..000000000 --- a/src/api/cat/aliases.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/aliases"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html -pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 14 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/aliases/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/allocation.rs b/src/api/cat/allocation.rs deleted file mode 100644 index c4ae45237..000000000 --- a/src/api/cat/allocation.rs +++ /dev/null @@ -1,36 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/allocation"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html -pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 17 + node_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/allocation/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/count.rs b/src/api/cat/count.rs deleted file mode 100644 index ac435f9f1..000000000 --- a/src/api/cat/count.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 12 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/count/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/fielddata.rs b/src/api/cat/fielddata.rs deleted file mode 100644 index 4bca96031..000000000 --- a/src/api/cat/fielddata.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/fielddata"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html -pub fn get_fields<'a>(client: &'a mut Client, req: &'a RequestParams, - fields: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + fields.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/fielddata/"); - url_fmtd.push_str(fields); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/health.rs b/src/api/cat/health.rs deleted file mode 100644 index f850fdce2..000000000 --- a/src/api/cat/health.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/health"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/help.rs b/src/api/cat/help.rs deleted file mode 100644 index ba0529af0..000000000 --- a/src/api/cat/help.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 5 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/indices.rs b/src/api/cat/indices.rs deleted file mode 100644 index bc47fea23..000000000 --- a/src/api/cat/indices.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/indices"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 14 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/indices/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/master.rs b/src/api/cat/master.rs deleted file mode 100644 index f9939a795..000000000 --- a/src/api/cat/master.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/master"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/mod.rs b/src/api/cat/mod.rs deleted file mode 100644 index 4ebdf3637..000000000 --- a/src/api/cat/mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -pub mod thread_pool; -pub mod repositories; -pub mod nodeattrs; -pub mod allocation; -pub mod help; -pub mod aliases; -pub mod pending_tasks; -pub mod shards; -pub mod segments; -pub mod recovery; -pub mod health; -pub mod count; -pub mod snapshots; -pub mod nodes; -pub mod indices; -pub mod plugins; -pub mod tasks; -pub mod fielddata; -pub mod master; diff --git a/src/api/cat/nodeattrs.rs b/src/api/cat/nodeattrs.rs deleted file mode 100644 index 14e40652e..000000000 --- a/src/api/cat/nodeattrs.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/nodeattrs"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/nodes.rs b/src/api/cat/nodes.rs deleted file mode 100644 index be5970968..000000000 --- a/src/api/cat/nodes.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/nodes"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/pending_tasks.rs b/src/api/cat/pending_tasks.rs deleted file mode 100644 index 8726c3bce..000000000 --- a/src/api/cat/pending_tasks.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 19 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/pending_tasks"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/plugins.rs b/src/api/cat/plugins.rs deleted file mode 100644 index 63cdb9fca..000000000 --- a/src/api/cat/plugins.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/plugins"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/recovery.rs b/src/api/cat/recovery.rs deleted file mode 100644 index ae0216586..000000000 --- a/src/api/cat/recovery.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/recovery"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 15 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/recovery/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/repositories.rs b/src/api/cat/repositories.rs deleted file mode 100644 index 5ef749f0a..000000000 --- a/src/api/cat/repositories.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/repositories"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/segments.rs b/src/api/cat/segments.rs deleted file mode 100644 index 7fbdb4090..000000000 --- a/src/api/cat/segments.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/segments"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 15 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/segments/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/shards.rs b/src/api/cat/shards.rs deleted file mode 100644 index cbd506d82..000000000 --- a/src/api/cat/shards.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/shards"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 13 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/shards/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/snapshots.rs b/src/api/cat/snapshots.rs deleted file mode 100644 index c8c9027cc..000000000 --- a/src/api/cat/snapshots.rs +++ /dev/null @@ -1,24 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html -pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/snapshots/"); - url_fmtd.push_str(repository); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/tasks.rs b/src/api/cat/tasks.rs deleted file mode 100644 index 91050eadc..000000000 --- a/src/api/cat/tasks.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 11 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/tasks"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cat/thread_pool.rs b/src/api/cat/thread_pool.rs deleted file mode 100644 index 86e4f2dd3..000000000 --- a/src/api/cat/thread_pool.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cat/thread_pool"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/clear_scroll/mod.rs b/src/api/clear_scroll/mod.rs deleted file mode 100644 index 2cd7a44bb..000000000 --- a/src/api/clear_scroll/mod.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn delete<'a>(client: &'a mut Client, req: &'a RequestParams) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll"); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn delete_scroll_id<'a>(client: &'a mut Client, req: &'a RequestParams, - scroll_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + scroll_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll/"); - url_fmtd.push_str(scroll_id); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cluster/allocation_explain.rs b/src/api/cluster/allocation_explain.rs deleted file mode 100644 index 8e2dc5431..000000000 --- a/src/api/cluster/allocation_explain.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 28 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/allocation/explain"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 28 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/allocation/explain"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/cluster/get_settings.rs b/src/api/cluster/get_settings.rs deleted file mode 100644 index f9b416eb2..000000000 --- a/src/api/cluster/get_settings.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/settings"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cluster/health.rs b/src/api/cluster/health.rs deleted file mode 100644 index a44a1fdae..000000000 --- a/src/api/cluster/health.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/health"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 17 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/health/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cluster/mod.rs b/src/api/cluster/mod.rs deleted file mode 100644 index c8f023df7..000000000 --- a/src/api/cluster/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod allocation_explain; -pub mod state; -pub mod health; -pub mod pending_tasks; -pub mod stats; -pub mod reroute; -pub mod put_settings; -pub mod get_settings; diff --git a/src/api/cluster/pending_tasks.rs b/src/api/cluster/pending_tasks.rs deleted file mode 100644 index b85c597bb..000000000 --- a/src/api/cluster/pending_tasks.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 23 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/pending_tasks"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cluster/put_settings.rs b/src/api/cluster/put_settings.rs deleted file mode 100644 index 775ad7db3..000000000 --- a/src/api/cluster/put_settings.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html -pub fn put<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/settings"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/cluster/reroute.rs b/src/api/cluster/reroute.rs deleted file mode 100644 index f0263ade5..000000000 --- a/src/api/cluster/reroute.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/reroute"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/cluster/state.rs b/src/api/cluster/state.rs deleted file mode 100644 index a39dadfab..000000000 --- a/src/api/cluster/state.rs +++ /dev/null @@ -1,53 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html -pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/state/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html -pub fn get_metric_index<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str, index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + 1 + metric.len() + index.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/state/"); - url_fmtd.push_str(metric); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/state"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/cluster/stats.rs b/src/api/cluster/stats.rs deleted file mode 100644 index 002dbf5ce..000000000 --- a/src/api/cluster/stats.rs +++ /dev/null @@ -1,36 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html -pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 22 + node_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cluster/stats/nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/count/mod.rs b/src/api/count/mod.rs deleted file mode 100644 index 1d22f3c5b..000000000 --- a/src/api/count/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 7 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 7 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/count_percolate/mod.rs b/src/api/count_percolate/mod.rs deleted file mode 100644 index 63e790b33..000000000 --- a/src/api/count_percolate/mod.rs +++ /dev/null @@ -1,98 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 17 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_percolate/count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_percolate/count"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 17 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_percolate/count"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_percolate/count"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/delete/mod.rs b/src/api/delete/mod.rs deleted file mode 100644 index 2d9c9e39e..000000000 --- a/src/api/delete/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html -pub fn delete_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/delete_by_query/mod.rs b/src/api/delete_by_query/mod.rs deleted file mode 100644 index 5055897a9..000000000 --- a/src/api/delete_by_query/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_delete_by_query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 17 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_delete_by_query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/delete_script/mod.rs b/src/api/delete_script/mod.rs deleted file mode 100644 index 30d4f1612..000000000 --- a/src/api/delete_script/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html -pub fn delete_lang_id<'a>(client: &'a mut Client, req: &'a RequestParams, - lang: &'a str, id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_scripts/"); - url_fmtd.push_str(lang); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/delete_template/mod.rs b/src/api/delete_template/mod.rs deleted file mode 100644 index fa479ebea..000000000 --- a/src/api/delete_template/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html -pub fn delete_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/exists/mod.rs b/src/api/exists/mod.rs deleted file mode 100644 index 4fc58e907..000000000 --- a/src/api/exists/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html -pub fn head_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/explain/mod.rs b/src/api/explain/mod.rs deleted file mode 100644 index a8d7a2831..000000000 --- a/src/api/explain/mod.rs +++ /dev/null @@ -1,56 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 9 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_explain"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 9 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_explain"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/field_stats/mod.rs b/src/api/field_stats/mod.rs deleted file mode 100644 index d6f760766..000000000 --- a/src/api/field_stats/mod.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_field_stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 13 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_field_stats"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_field_stats"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-stats.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 13 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_field_stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/get/mod.rs b/src/api/get/mod.rs deleted file mode 100644 index d4e840cd7..000000000 --- a/src/api/get/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/get_script/mod.rs b/src/api/get_script/mod.rs deleted file mode 100644 index 6f21142e6..000000000 --- a/src/api/get_script/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html -pub fn get_lang_id<'a>(client: &'a mut Client, req: &'a RequestParams, - lang: &'a str, id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_scripts/"); - url_fmtd.push_str(lang); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/get_source/mod.rs b/src/api/get_source/mod.rs deleted file mode 100644 index e06932d39..000000000 --- a/src/api/get_source/mod.rs +++ /dev/null @@ -1,30 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 8 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_source"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/get_template/mod.rs b/src/api/get_template/mod.rs deleted file mode 100644 index 26dc955e0..000000000 --- a/src/api/get_template/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html -pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/index/mod.rs b/src/api/index/mod.rs deleted file mode 100644 index e00e943cd..000000000 --- a/src/api/index/mod.rs +++ /dev/null @@ -1,102 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html -pub fn put_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html -pub fn put_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/analyze.rs b/src/api/indices/analyze.rs deleted file mode 100644 index 91b45def8..000000000 --- a/src/api/indices/analyze.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_analyze"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_analyze"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_analyze"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_analyze"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/clear_cache.rs b/src/api/indices/clear_cache.rs deleted file mode 100644 index b90bcddb0..000000000 --- a/src/api/indices/clear_cache.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cache/clear"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 13 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_cache/clear"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_cache/clear"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 13 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_cache/clear"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/close.rs b/src/api/indices/close.rs deleted file mode 100644 index ff81a3593..000000000 --- a/src/api/indices/close.rs +++ /dev/null @@ -1,28 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_close"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/create.rs b/src/api/indices/create.rs deleted file mode 100644 index 106e360b6..000000000 --- a/src/api/indices/create.rs +++ /dev/null @@ -1,44 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html -pub fn put_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/delete.rs b/src/api/indices/delete.rs deleted file mode 100644 index 52651b776..000000000 --- a/src/api/indices/delete.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html -pub fn delete_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/delete_alias.rs b/src/api/indices/delete_alias.rs deleted file mode 100644 index 74a747015..000000000 --- a/src/api/indices/delete_alias.rs +++ /dev/null @@ -1,26 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn delete_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_aliases/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/delete_template.rs b/src/api/indices/delete_template.rs deleted file mode 100644 index 68a4ae138..000000000 --- a/src/api/indices/delete_template.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn delete_name<'a>(client: &'a mut Client, req: &'a RequestParams, - name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/exists.rs b/src/api/indices/exists.rs deleted file mode 100644 index 319abe10c..000000000 --- a/src/api/indices/exists.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html -pub fn head_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/exists_alias.rs b/src/api/indices/exists_alias.rs deleted file mode 100644 index ae8ec37a2..000000000 --- a/src/api/indices/exists_alias.rs +++ /dev/null @@ -1,58 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn head_name<'a>(client: &'a mut Client, req: &'a RequestParams, - name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_alias/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn head_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 8 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_alias/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn head_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_alias"); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/exists_template.rs b/src/api/indices/exists_template.rs deleted file mode 100644 index f8ecb3917..000000000 --- a/src/api/indices/exists_template.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn head_name<'a>(client: &'a mut Client, req: &'a RequestParams, - name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/exists_type.rs b/src/api/indices/exists_type.rs deleted file mode 100644 index fb3da81d7..000000000 --- a/src/api/indices/exists_type.rs +++ /dev/null @@ -1,26 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html -pub fn head_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + index.len() + _type.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/flush.rs b/src/api/indices/flush.rs deleted file mode 100644 index 61ef173f9..000000000 --- a/src/api/indices/flush.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_flush"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_flush"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_flush"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_flush"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/flush_synced.rs b/src/api/indices/flush_synced.rs deleted file mode 100644 index bba4bfc20..000000000 --- a/src/api/indices/flush_synced.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_flush/synced"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 14 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_flush/synced"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_flush/synced"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 14 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_flush/synced"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/forcemerge.rs b/src/api/indices/forcemerge.rs deleted file mode 100644 index b7e3f51b5..000000000 --- a/src/api/indices/forcemerge.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 12 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_forcemerge"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_forcemerge"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/get.rs b/src/api/indices/get.rs deleted file mode 100644 index 0c6a85f39..000000000 --- a/src/api/indices/get.rs +++ /dev/null @@ -1,41 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html -pub fn get_index_feature<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, feature: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + index.len() + feature.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(feature); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_alias.rs b/src/api/indices/get_alias.rs deleted file mode 100644 index 8d5551bc0..000000000 --- a/src/api/indices/get_alias.rs +++ /dev/null @@ -1,70 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn get_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 8 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_alias/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_alias"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_alias/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_alias"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_field_mapping.rs b/src/api/indices/get_field_mapping.rs deleted file mode 100644 index 944d6ded2..000000000 --- a/src/api/indices/get_field_mapping.rs +++ /dev/null @@ -1,80 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html -pub fn get_index_type_fields<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, fields: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + 7 + index.len() + - _type.len() + fields.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mapping/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/field/"); - url_fmtd.push_str(fields); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html -pub fn get_index_fields<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, fields: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 16 + index.len() + fields.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mapping/field/"); - url_fmtd.push_str(fields); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html -pub fn get_fields<'a>(client: &'a mut Client, req: &'a RequestParams, - fields: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + fields.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mapping/field/"); - url_fmtd.push_str(fields); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html -pub fn get_type_fields<'a>(client: &'a mut Client, req: &'a RequestParams, - _type: &'a str, fields: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + 7 + _type.len() + fields.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mapping/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/field/"); - url_fmtd.push_str(fields); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_mapping.rs b/src/api/indices/get_mapping.rs deleted file mode 100644 index 96039ba2d..000000000 --- a/src/api/indices/get_mapping.rs +++ /dev/null @@ -1,70 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mapping"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + _type.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mapping/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html -pub fn get_type<'a>(client: &'a mut Client, req: &'a RequestParams, - _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mapping/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mapping"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_settings.rs b/src/api/indices/get_settings.rs deleted file mode 100644 index d5be5f0fe..000000000 --- a/src/api/indices/get_settings.rs +++ /dev/null @@ -1,70 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html -pub fn get_index_name<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, name: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 11 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_settings/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_settings"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html -pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_settings/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_settings"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_template.rs b/src/api/indices/get_template.rs deleted file mode 100644 index 09f436624..000000000 --- a/src/api/indices/get_template.rs +++ /dev/null @@ -1,35 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn get_name<'a>(client: &'a mut Client, req: &'a RequestParams, name: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/get_upgrade.rs b/src/api/indices/get_upgrade.rs deleted file mode 100644 index 6d31aff66..000000000 --- a/src/api/indices/get_upgrade.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_upgrade"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_upgrade"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/mod.rs b/src/api/indices/mod.rs deleted file mode 100644 index e97e9a366..000000000 --- a/src/api/indices/mod.rs +++ /dev/null @@ -1,36 +0,0 @@ -pub mod close; -pub mod get_settings; -pub mod put_template; -pub mod get_template; -pub mod stats; -pub mod forcemerge; -pub mod exists; -pub mod flush_synced; -pub mod delete; -pub mod create; -pub mod flush; -pub mod refresh; -pub mod exists_alias; -pub mod get_field_mapping; -pub mod get_alias; -pub mod recovery; -pub mod clear_cache; -pub mod put_mapping; -pub mod validate_query; -pub mod shard_stores; -pub mod update_aliases; -pub mod open; -pub mod get_mapping; -pub mod exists_template; -pub mod get_upgrade; -pub mod delete_template; -pub mod put_settings; -pub mod put_alias; -pub mod upgrade; -pub mod delete_alias; -pub mod rollover; -pub mod get; -pub mod analyze; -pub mod segments; -pub mod shrink; -pub mod exists_type; diff --git a/src/api/indices/open.rs b/src/api/indices/open.rs deleted file mode 100644 index 92dca5717..000000000 --- a/src/api/indices/open.rs +++ /dev/null @@ -1,28 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 6 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_open"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/put_alias.rs b/src/api/indices/put_alias.rs deleted file mode 100644 index bdfdd14b2..000000000 --- a/src/api/indices/put_alias.rs +++ /dev/null @@ -1,52 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn post_index_name<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - name: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_aliases/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn put_index_name<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - name: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + name.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_aliases/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/put_mapping.rs b/src/api/indices/put_mapping.rs deleted file mode 100644 index b9d65492d..000000000 --- a/src/api/indices/put_mapping.rs +++ /dev/null @@ -1,87 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 11 + index.len() + _type.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mappings/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html -pub fn put_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 11 + index.len() + _type.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mappings/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html -pub fn post_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, _type: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mappings/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html -pub fn put_type<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - _type: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mappings/"); - url_fmtd.push_str(_type); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/put_settings.rs b/src/api/indices/put_settings.rs deleted file mode 100644 index f110cbebd..000000000 --- a/src/api/indices/put_settings.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html -pub fn put<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_settings"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html -pub fn put_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_settings"); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/put_template.rs b/src/api/indices/put_template.rs deleted file mode 100644 index 534f4ba74..000000000 --- a/src/api/indices/put_template.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn post_name<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, name: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html -pub fn put_name<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - name: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + name.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_template/"); - url_fmtd.push_str(name); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/recovery.rs b/src/api/indices/recovery.rs deleted file mode 100644 index 0744b3f22..000000000 --- a/src/api/indices/recovery.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_recovery"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_recovery"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/refresh.rs b/src/api/indices/refresh.rs deleted file mode 100644 index e5fa06371..000000000 --- a/src/api/indices/refresh.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_refresh"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_refresh"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_refresh"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_refresh"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/rollover.rs b/src/api/indices/rollover.rs deleted file mode 100644 index e4c0dfe3b..000000000 --- a/src/api/indices/rollover.rs +++ /dev/null @@ -1,50 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html -pub fn post_alias<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, alias: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + alias.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(alias); - url_fmtd.push_str("/_rollover"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html -pub fn post_alias_new_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - alias: &'a str, new_index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 11 + alias.len() + - new_index.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(alias); - url_fmtd.push_str("/_rollover/"); - url_fmtd.push_str(new_index); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/segments.rs b/src/api/indices/segments.rs deleted file mode 100644 index 79d2c806b..000000000 --- a/src/api/indices/segments.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_segments"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 10 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_segments"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/shard_stores.rs b/src/api/indices/shard_stores.rs deleted file mode 100644 index 22a7cf75d..000000000 --- a/src/api/indices/shard_stores.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_shard_stores"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 14 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_shard_stores"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/shrink.rs b/src/api/indices/shrink.rs deleted file mode 100644 index 5adc98817..000000000 --- a/src/api/indices/shrink.rs +++ /dev/null @@ -1,52 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html -pub fn put_index_target<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - target: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + target.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_shrink/"); - url_fmtd.push_str(target); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html -pub fn post_index_target<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, target: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + target.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_shrink/"); - url_fmtd.push_str(target); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/stats.rs b/src/api/indices/stats.rs deleted file mode 100644 index 71b7976cd..000000000 --- a/src/api/indices/stats.rs +++ /dev/null @@ -1,70 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html -pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html -pub fn get_index_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, metric: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 8 + index.len() + metric.len() - + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 7 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/indices/update_aliases.rs b/src/api/indices/update_aliases.rs deleted file mode 100644 index 8c8cdbc06..000000000 --- a/src/api/indices/update_aliases.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_aliases"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/upgrade.rs b/src/api/indices/upgrade.rs deleted file mode 100644 index 0d322544d..000000000 --- a/src/api/indices/upgrade.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_upgrade"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_upgrade"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/indices/validate_query.rs b/src/api/indices/validate_query.rs deleted file mode 100644 index 291d36b71..000000000 --- a/src/api/indices/validate_query.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 16 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 16 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 16 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 16 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 16 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_validate/query"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/info/mod.rs b/src/api/info/mod.rs deleted file mode 100644 index f1713e232..000000000 --- a/src/api/info/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/ -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 1 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/ingest/delete_pipeline.rs b/src/api/ingest/delete_pipeline.rs deleted file mode 100644 index 4064863f8..000000000 --- a/src/api/ingest/delete_pipeline.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn delete_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/ingest/get_pipeline.rs b/src/api/ingest/get_pipeline.rs deleted file mode 100644 index 0a59a0554..000000000 --- a/src/api/ingest/get_pipeline.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/ingest/mod.rs b/src/api/ingest/mod.rs deleted file mode 100644 index e52407664..000000000 --- a/src/api/ingest/mod.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub mod put_pipeline; -pub mod simulate; -pub mod delete_pipeline; -pub mod get_pipeline; diff --git a/src/api/ingest/put_pipeline.rs b/src/api/ingest/put_pipeline.rs deleted file mode 100644 index 2982d5022..000000000 --- a/src/api/ingest/put_pipeline.rs +++ /dev/null @@ -1,25 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn put_id<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/ingest/simulate.rs b/src/api/ingest/simulate.rs deleted file mode 100644 index 033d335fd..000000000 --- a/src/api/ingest/simulate.rs +++ /dev/null @@ -1,71 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn post_id<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + 10 + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_simulate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 27 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/_simulate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + 10 + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_simulate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 27 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_ingest/pipeline/_simulate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/mget/mod.rs b/src/api/mget/mod.rs deleted file mode 100644 index 05e86528b..000000000 --- a/src/api/mget/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 6 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 6 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 6 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 6 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mget"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/mod.rs b/src/api/mod.rs deleted file mode 100644 index e3c0240cb..000000000 --- a/src/api/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -pub mod index; -pub mod exists; -pub mod tasks; -pub mod ingest; -pub mod clear_scroll; -pub mod termvectors; -pub mod field_stats; -pub mod cat; -pub mod nodes; -pub mod snapshot; -pub mod suggest; -pub mod delete_script; -pub mod msearch_template; -pub mod scroll; -pub mod indices; -pub mod put_template; -pub mod ping; -pub mod update; -pub mod mtermvectors; -pub mod search; -pub mod get_template; -pub mod cluster; -pub mod get_script; -pub mod reindex; -pub mod mget; -pub mod count_percolate; -pub mod render_search_template; -pub mod get; -pub mod delete_template; -pub mod explain; -pub mod count; -pub mod get_source; -pub mod delete; -pub mod percolate; -pub mod info; -pub mod search_template; -pub mod update_by_query; -pub mod search_shards; -pub mod delete_by_query; -pub mod mpercolate; -pub mod put_script; -pub mod bulk; -pub mod msearch; diff --git a/src/api/mpercolate/mod.rs b/src/api/mpercolate/mod.rs deleted file mode 100644 index a856dd606..000000000 --- a/src/api/mpercolate/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 12 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 12 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 12 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 12 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 12 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mpercolate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/msearch/mod.rs b/src/api/msearch/mod.rs deleted file mode 100644 index 16c8d2abd..000000000 --- a/src/api/msearch/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 9 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 9 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_msearch"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/msearch_template/mod.rs b/src/api/msearch_template/mod.rs deleted file mode 100644 index a8c58d6e8..000000000 --- a/src/api/msearch_template/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 18 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 18 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 18 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 18 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_msearch/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/mtermvectors/mod.rs b/src/api/mtermvectors/mod.rs deleted file mode 100644 index cb52a1deb..000000000 --- a/src/api/mtermvectors/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 14 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 14 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 14 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 14 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 14 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_mtermvectors"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/nodes/hot_threads.rs b/src/api/nodes/hot_threads.rs deleted file mode 100644 index 21986c4cc..000000000 --- a/src/api/nodes/hot_threads.rs +++ /dev/null @@ -1,37 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 19 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/hot_threads"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html -pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 12 + node_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str("/hot_threads"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/nodes/info.rs b/src/api/nodes/info.rs deleted file mode 100644 index c3c5e0665..000000000 --- a/src/api/nodes/info.rs +++ /dev/null @@ -1,69 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html -pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html -pub fn get_node_id_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str, metric: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 1 + node_id.len() + - metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str("/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html -pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + node_id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/nodes/mod.rs b/src/api/nodes/mod.rs deleted file mode 100644 index a94b5634c..000000000 --- a/src/api/nodes/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod hot_threads; -pub mod stats; -pub mod info; diff --git a/src/api/nodes/stats.rs b/src/api/nodes/stats.rs deleted file mode 100644 index 44a605cbb..000000000 --- a/src/api/nodes/stats.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get_metric_index_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str, index_metric: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 14 + 1 + metric.len() + - index_metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str("/"); - url_fmtd.push_str(index_metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - metric: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 14 + metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 13 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get_node_id_metric_index_metric<'a>(client: &'a mut Client, - req: &'a RequestParams, - node_id: &'a str, metric: &'a str, - index_metric: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 7 + 1 + node_id.len() + - metric.len() + index_metric.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str("/stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str("/"); - url_fmtd.push_str(index_metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get_node_id_metric<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str, metric: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 7 + node_id.len() + - metric.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str("/stats/"); - url_fmtd.push_str(metric); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html -pub fn get_node_id<'a>(client: &'a mut Client, req: &'a RequestParams, - node_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 6 + node_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_nodes/"); - url_fmtd.push_str(node_id); - url_fmtd.push_str("/stats"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/percolate/mod.rs b/src/api/percolate/mod.rs deleted file mode 100644 index ceaff6cec..000000000 --- a/src/api/percolate/mod.rs +++ /dev/null @@ -1,98 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 11 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_percolate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 11 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_percolate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 11 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_percolate"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-percolate.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 11 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_percolate"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/ping/mod.rs b/src/api/ping/mod.rs deleted file mode 100644 index 508a28f41..000000000 --- a/src/api/ping/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/ -pub fn head<'a>(client: &'a mut Client, req: &'a RequestParams) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 1 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(url_qry); - let res = client.head(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/put_script/mod.rs b/src/api/put_script/mod.rs deleted file mode 100644 index ec0883cdd..000000000 --- a/src/api/put_script/mod.rs +++ /dev/null @@ -1,50 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html -pub fn put_lang_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, lang: &'a str, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_scripts/"); - url_fmtd.push_str(lang); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html -pub fn post_lang_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, lang: &'a str, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 10 + 1 + lang.len() + id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_scripts/"); - url_fmtd.push_str(lang); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/put_template/mod.rs b/src/api/put_template/mod.rs deleted file mode 100644 index 8ed261579..000000000 --- a/src/api/put_template/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html -pub fn put_id<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-template.html -pub fn post_id<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/reindex/mod.rs b/src/api/reindex/mod.rs deleted file mode 100644 index d04e7ce7c..000000000 --- a/src/api/reindex/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub mod rethrottle; -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_reindex"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/reindex/rethrottle.rs b/src/api/reindex/rethrottle.rs deleted file mode 100644 index 513225776..000000000 --- a/src/api/reindex/rethrottle.rs +++ /dev/null @@ -1,28 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html -pub fn post_task_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, task_id: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + 12 + task_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_delete_by_query/"); - url_fmtd.push_str(task_id); - url_fmtd.push_str("/_rethrottle"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/render_search_template/mod.rs b/src/api/render_search_template/mod.rs deleted file mode 100644 index 0a6040bd4..000000000 --- a/src/api/render_search_template/mod.rs +++ /dev/null @@ -1,67 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html -pub fn post_id<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - id: &'a str, body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_render/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_render/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html -pub fn get_id<'a>(client: &'a mut Client, req: &'a RequestParams, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 18 + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_render/template/"); - url_fmtd.push_str(id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_render/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/scroll/mod.rs b/src/api/scroll/mod.rs deleted file mode 100644 index 682132342..000000000 --- a/src/api/scroll/mod.rs +++ /dev/null @@ -1,71 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn get_scroll_id<'a>(client: &'a mut Client, req: &'a RequestParams, - scroll_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + scroll_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll/"); - url_fmtd.push_str(scroll_id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn post_scroll_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - scroll_id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 16 + scroll_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll/"); - url_fmtd.push_str(scroll_id); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/scroll"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/search/mod.rs b/src/api/search/mod.rs deleted file mode 100644 index 302cc85d0..000000000 --- a/src/api/search/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 8 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 8 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 8 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 8 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 8 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 8 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/search_shards/mod.rs b/src/api/search_shards/mod.rs deleted file mode 100644 index 138f8a776..000000000 --- a/src/api/search_shards/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 15 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 15 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 15 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 15 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search_shards"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/search_template/mod.rs b/src/api/search_template/mod.rs deleted file mode 100644 index e56d7731c..000000000 --- a/src/api/search_template/mod.rs +++ /dev/null @@ -1,114 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 17 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 17 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 17 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_search/template"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/create.rs b/src/api/snapshot/create.rs deleted file mode 100644 index d275462ee..000000000 --- a/src/api/snapshot/create.rs +++ /dev/null @@ -1,54 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn put_repository_snapshot<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, - snapshot: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn post_repository_snapshot<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, - snapshot: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/snapshot/create_repository.rs b/src/api/snapshot/create_repository.rs deleted file mode 100644 index 6cc72e2fc..000000000 --- a/src/api/snapshot/create_repository.rs +++ /dev/null @@ -1,48 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn post_repository<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn put_repository<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str(url_qry); - let res = - client.put(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/snapshot/delete.rs b/src/api/snapshot/delete.rs deleted file mode 100644 index c781730b3..000000000 --- a/src/api/snapshot/delete.rs +++ /dev/null @@ -1,27 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn delete_repository_snapshot<'a>(client: &'a mut Client, - req: &'a RequestParams, repository: &'a str, - snapshot: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/delete_repository.rs b/src/api/snapshot/delete_repository.rs deleted file mode 100644 index 4bb65a474..000000000 --- a/src/api/snapshot/delete_repository.rs +++ /dev/null @@ -1,24 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn delete_repository<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str(url_qry); - let res = client.delete(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/get.rs b/src/api/snapshot/get.rs deleted file mode 100644 index eeb35612e..000000000 --- a/src/api/snapshot/get.rs +++ /dev/null @@ -1,27 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get_repository_snapshot<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str, snapshot: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/get_repository.rs b/src/api/snapshot/get_repository.rs deleted file mode 100644 index af887fcf3..000000000 --- a/src/api/snapshot/get_repository.rs +++ /dev/null @@ -1,36 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 10 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/mod.rs b/src/api/snapshot/mod.rs deleted file mode 100644 index 59606b5c6..000000000 --- a/src/api/snapshot/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -pub mod delete; -pub mod delete_repository; -pub mod get_repository; -pub mod verify_repository; -pub mod restore; -pub mod get; -pub mod create; -pub mod status; -pub mod create_repository; diff --git a/src/api/snapshot/restore.rs b/src/api/snapshot/restore.rs deleted file mode 100644 index c014dd136..000000000 --- a/src/api/snapshot/restore.rs +++ /dev/null @@ -1,32 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn post_repository_snapshot<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, - snapshot: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + 9 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str("/_restore"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/snapshot/status.rs b/src/api/snapshot/status.rs deleted file mode 100644 index 5595ceb08..000000000 --- a/src/api/snapshot/status.rs +++ /dev/null @@ -1,57 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get_repository<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 8 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/_status"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get_repository_snapshot<'a>(client: &'a mut Client, req: &'a RequestParams, - repository: &'a str, snapshot: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 1 + 8 + repository.len() + - snapshot.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/"); - url_fmtd.push_str(snapshot); - url_fmtd.push_str("/_status"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 18 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/_status"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/snapshot/verify_repository.rs b/src/api/snapshot/verify_repository.rs deleted file mode 100644 index e71b5cf27..000000000 --- a/src/api/snapshot/verify_repository.rs +++ /dev/null @@ -1,29 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html -pub fn post_repository<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - repository: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 11 + 8 + repository.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_snapshot/"); - url_fmtd.push_str(repository); - url_fmtd.push_str("/_verify"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/suggest/mod.rs b/src/api/suggest/mod.rs deleted file mode 100644 index 19c3009e2..000000000 --- a/src/api/suggest/mod.rs +++ /dev/null @@ -1,72 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_suggest"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_suggest"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 9 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_suggest"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters.html -pub fn get_index<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 9 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_suggest"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/tasks/cancel.rs b/src/api/tasks/cancel.rs deleted file mode 100644 index 1ed71568d..000000000 --- a/src/api/tasks/cancel.rs +++ /dev/null @@ -1,43 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html -pub fn post_task_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, task_id: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + 8 + task_id.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_tasks/"); - url_fmtd.push_str(task_id); - url_fmtd.push_str("/_cancel"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html -pub fn post<'a, - I: Into>>(client: &'a mut Client, req: &'a RequestParams, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 15 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_tasks/_cancel"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/tasks/get.rs b/src/api/tasks/get.rs deleted file mode 100644 index 359101ad3..000000000 --- a/src/api/tasks/get.rs +++ /dev/null @@ -1,23 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html -pub fn get_task_id<'a>(client: &'a mut Client, req: &'a RequestParams, - task_id: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 8 + task_id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_tasks/"); - url_fmtd.push_str(task_id); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/tasks/list.rs b/src/api/tasks/list.rs deleted file mode 100644 index e3fb50ac1..000000000 --- a/src/api/tasks/list.rs +++ /dev/null @@ -1,20 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html -pub fn get<'a>(client: &'a mut Client, req: &'a RequestParams) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = String::with_capacity(base.len() + 7 + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/_tasks"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/tasks/mod.rs b/src/api/tasks/mod.rs deleted file mode 100644 index c5a94f8c8..000000000 --- a/src/api/tasks/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod get; -pub mod cancel; -pub mod list; diff --git a/src/api/termvectors/mod.rs b/src/api/termvectors/mod.rs deleted file mode 100644 index f1ce2dbc8..000000000 --- a/src/api/termvectors/mod.rs +++ /dev/null @@ -1,98 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html -pub fn get_index_type_id<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str, id: &'a str) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 13 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_termvectors"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 13 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_termvectors"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 13 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_termvectors"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html -pub fn get_index_type<'a>(client: &'a mut Client, req: &'a RequestParams, - index: &'a str, _type: &'a str) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 13 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_termvectors"); - url_fmtd.push_str(url_qry); - let res = client.get(&url_fmtd).headers(req.headers.to_owned()); - res.send() -} - diff --git a/src/api/update/mod.rs b/src/api/update/mod.rs deleted file mode 100644 index c8165f192..000000000 --- a/src/api/update/mod.rs +++ /dev/null @@ -1,34 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html -pub fn post_index_type_id<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, - index: &'a str, _type: &'a str, - id: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 1 + 8 + index.len() + - _type.len() + id.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/"); - url_fmtd.push_str(id); - url_fmtd.push_str("/_update"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/api/update_by_query/mod.rs b/src/api/update_by_query/mod.rs deleted file mode 100644 index ac3859eb3..000000000 --- a/src/api/update_by_query/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -use hyper::client::Client; -#[allow(unused_imports)] -use hyper::client::Body; -use hyper::client::response::Response; -use hyper::error::Result; - -use ::RequestParams; - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html -pub fn post_index_type<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - _type: &'a str, body: I) - -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 1 + 17 + index.len() + - _type.len() + url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/"); - url_fmtd.push_str(_type); - url_fmtd.push_str("/_update_by_query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - -/// https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html -pub fn post_index<'a, - I: Into>>(client: &'a mut Client, - req: &'a RequestParams, index: &'a str, - body: I) -> Result{ - let url_qry = &req.get_url_qry(); - let base = &req.base_url; - let mut url_fmtd = - String::with_capacity(base.len() + 1 + 17 + index.len() + - url_qry.len()); - url_fmtd.push_str(base); - url_fmtd.push_str("/"); - url_fmtd.push_str(index); - url_fmtd.push_str("/_update_by_query"); - url_fmtd.push_str(url_qry); - let res = - client.post(&url_fmtd).headers(req.headers.to_owned()).body(body.into()); - res.send() -} - diff --git a/src/lib.rs b/src/lib.rs index 965929d19..7c8ed226c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,14 +3,15 @@ //! A lightweight implementation of the Elasticsearch API based on the //! [`hyper`](http://hyper.rs/hyper/) HTTP client. //! -//! Each API endpoint is represented as its own function, so each possible http route gets its own function. +//! Each API endpoint is represented as its own function, +//! so each possible http route gets its own function. //! This library makes very few assumptions, leaving it up to you to decide what to invest your //! precious CPU cycles into. //! //! The entire API is generated from the official Elasticsearch spec, so it's always current. -//! +//! //! # Supported Versions -//! +//! //! `elastic_types` | Elasticsearch //! --------------- | ------------- //! `0.x` | `5.x` @@ -69,10 +70,10 @@ //! # fn main() { //! let mut client = hyper::Client::new(); //! let mut params = elastic::RequestParams::default() -//! .url_params(vec![ -//! ("q", "'my string'".to_owned()), -//! ("pretty", "true".to_owned()) -//! ]); +//! .url_params(vec![ +//! ("q", "'my string'".to_owned()), +//! ("pretty", "true".to_owned()) +//! ]); //! //! elastic::search::get_index_type(&mut client, ¶ms, "myindex", "mytype").unwrap(); //! # } @@ -94,24 +95,24 @@ //! let (mut client, params) = elastic::default(); //! //! elastic::search::post_index_type(&mut client, ¶ms, -//! "myindex", "mytype", &json_str!({ -//! "query": { -//! "filtered": { -//! "query": { -//! "match_all": {} -//! }, -//! "filter": { -//! "geo_distance": { -//! "distance": "20km", -//! "location": { -//! "lat": 37.776, -//! "lon": -122.41 -//! } -//! } -//! } -//! } -//! } -//! }) +//! "myindex", "mytype", &json_str!({ +//! "query": { +//! "filtered": { +//! "query": { +//! "match_all": {} +//! }, +//! "filter": { +//! "geo_distance": { +//! "distance": "20km", +//! "location": { +//! "lat": 37.776, +//! "lon": -122.41 +//! } +//! } +//! } +//! } +//! } +//! }) //! ).unwrap(); //! # } //! ``` @@ -126,8 +127,8 @@ //! //! ## [`elastic_types`](https://github.com/elastic-rs/elastic-types) //! -//! A library that implements the core datatypes in Elasticsearch documents and automatically generates -//! a json mapping from your Rust structures. +//! A library that implements the core datatypes in Elasticsearch +//! documents and automatically generates a json mapping from your Rust structures. //! //! ## [`json_str`](https://github.com/KodrAus/json_str) //! @@ -137,12 +138,17 @@ //! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) //! - [Github](https://github.com/elastic-rs/elastic-hyper) +extern crate elastic_requests; extern crate hyper; extern crate url; +use std::io::Cursor; +use std::borrow::Borrow; use std::collections::BTreeMap; -use hyper::header::Headers; -use hyper::header::ContentType; +use elastic_requests::*; +use hyper::error::Result; +use hyper::client::Response; +use hyper::header::{Headers, ContentType}; use url::form_urlencoded::Serializer; /// Misc parameters for any request. @@ -181,10 +187,10 @@ use url::form_urlencoded::Serializer; /// extern crate elastic_hyper as elastic; /// /// let params = elastic::RequestParams::default() -/// .url_params(vec![ -/// ("pretty", "true".to_owned()), -/// ("q", "*".to_owned()) -/// ]); +/// .url_params(vec![ +/// ("pretty", "true".to_owned()), +/// ("q", "*".to_owned()) +/// ]); /// ``` /// /// With a custom base url: @@ -197,69 +203,107 @@ use url::form_urlencoded::Serializer; /// ``` #[derive(Debug, Clone)] pub struct RequestParams { - /// Base url for Elasticsearch - pub base_url: String, - /// Simple key-value store for url query params. - pub url_params: BTreeMap<&'static str, String>, - /// The complete set of headers that will be sent with the request. - pub headers: Headers + /// Base url for Elasticsearch + pub base_url: String, + /// Simple key-value store for url query params. + pub url_params: BTreeMap<&'static str, String>, + /// The complete set of headers that will be sent with the request. + pub headers: Headers, } impl RequestParams { - /// Create a new container for request parameters. - /// - /// Attempts to add `ContentType::json` to the passed in `headers` param. - pub fn new>(base: T, mut headers: Headers) -> Self { - headers.set(ContentType::json()); + /// Create a new container for request parameters. + /// + /// Attempts to add `ContentType::json` to the passed in `headers` param. + pub fn new>(base: T, mut headers: Headers) -> Self { + headers.set(ContentType::json()); - RequestParams { - base_url: base.into(), - headers: headers, - url_params: BTreeMap::new() - } - } + RequestParams { + base_url: base.into(), + headers: headers, + url_params: BTreeMap::new(), + } + } - /// Add a collection of url params. - pub fn url_params(mut self, url_params: I) -> Self - where I: IntoIterator { - for (k, v) in url_params { - self.url_params.insert(k, v); - } + /// Add a collection of url params. + pub fn url_params(mut self, url_params: I) -> Self + where I: IntoIterator + { + for (k, v) in url_params { + self.url_params.insert(k, v); + } - self - } + self + } - /// Get the url params as a formatted string. - /// - /// Follows the `application/x-www-form-urlencoded` format. - pub fn get_url_qry(&self) -> String { - if self.url_params.len() > 0 { - let qry: String = Serializer::new(String::new()) - .extend_pairs(self.url_params.iter()) - .finish(); - let mut url_qry = String::with_capacity(qry.len() + 1); + /// Get the url params as a formatted string. + /// + /// Follows the `application/x-www-form-urlencoded` format. + pub fn get_url_qry(&self) -> String { + if self.url_params.len() > 0 { + let qry: String = Serializer::new(String::new()) + .extend_pairs(self.url_params.iter()) + .finish(); + let mut url_qry = String::with_capacity(qry.len() + 1); - url_qry.push('?'); - url_qry.push_str(&qry); + url_qry.push('?'); + url_qry.push_str(&qry); - url_qry - } - else { - String::with_capacity(0) - } - } + url_qry + } else { + String::with_capacity(0) + } + } } impl Default for RequestParams { - fn default() -> Self { - RequestParams::new("http://localhost:9200", Headers::new()) - } + fn default() -> Self { + RequestParams::new("http://localhost:9200", Headers::new()) + } } -mod api; -pub use api::*; - /// Get a default `Client` and `RequestParams`. pub fn default() -> (hyper::Client, RequestParams) { - (hyper::Client::new(), RequestParams::default()) + (hyper::Client::new(), RequestParams::default()) +} + +macro_rules! req_with_body { + ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ + let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); + let body: &[u8] = (*body).borrow(); + let mut cursor = Cursor::new(body); + + $client.$method(&$url).headers($params.headers.to_owned()).body(&mut cursor).send() + }) +} + +/// Represents a client that can send Elasticsearch requests. +pub trait ElasticClient { + /// Send a request and get a response. + fn request<'a, I>(&self, params: &RequestParams, req: I) -> Result where I: Into>; +} + +impl ElasticClient for hyper::Client { + fn request<'a, I>(&self, params: &RequestParams, req: I) -> Result + where I: Into> + { + let req = req.into(); + + let qry = ¶ms.get_url_qry(); + + let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry.len()); + + url.push_str(¶ms.base_url); + url.push_str(&req.url); + url.push_str(qry); + + match req.method { + HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), + HttpMethod::Post => req_with_body!(self, url, req, params, post), + HttpMethod::Head => self.head(&url).headers(params.headers.to_owned()).send(), + HttpMethod::Delete => self.delete(&url).headers(params.headers.to_owned()).send(), + HttpMethod::Put => req_with_body!(self, url, req, params, put), + HttpMethod::Patch => req_with_body!(self, url, req, params, patch), + } + } } From cc13724295a13c46ae7013bf384c0383cc24014e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 12 Dec 2016 20:54:52 +1000 Subject: [PATCH 009/127] update basic sample --- samples/basic/Cargo.toml | 3 +- samples/basic/src/main.rs | 41 ++++++++++------------- src/lib.rs | 68 ++++++++++++++++++++------------------- 3 files changed, 54 insertions(+), 58 deletions(-) diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index 4d32086ac..0bf5d3ee0 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Ashley Mannix "] nightly-testing = [] [dependencies] -elastic_hyper = "~0.3.0" +elastic_hyper = { version = "*", path = "../../" } +elastic_requests = { version = "*", git = "https://github.com/elastic-rs/elastic-requests" } json_str = "*" hyper = "~0.9.0" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 8ab5df07e..4d95ba5b9 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -8,36 +8,29 @@ #[macro_use] extern crate json_str; extern crate hyper; -extern crate elastic_hyper as elastic; +extern crate elastic_hyper; +extern crate elastic_requests as requests; +use elastic_hyper::{ElasticClient, RequestParams}; use hyper::client::Client; use std::io::Read; fn main() { - //Create a hyper client. - //We specify `pretty` on requests to make them more readable. - let mut client = Client::new(); - let params = elastic::RequestParams::default() - .url_params(vec![ - ("pretty", "true".to_owned()) - ]); + let cli = Client::new(); + let params = RequestParams::default().url_params(vec![("pretty", "true".to_owned())]); - //Execute a HTTP Post search request. - //Other variants include post_index, post_index_type. - let mut res = elastic::search::post( - &mut client, ¶ms, - &json_str!({ - query: { - query_string: { - query: "*" - } - } - }) - ).unwrap(); + let body = json_str!({ + query: { + query_string: { + query: "*" + } + } + }); - //Deserialisation goes here. - let mut message = String::new(); - let _ = res.read_to_string(&mut message); + let mut res = cli.elastic_req(¶ms, requests::SearchRequest::index("_all", body)).unwrap(); - println!("Got response: {}", message); + let mut message = String::new(); + res.read_to_string(&mut message).unwrap(); + + println!("Got response: {}", message); } diff --git a/src/lib.rs b/src/lib.rs index 7c8ed226c..887b998d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,10 +70,10 @@ //! # fn main() { //! let mut client = hyper::Client::new(); //! let mut params = elastic::RequestParams::default() -//! .url_params(vec![ -//! ("q", "'my string'".to_owned()), -//! ("pretty", "true".to_owned()) -//! ]); +//! .url_params(vec![ +//! ("q", "'my string'".to_owned()), +//! ("pretty", "true".to_owned()) +//! ]); //! //! elastic::search::get_index_type(&mut client, ¶ms, "myindex", "mytype").unwrap(); //! # } @@ -95,24 +95,24 @@ //! let (mut client, params) = elastic::default(); //! //! elastic::search::post_index_type(&mut client, ¶ms, -//! "myindex", "mytype", &json_str!({ -//! "query": { -//! "filtered": { -//! "query": { -//! "match_all": {} -//! }, -//! "filter": { -//! "geo_distance": { -//! "distance": "20km", -//! "location": { -//! "lat": 37.776, -//! "lon": -122.41 -//! } -//! } -//! } -//! } -//! } -//! }) +//! "myindex", "mytype", &json_str!({ +//! "query": { +//! "filtered": { +//! "query": { +//! "match_all": {} +//! }, +//! "filter": { +//! "geo_distance": { +//! "distance": "20km", +//! "location": { +//! "lat": 37.776, +//! "lon": -122.41 +//! } +//! } +//! } +//! } +//! } +//! }) //! ).unwrap(); //! # } //! ``` @@ -187,10 +187,10 @@ use url::form_urlencoded::Serializer; /// extern crate elastic_hyper as elastic; /// /// let params = elastic::RequestParams::default() -/// .url_params(vec![ -/// ("pretty", "true".to_owned()), -/// ("q", "*".to_owned()) -/// ]); +/// .url_params(vec![ +/// ("pretty", "true".to_owned()), +/// ("q", "*".to_owned()) +/// ]); /// ``` /// /// With a custom base url: @@ -269,22 +269,24 @@ pub fn default() -> (hyper::Client, RequestParams) { macro_rules! req_with_body { ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ - let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body: &[u8] = (*body).borrow(); - let mut cursor = Cursor::new(body); + let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - $client.$method(&$url).headers($params.headers.to_owned()).body(&mut cursor).send() - }) + let body: &[u8] = (*body).borrow(); + let mut cursor = Cursor::new(body); + + $client.$method(&$url).headers($params.headers.to_owned()).body(&mut cursor).send() + }) } /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. - fn request<'a, I>(&self, params: &RequestParams, req: I) -> Result where I: Into>; + fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result + where I: Into>; } impl ElasticClient for hyper::Client { - fn request<'a, I>(&self, params: &RequestParams, req: I) -> Result + fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result where I: Into> { let req = req.into(); From cab59b04ce34a954c278d6d430aa51fd20a33212 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 19 Dec 2016 20:02:04 +1000 Subject: [PATCH 010/127] update docs --- src/lib.rs | 86 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 887b998d1..607d6eead 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,7 @@ //! //! ```ignore //! [dependencies] +//! elastic_requests = "*" //! elastic_hyper = "*" //! hyper = "*" //! ``` @@ -31,6 +32,7 @@ //! //! ```ignore //! [dependencies] +//! elastic_requests = "*" //! elastic_hyper = { version = "*", default-features = false } //! hyper = { version = "*", default-features = false } //! ``` @@ -38,7 +40,8 @@ //! Then reference in your crate root: //! //! ```ignore -//! extern crate elastic_hyper as elastic; +//! extern crate elastic_requests as req; +//! extern crate elastic_hyper as cli; //! extern crate hyper; //! ``` //! @@ -50,11 +53,15 @@ //! //HTTP HEAD / //! //! # extern crate hyper; -//! # extern crate elastic_hyper as elastic; +//! # extern crate elastic_requests as req; +//! # extern crate elastic_hyper as cli; +//! use cli::ElasticClient; +//! use req::PingRequest; +//! //! # fn main() { -//! let (mut client, params) = elastic::default(); +//! let (client, params) = cli::default(); //! -//! elastic::ping::head(&mut client, ¶ms).unwrap(); +//! client.elastic_req(¶ms, PingRequest::new()).unwrap(); //! # } //! ``` //! @@ -66,16 +73,25 @@ //! //HTTP GET /myindex/mytype/_search?q='my string' //! //! # extern crate hyper; -//! # extern crate elastic_hyper as elastic; +//! # extern crate elastic_requests as req; +//! # extern crate elastic_hyper as cli; +//! use cli::{ ElasticClient, RequestParams }; +//! use req::SimpleSearchRequest; +//! //! # fn main() { -//! let mut client = hyper::Client::new(); -//! let mut params = elastic::RequestParams::default() +//! let client = hyper::Client::new(); +//! +//! let params = RequestParams::default() //! .url_params(vec![ //! ("q", "'my string'".to_owned()), //! ("pretty", "true".to_owned()) //! ]); //! -//! elastic::search::get_index_type(&mut client, ¶ms, "myindex", "mytype").unwrap(); +//! let search = SimpleSearchRequest::for_index_ty( +//! "myindex", "mytype" +//! ); +//! +//! client.elastic_req(¶ms, search).unwrap(); //! # } //! ``` //! @@ -90,30 +106,38 @@ //! # #[macro_use] //! # extern crate json_str; //! # extern crate hyper; -//! # extern crate elastic_hyper as elastic; +//! # extern crate elastic_requests as req; +//! # extern crate elastic_hyper as cli; +//! use cli::ElasticClient; +//! use req::SearchRequest; +//! //! # fn main() { -//! let (mut client, params) = elastic::default(); -//! -//! elastic::search::post_index_type(&mut client, ¶ms, -//! "myindex", "mytype", &json_str!({ -//! "query": { -//! "filtered": { -//! "query": { -//! "match_all": {} -//! }, -//! "filter": { -//! "geo_distance": { -//! "distance": "20km", -//! "location": { -//! "lat": 37.776, -//! "lon": -122.41 -//! } -//! } -//! } -//! } -//! } -//! }) -//! ).unwrap(); +//! let (client, params) = cli::default(); +//! +//! +//! let search = SearchRequest::for_index_ty( +//! "myindex", "mytype", +//! json_str!({ +//! query: { +//! filtered: { +//! query: { +//! match_all: {} +//! }, +//! filter: { +//! geo_distance: { +//! distance: "20km", +//! location: { +//! lat: 37.776, +//! lon: -122.41 +//! } +//! } +//! } +//! } +//! } +//! }) +//! ); +//! +//! client.elastic_req(¶ms, search).unwrap(); //! # } //! ``` //! From 24d760d6390feef6354b0e2bc0e3412745bba14b Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 15:01:13 +1000 Subject: [PATCH 011/127] avoid string alloc on none qry --- src/lib.rs | 15 +++++++++------ tests/mod.rs | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 607d6eead..1fd25d06c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -263,7 +263,7 @@ impl RequestParams { /// Get the url params as a formatted string. /// /// Follows the `application/x-www-form-urlencoded` format. - pub fn get_url_qry(&self) -> String { + pub fn get_url_qry(&self) -> (usize, Option) { if self.url_params.len() > 0 { let qry: String = Serializer::new(String::new()) .extend_pairs(self.url_params.iter()) @@ -273,9 +273,9 @@ impl RequestParams { url_qry.push('?'); url_qry.push_str(&qry); - url_qry + (url_qry.len(), Some(url_qry)) } else { - String::with_capacity(0) + (0, None) } } } @@ -315,13 +315,16 @@ impl ElasticClient for hyper::Client { { let req = req.into(); - let qry = ¶ms.get_url_qry(); + let (qry_len, qry) = params.get_url_qry(); - let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry.len()); + let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry_len); url.push_str(¶ms.base_url); url.push_str(&req.url); - url.push_str(qry); + + if let Some(qry) = qry { + url.push_str(&qry); + } match req.method { HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), diff --git a/tests/mod.rs b/tests/mod.rs index a10a84890..3999cdf8f 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -27,12 +27,12 @@ fn request_params_has_url_query() { ("q", "*".to_owned()) ]); - assert_eq!("?pretty=true&q=*", &req.get_url_qry()); + assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); } #[test] fn empty_request_params_returns_empty_string() { let req = RequestParams::default(); - assert_eq!("", &req.get_url_qry()); + assert_eq!((0, None), req.get_url_qry()); } \ No newline at end of file From 8d7fbbd02bac860da41a88664def6ae1c3e8423b Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 15:24:40 +1000 Subject: [PATCH 012/127] update to elastic_requests 0.1.0 --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 502b09ffc..21ce9da87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,16 +4,16 @@ version = "0.4.0" authors = ["Ashley Mannix "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on Hyper." -documentation = "https://docs.rs/elastic_types/0.3.2/elastic_hyper/" +documentation = "https://docs.rs/elastic_types/0.4.0/elastic_hyper/" repository = "https://github.com/elastic-rs/elastic-hyper" -exclude = [ "samples", "codegen" ] +exclude = [ "samples" ] [features] default = [ "ssl" ] ssl = [ "hyper/ssl" ] [dependencies] -elastic_requests = { version = "*", git = "https://github.com/elastic-rs/elastic-requests" } +elastic_requests = "~0.1.0" hyper = { version = "~0.9.0", default-features = false } url = "~1.1.0" From 1552b8df37df2d109ceaf41363cbf2d7251107af Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 16:13:51 +1000 Subject: [PATCH 013/127] update samples --- .travis.yml | 5 + samples/basic/Cargo.toml | 2 +- samples/basic/src/main.rs | 7 +- samples/typed/Cargo.toml | 9 +- samples/typed/src/main.rs | 186 +++++++++++++++++++--------------- samples/typed/src/response.rs | 27 ++--- 6 files changed, 133 insertions(+), 103 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9467c1d0..14472bf64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,11 @@ script: travis-cargo build && travis-cargo test && travis-cargo bench && + cd samples/basic && + travis-cargo build && + cd ../typed && + travis-cargo build && + cd ../../ && travis-cargo --only stable doc after_success: - travis-cargo --only stable doc-upload \ No newline at end of file diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index 0bf5d3ee0..506985705 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -8,6 +8,6 @@ nightly-testing = [] [dependencies] elastic_hyper = { version = "*", path = "../../" } -elastic_requests = { version = "*", git = "https://github.com/elastic-rs/elastic-requests" } +elastic_requests = "*" json_str = "*" hyper = "~0.9.0" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 4d95ba5b9..e31a06678 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -9,15 +9,16 @@ extern crate json_str; extern crate hyper; extern crate elastic_hyper; -extern crate elastic_requests as requests; +extern crate elastic_requests; use elastic_hyper::{ElasticClient, RequestParams}; +use elastic_requests::SearchRequest; use hyper::client::Client; use std::io::Read; fn main() { let cli = Client::new(); - let params = RequestParams::default().url_params(vec![("pretty", "true".to_owned())]); + let params = RequestParams::default().url_params(vec![("pretty", String::from("true"))]); let body = json_str!({ query: { @@ -27,7 +28,7 @@ fn main() { } }); - let mut res = cli.elastic_req(¶ms, requests::SearchRequest::index("_all", body)).unwrap(); + let mut res = cli.elastic_req(¶ms, SearchRequest::for_index("_all", body)).unwrap(); let mut message = String::new(); res.read_to_string(&mut message).unwrap(); diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index fe0744408..21f36d94d 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -7,11 +7,12 @@ authors = ["Ashley Mannix "] nightly-testing = [] [dependencies] +hyper = "~0.9.0" elastic_hyper = { version = "*", path = "../../" } +elastic_requests = "*" +elastic_types = { version = "*", features = ["nightly"]} +elastic_types_derive = "*" json_str = { version = "*", features = ["nightly"]} -hyper = "~0.9.0" -elastic_types = { version = "*", path = "../../../types", features = ["nightly"]} -elastic_types_macros = { version = "*", path = "../../../macros/types" } serde = "~0.8.0" -serde_macros = "~0.8.0" +serde_derive = "~0.8.0" serde_json = "~0.8.0" diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index dc7ff3f30..c1368c2d3 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -5,126 +5,146 @@ //! This sample executes a simple search request against some indexed data. //! The data is provided by a struct with mapping generated by `elastic_types`. -#![feature(plugin, custom_derive)] -#![plugin(serde_macros, elastic_types_macros, json_str)] +#![feature(plugin, proc_macro)] +#![plugin(json_str)] extern crate serde; extern crate serde_json; +extern crate hyper; + +#[macro_use] +extern crate serde_derive; +#[macro_use] +extern crate elastic_types_derive; + #[macro_use] extern crate elastic_types; -extern crate hyper; -extern crate elastic_hyper as elastic; +extern crate elastic_hyper; +extern crate elastic_requests; use std::net::Ipv4Addr; -use std::{ thread, time }; + +use serde_json::{Value, Map}; + use hyper::Client; -use elastic::RequestParams; +use elastic_hyper::{ElasticClient, RequestParams}; +use elastic_requests::{IndicesCreateRequest, IndexRequest, SearchRequest}; use elastic_types::prelude::*; mod response; use response::*; -//The type we want to index in Elasticsearch +// The type we want to index in Elasticsearch #[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] pub struct MyStruct { - pub id: i32, - pub title: String, - pub timestamp: Date, - pub geo: GeoLocation + pub id: i32, + pub title: String, + pub timestamp: Date, + pub geo: GeoLocation, } #[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] pub struct GeoLocation { - pub ip: Ipv4Addr, - pub loc: GeoPoint + pub ip: Ipv4Addr, + pub loc: GeoPoint, } const INDEX: &'static str = "testidx"; fn main() { - //Create a hyper client - let (mut client, params) = elastic::default(); + // Create a hyper client + let client = Client::new(); + + // Default request parameters + let params = RequestParams::default(); - //Create an index and map our type - create_index(&mut client, ¶ms); + // Wait for refresh when indexing data. + // Normally this isn't a good idea, but is ok for this example. + let index_params = RequestParams::default().url_params(vec![("refresh", String::from("true"))]); - //Index some objects. For lots of data, prefer the `bulk` mod - for t in get_data() { - index_datum(&mut client, ¶ms, &t); - } + // Create an index and map our type + create_index(&client, ¶ms); - //NOTE: Elasticsearch is _near_ realtime, so results aren't guaranteed to show up right away - thread::sleep(time::Duration::from_secs(2)); + // Index some objects. + // For lots of data, prefer the `BulkRequest` + for t in get_data() { + index_datum(&client, &index_params, &t); + } - //Perform a search request and deserialise to `SearchResponse` - let res = query(&mut client, ¶ms); + // Perform a search request and deserialise to `SearchResponse`. + let res = query(&client, ¶ms); - println!("results: {}", res.hits.total); - for hit in res.hits.hits { - if let Some(hit) = hit.source { - println!("hit: {:?}", hit); - } - } + println!("results: {}", res.hits.total); + + for hit in res.hits.hits { + if let Some(hit) = hit.source { + println!("hit: {:?}", hit); + } + } } -fn create_index(client: &mut Client, params: &RequestParams) { - //Create index - let _ = elastic::indices::create::put_index(client, ¶ms, INDEX, "").unwrap(); - - //Put mapping for MyStruct - let _ = elastic::indices::put_mapping::put_index_type(client, ¶ms, - //Index and type - INDEX, MyStruct::name(), - //Serialised mapping - &TypeMapper::to_string(MyStruct::mapping()).unwrap() - ).unwrap(); +fn create_index(client: &Client, params: &RequestParams) { + // Create a dynamic structure for the mappings body + let mut body = Map::new(); + body.insert(String::from("mappings"), { + let mut mappings = Map::new(); + + mappings.insert(String::from(MyStruct::name()), + TypeMapper::to_value(MyStruct::mapping()).unwrap()); + + Value::Object(mappings) + }); + + let body = Value::Object(body); + + let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&body).unwrap()); + + // Create index + client.elastic_req(¶ms, req).unwrap(); } fn get_data() -> Vec { - vec![ - MyStruct { - id: 1, - title: String::from("Some Title"), - timestamp: Date::now(), - geo: GeoLocation { - ip: Ipv4Addr::new(10, 0, 0, 1), - loc: GeoPoint::build(-71.34, 41.12) - } - }, - MyStruct { - id: 2, - title: String::from("Some Other Title"), - timestamp: Date::now(), - geo: GeoLocation { - ip: Ipv4Addr::new(10, 0, 0, 2), - loc: GeoPoint::build(-71.34, 41.12) - } - } - ] + vec![MyStruct { + id: 1, + title: String::from("Some Title"), + timestamp: Date::now(), + geo: GeoLocation { + ip: Ipv4Addr::new(10, 0, 0, 1), + loc: GeoPoint::build(-71.34, 41.12), + }, + }, + MyStruct { + id: 2, + title: String::from("Some Other Title"), + timestamp: Date::now(), + geo: GeoLocation { + ip: Ipv4Addr::new(10, 0, 0, 2), + loc: GeoPoint::build(-71.34, 41.12), + }, + }] } -fn index_datum(client: &mut Client, params: &RequestParams, datum: &MyStruct) { - let _ = elastic::index::put_index_type_id(client, ¶ms, - //Index, type and id - INDEX, MyStruct::name(), &datum.id.to_string(), - //Serialised data - &serde_json::to_string(&datum).unwrap() - ).unwrap(); +fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { + let req = IndexRequest::for_index_ty_id(INDEX, + MyStruct::name(), + datum.id.to_string(), + serde_json::to_string(&datum).unwrap()); + + client.elastic_req(¶ms, req).unwrap(); } -fn query(client: &mut Client, params: &RequestParams) -> SearchResponse { - serde_json::de::from_reader( - elastic::search::post_index_type(client, ¶ms, - //Index and type - INDEX, MyStruct::name(), - //Query - json_lit!({ - query: { - query_string: { - query: "*" - } +fn query(client: &Client, params: &RequestParams) -> SearchResponse { + let req = SearchRequest::for_index_ty(INDEX, + MyStruct::name(), + json_lit!({ + query: { + query_string: { + query: "*" } - }) - ).unwrap() - ).unwrap() + } + })); + + let res = client.elastic_req(¶ms, req).unwrap(); + + serde_json::de::from_reader(res).unwrap() } diff --git a/samples/typed/src/response.rs b/samples/typed/src/response.rs index e904020ef..6cbb37598 100644 --- a/samples/typed/src/response.rs +++ b/samples/typed/src/response.rs @@ -1,11 +1,12 @@ -//NOTE: This module lives here until we have a proper crate for Elasticsearch responses +// NOTE: This module lives here until we have a proper crate for Elasticsearch responses use serde::Deserialize; /// A successful response from a Query DSL query. #[derive(Debug, Deserialize)] -pub struct SearchResponse where -T: Deserialize { +pub struct SearchResponse + where T: Deserialize +{ /// The time taken to complete a query in ms. pub took: u64, /// Whether or not the query timed out. @@ -14,7 +15,7 @@ T: Deserialize { #[serde(rename="_shards")] pub shards: Shards, /// Document results. - pub hits: SearchHits + pub hits: SearchHits, } /// Metadata on shard activity for a Query DSL query. @@ -25,23 +26,25 @@ pub struct Shards { /// The total number of shards that successfully executed the query. pub successful: u64, /// The total number of shards that failed to execute the query. - pub failed: u64 + pub failed: u64, } /// A collection of hits for a Query DSL query. #[derive(Debug, Deserialize)] -pub struct SearchHits where -T: Deserialize { +pub struct SearchHits + where T: Deserialize +{ /// The total number of hits. pub total: u64, /// Document results. - pub hits: Vec> + pub hits: Vec>, } /// An individual hit for a Query DSL query. #[derive(Debug, Deserialize)] -pub struct Hit where -T: Deserialize { +pub struct Hit + where T: Deserialize +{ /// The index of the hit. #[serde(rename="_index")] pub index: String, @@ -62,5 +65,5 @@ T: Deserialize { pub timestamp: Option, /// The routing value of the hit. #[serde(rename="_routing")] - pub routing: Option -} \ No newline at end of file + pub routing: Option, +} From 2eeceb32ebf6a7d78ba773b66733c9df17805c3e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 16:15:39 +1000 Subject: [PATCH 014/127] only build typed sample on nightly --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 14472bf64..a37a7b200 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: cd samples/basic && travis-cargo build && cd ../typed && - travis-cargo build && + travis-cargo --only nightly build && cd ../../ && travis-cargo --only stable doc after_success: From 0a2000c3541a932b18476570170b951c0a3852e9 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 16:28:18 +1000 Subject: [PATCH 015/127] update typed sample --- samples/typed/src/data.rs | 31 ++++++++++++++++++++++++++ samples/typed/src/main.rs | 47 ++++++++------------------------------- 2 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 samples/typed/src/data.rs diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs new file mode 100644 index 000000000..d3815e96f --- /dev/null +++ b/samples/typed/src/data.rs @@ -0,0 +1,31 @@ +use std::net::Ipv4Addr; +use serde::Serializer; +use elastic_types::prelude::*; + +// The type we want to index in Elasticsearch +#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] +pub struct MyStruct { + pub id: i32, + pub title: String, + pub timestamp: Date, + pub geo: GeoLocation, +} + +#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] +pub struct GeoLocation { + pub ip: Ipv4Addr, + pub loc: GeoPoint, +} + +// An index request type with mappings bundled in +#[derive(Default, Serialize)] +pub struct Index { + #[serde(serialize_with = "serialise_mappings")] + mappings: (), +} + +fn serialise_mappings(_: &(), serializer: &mut S) -> Result<(), S::Error> + where S: Serializer +{ + TypeMapper::to_writer(MyStruct::mapping(), serializer) +} diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index c1368c2d3..321e29a2c 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -23,32 +23,16 @@ extern crate elastic_hyper; extern crate elastic_requests; use std::net::Ipv4Addr; - -use serde_json::{Value, Map}; - use hyper::Client; use elastic_hyper::{ElasticClient, RequestParams}; use elastic_requests::{IndicesCreateRequest, IndexRequest, SearchRequest}; use elastic_types::prelude::*; +mod data; +use data::*; mod response; use response::*; -// The type we want to index in Elasticsearch -#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] -pub struct MyStruct { - pub id: i32, - pub title: String, - pub timestamp: Date, - pub geo: GeoLocation, -} - -#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] -pub struct GeoLocation { - pub ip: Ipv4Addr, - pub loc: GeoPoint, -} - const INDEX: &'static str = "testidx"; fn main() { @@ -84,20 +68,7 @@ fn main() { } fn create_index(client: &Client, params: &RequestParams) { - // Create a dynamic structure for the mappings body - let mut body = Map::new(); - body.insert(String::from("mappings"), { - let mut mappings = Map::new(); - - mappings.insert(String::from(MyStruct::name()), - TypeMapper::to_value(MyStruct::mapping()).unwrap()); - - Value::Object(mappings) - }); - - let body = Value::Object(body); - - let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&body).unwrap()); + let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&Index::default()).unwrap()); // Create index client.elastic_req(¶ms, req).unwrap(); @@ -137,12 +108,12 @@ fn query(client: &Client, params: &RequestParams) -> SearchResponse { let req = SearchRequest::for_index_ty(INDEX, MyStruct::name(), json_lit!({ - query: { - query_string: { - query: "*" - } - } - })); + query: { + query_string: { + query: "*" + } + } + })); let res = client.elastic_req(¶ms, req).unwrap(); From 40a695faae1c9c53e24aa85e48f8131d96d07bfb Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 16:39:53 +1000 Subject: [PATCH 016/127] update readme --- README.md | 65 +++++++++++++++++++++++++++++++++++++----------------- src/lib.rs | 1 - 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 929a7da15..a2f880cf2 100644 --- a/README.md +++ b/README.md @@ -30,39 +30,64 @@ Add `elastic_hyper` and `json_str` to your `Cargo.toml`: ``` [dependencies] +elastic_requests = "*" elastic_hyper = "*" +hyper = "*" + +# Optional json_str = "*" ``` Ping the availability of your cluster: ```rust -#[macro_use] -extern crate json_str; -extern crate elastic_hyper as elastic; +extern crate elastic_requests as req; +extern crate elastic_hyper as cli; +extern crate hyper; + +use cli::ElasticClient; +use req::PingRequest; -let (mut client, params) = elastic::default(); +let (client, params) = cli::default(); -elastic::ping::head(&mut client, ¶ms).unwrap(); +client.elastic_req(¶ms, PingRequest::new()).unwrap(); ``` -A simple `query_string` query: +A query DSL query: ```rust #[macro_use] extern crate json_str; -extern crate elastic_hyper as elastic; - -let (mut client, params) = elastic::default(); - -let response = elastic::search::post( - &mut client, ¶ms, - &json_str!({ - query: { - query_string: { - query: "*" - } - } - }) -).unwrap(); +extern crate elastic_requests as req; +extern crate elastic_hyper as cli; +extern crate hyper; + +use cli::ElasticClient; +use req::SearchRequest; + +let (client, params) = cli::default(); + +let search = SearchRequest::for_index_ty( + "myindex", "mytype", + json_str!({ + query: { + filtered: { + query: { + match_all: {} + }, + filter: { + geo_distance: { + distance: "20km", + location: { + lat: 37.776, + lon: -122.41 + } + } + } + } + } + }) +); + +client.elastic_req(¶ms, search).unwrap(); ``` \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 1fd25d06c..73ff7dc5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,6 @@ //! # fn main() { //! let (client, params) = cli::default(); //! -//! //! let search = SearchRequest::for_index_ty( //! "myindex", "mytype", //! json_str!({ From 7096e72f498f787f7c46b38dc60aa2f159b98f14 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 21 Dec 2016 17:21:19 +1000 Subject: [PATCH 017/127] fix data mapping --- samples/typed/src/data.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs index d3815e96f..466719471 100644 --- a/samples/typed/src/data.rs +++ b/samples/typed/src/data.rs @@ -1,5 +1,5 @@ use std::net::Ipv4Addr; -use serde::Serializer; +use serde::ser::{Serializer, Error}; use elastic_types::prelude::*; // The type we want to index in Elasticsearch @@ -27,5 +27,11 @@ pub struct Index { fn serialise_mappings(_: &(), serializer: &mut S) -> Result<(), S::Error> where S: Serializer { - TypeMapper::to_writer(MyStruct::mapping(), serializer) + let mut state = serializer.serialize_struct("mappings", 1)?; + + let mapping = TypeMapper::to_value(MyStruct::mapping()).map_err(|e| S::Error::custom("failed to build mapping"))?; + + serializer.serialize_struct_elt(&mut state, MyStruct::name(), mapping)?; + + serializer.serialize_struct_end(state) } From 21480b3f5cf220300af25b29b1b17bf38c6d54a8 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 22 Dec 2016 11:27:56 +1000 Subject: [PATCH 018/127] update typed sample --- samples/typed/src/data.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs index 466719471..f51d4383e 100644 --- a/samples/typed/src/data.rs +++ b/samples/typed/src/data.rs @@ -20,18 +20,10 @@ pub struct GeoLocation { // An index request type with mappings bundled in #[derive(Default, Serialize)] pub struct Index { - #[serde(serialize_with = "serialise_mappings")] - mappings: (), + mappings: Mappings, } -fn serialise_mappings(_: &(), serializer: &mut S) -> Result<(), S::Error> - where S: Serializer -{ - let mut state = serializer.serialize_struct("mappings", 1)?; - - let mapping = TypeMapper::to_value(MyStruct::mapping()).map_err(|e| S::Error::custom("failed to build mapping"))?; - - serializer.serialize_struct_elt(&mut state, MyStruct::name(), mapping)?; - - serializer.serialize_struct_end(state) -} +#[derive(Default, Serialize)] +struct Mappings { + mystruct: Type +} \ No newline at end of file From d3bb4496424e0ed72715af09e531f804a04b4d5c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 22 Dec 2016 12:03:59 +1000 Subject: [PATCH 019/127] use TypeMapping struct --- samples/typed/src/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs index f51d4383e..32c556758 100644 --- a/samples/typed/src/data.rs +++ b/samples/typed/src/data.rs @@ -25,5 +25,5 @@ pub struct Index { #[derive(Default, Serialize)] struct Mappings { - mystruct: Type + mystruct: TypeMapping } \ No newline at end of file From 185d40b3e6e7946360b0146835bebf7591fa9980 Mon Sep 17 00:00:00 2001 From: Stephan Buys Date: Tue, 27 Dec 2016 07:23:10 +0200 Subject: [PATCH 020/127] Port to reqwest --- .gitignore | 3 +- Cargo.toml | 22 ++++---- samples/basic/Cargo.toml | 2 +- samples/basic/src/main.rs | 14 ++--- samples/typed/Cargo.toml | 4 +- samples/typed/src/main.rs | 12 ++--- src/lib.rs | 104 ++++++++++++++++---------------------- tests/mod.rs | 9 ++-- 8 files changed, 77 insertions(+), 93 deletions(-) diff --git a/.gitignore b/.gitignore index b7f386575..381a7d4f9 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ Cargo.lock *.suo /target/ -/obj/ \ No newline at end of file +/obj/ +.idea diff --git a/Cargo.toml b/Cargo.toml index 21ce9da87..ca6367323 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,21 @@ [package] -name = "elastic_hyper" -version = "0.4.0" +name = "elastic_reqwest" +version = "0.1.0" authors = ["Ashley Mannix "] license = "Apache-2.0" -description = "A lightweight implementation of the Elasticsearch API based on Hyper." -documentation = "https://docs.rs/elastic_types/0.4.0/elastic_hyper/" -repository = "https://github.com/elastic-rs/elastic-hyper" +description = "A lightweight implementation of the Elasticsearch API based on Reqwest, derived from elastic-hyper." +#documentation = "https://docs.rs/elastic_types/0.4.0/elastic_hyper/" +#repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] -[features] -default = [ "ssl" ] -ssl = [ "hyper/ssl" ] +#[features] +#default = [ "ssl" ] +#ssl = [ "hyper/ssl" ] [dependencies] elastic_requests = "~0.1.0" -hyper = { version = "~0.9.0", default-features = false } -url = "~1.1.0" +reqwest = "*" +url = "*" [dev-dependencies] -json_str = "^0.*" +json_str = "*" diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index 506985705..e0b1a4321 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Ashley Mannix "] nightly-testing = [] [dependencies] -elastic_hyper = { version = "*", path = "../../" } +elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" json_str = "*" hyper = "~0.9.0" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index e31a06678..d544208db 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -1,4 +1,4 @@ -//! Elasticsearch Hyper Client Samples +//! Elasticsearch Reqwest Client Samples //! //! This sample assumes you have a node running on `localhost`. //! @@ -7,17 +7,17 @@ #[macro_use] extern crate json_str; -extern crate hyper; -extern crate elastic_hyper; +extern crate elastic_reqwest; extern crate elastic_requests; -use elastic_hyper::{ElasticClient, RequestParams}; +use elastic_reqwest::{ElasticClient, RequestParams}; use elastic_requests::SearchRequest; -use hyper::client::Client; use std::io::Read; fn main() { - let cli = Client::new(); + + let (client, _) = elastic_reqwest::default(); + let params = RequestParams::default().url_params(vec![("pretty", String::from("true"))]); let body = json_str!({ @@ -28,7 +28,7 @@ fn main() { } }); - let mut res = cli.elastic_req(¶ms, SearchRequest::for_index("_all", body)).unwrap(); + let mut res = client.elastic_req(¶ms, SearchRequest::for_index("_all", body)).unwrap(); let mut message = String::new(); res.read_to_string(&mut message).unwrap(); diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 21f36d94d..638cf9348 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -7,8 +7,8 @@ authors = ["Ashley Mannix "] nightly-testing = [] [dependencies] -hyper = "~0.9.0" -elastic_hyper = { version = "*", path = "../../" } +reqwest = "*" +elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" elastic_types = { version = "*", features = ["nightly"]} elastic_types_derive = "*" diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 321e29a2c..6e3bc6b1e 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -10,7 +10,7 @@ extern crate serde; extern crate serde_json; -extern crate hyper; +extern crate reqwest; #[macro_use] extern crate serde_derive; @@ -19,12 +19,12 @@ extern crate elastic_types_derive; #[macro_use] extern crate elastic_types; -extern crate elastic_hyper; +extern crate elastic_reqwest; extern crate elastic_requests; use std::net::Ipv4Addr; -use hyper::Client; -use elastic_hyper::{ElasticClient, RequestParams}; +use reqwest::Client; +use elastic_reqwest::{ElasticClient, RequestParams}; use elastic_requests::{IndicesCreateRequest, IndexRequest, SearchRequest}; use elastic_types::prelude::*; @@ -36,8 +36,8 @@ use response::*; const INDEX: &'static str = "testidx"; fn main() { - // Create a hyper client - let client = Client::new(); + // Create a new client + let (client, _) = elastic_reqwest::default(); // Default request parameters let params = RequestParams::default(); diff --git a/src/lib.rs b/src/lib.rs index 73ff7dc5f..19d1e8c9c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! Elasticsearch REST API Client //! //! A lightweight implementation of the Elasticsearch API based on the -//! [`hyper`](http://hyper.rs/hyper/) HTTP client. +//! [`reqwest`](https://github.com/seanmonstar/reqwest/) HTTP client. //! //! Each API endpoint is represented as its own function, //! so each possible http route gets its own function. @@ -18,14 +18,14 @@ //! //! # Usage //! -//! This crate is on [crates.io](https://crates.io/crates/elastic_hyper). -//! To get started, add `elastic_hyper` and `hyper` to your `Cargo.toml`: +//! This crate is on [crates.io](https://crates.io/crates/reqwest). +//! To get started, add `elastic_reqwest` and `reqwest` to your `Cargo.toml`: //! //! ```ignore //! [dependencies] //! elastic_requests = "*" -//! elastic_hyper = "*" -//! hyper = "*" +//! elastic_reqwest = "*" +//! reqwest = "*" //! ``` //! //! For `Windows`, you may need to exclude `openssl` or the build can fail: @@ -33,28 +33,25 @@ //! ```ignore //! [dependencies] //! elastic_requests = "*" -//! elastic_hyper = { version = "*", default-features = false } -//! hyper = { version = "*", default-features = false } +//! elastic_reqwest = { version = "*", default-features = false } //! ``` //! //! Then reference in your crate root: //! -//! ```ignore +//! ``` //! extern crate elastic_requests as req; -//! extern crate elastic_hyper as cli; -//! extern crate hyper; +//! extern crate elastic_reqwest as cli; //! ``` //! //! ## Minimal Example //! //! Ping the availability of your cluster: //! -//! ```no_run +//! ``` //! //HTTP HEAD / //! -//! # extern crate hyper; //! # extern crate elastic_requests as req; -//! # extern crate elastic_hyper as cli; +//! # extern crate elastic_reqwest as cli; //! use cli::ElasticClient; //! use req::PingRequest; //! @@ -69,17 +66,17 @@ //! //! Execute a search query with a url parameter: //! -//! ```no_run +//! ``` //! //HTTP GET /myindex/mytype/_search?q='my string' //! -//! # extern crate hyper; -//! # extern crate elastic_requests as req; -//! # extern crate elastic_hyper as cli; +//! extern crate reqwest; +//! extern crate elastic_requests as req; +//! extern crate elastic_reqwest as cli; //! use cli::{ ElasticClient, RequestParams }; //! use req::SimpleSearchRequest; //! //! # fn main() { -//! let client = hyper::Client::new(); +//! let (client, _) = cli::default(); //! //! let params = RequestParams::default() //! .url_params(vec![ @@ -100,14 +97,14 @@ //! Using the [`json_str`](http://kodraus.github.io/rustdoc/json_str/) crate, you can execute //! queries using pure json: //! -//! ```no_run +//! ``` //! //HTTP POST /myindex/mytype/_search //! -//! # #[macro_use] -//! # extern crate json_str; -//! # extern crate hyper; -//! # extern crate elastic_requests as req; -//! # extern crate elastic_hyper as cli; +//! # +//! #[macro_use] +//! extern crate json_str; +//! extern crate elastic_requests as req; +//! extern crate elastic_reqwest as cli; //! use cli::ElasticClient; //! use req::SearchRequest; //! @@ -162,16 +159,14 @@ //! - [Github](https://github.com/elastic-rs/elastic-hyper) extern crate elastic_requests; -extern crate hyper; +extern crate reqwest; extern crate url; -use std::io::Cursor; -use std::borrow::Borrow; use std::collections::BTreeMap; use elastic_requests::*; -use hyper::error::Result; -use hyper::client::Response; -use hyper::header::{Headers, ContentType}; +use reqwest::Response; +use std::str; +use reqwest::header::{Headers,ContentType}; use url::form_urlencoded::Serializer; /// Misc parameters for any request. @@ -185,8 +180,7 @@ use url::form_urlencoded::Serializer; /// With default query parameters: /// /// ``` -/// extern crate hyper; -/// extern crate elastic_hyper as elastic; +/// extern crate elastic_reqwest as elastic; /// /// let params = elastic::RequestParams::default(); /// ``` @@ -194,20 +188,19 @@ use url::form_urlencoded::Serializer; /// With custom headers: /// /// ``` -/// extern crate hyper; -/// extern crate elastic_hyper as elastic; +/// extern crate reqwest; +/// extern crate elastic_reqwest as elastic; /// /// let mut params = elastic::RequestParams::default(); /// /// //Add your own headers -/// params.headers.set(hyper::header::Authorization("let me in".to_owned())); +/// params.headers.set(reqwest::header::Authorization("let me in".to_owned())); /// ``` /// /// Add url query parameters to the request: /// /// ``` -/// extern crate hyper; -/// extern crate elastic_hyper as elastic; +/// extern crate elastic_reqwest as elastic; /// /// let params = elastic::RequestParams::default() /// .url_params(vec![ @@ -219,10 +212,10 @@ use url::form_urlencoded::Serializer; /// With a custom base url: /// /// ``` -/// extern crate hyper; -/// extern crate elastic_hyper as elastic; +/// extern crate reqwest; +/// extern crate elastic_reqwest as elastic; /// -/// let params = elastic::RequestParams::new("http://mybaseurl:9200", hyper::header::Headers::new()); +/// let params = elastic::RequestParams::new("http://mybaseurl:9200", reqwest::header::Headers::new()); /// ``` #[derive(Debug, Clone)] pub struct RequestParams { @@ -286,30 +279,21 @@ impl Default for RequestParams { } /// Get a default `Client` and `RequestParams`. -pub fn default() -> (hyper::Client, RequestParams) { - (hyper::Client::new(), RequestParams::default()) -} - -macro_rules! req_with_body { - ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ - let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - - let body: &[u8] = (*body).borrow(); - let mut cursor = Cursor::new(body); - - $client.$method(&$url).headers($params.headers.to_owned()).body(&mut cursor).send() - }) +pub fn default() -> (reqwest::Client, RequestParams) { + //FIXME: Bad in libs + let client = reqwest::Client::new().unwrap(); + (client, RequestParams::default()) } /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. - fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result + fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result where I: Into>; } -impl ElasticClient for hyper::Client { - fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result +impl ElasticClient for reqwest::Client { + fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result where I: Into> { let req = req.into(); @@ -327,11 +311,11 @@ impl ElasticClient for hyper::Client { match req.method { HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), - HttpMethod::Post => req_with_body!(self, url, req, params, post), + HttpMethod::Post => self.post(&url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), HttpMethod::Head => self.head(&url).headers(params.headers.to_owned()).send(), - HttpMethod::Delete => self.delete(&url).headers(params.headers.to_owned()).send(), - HttpMethod::Put => req_with_body!(self, url, req, params, put), - HttpMethod::Patch => req_with_body!(self, url, req, params, patch), + HttpMethod::Delete => self.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()).send(), + HttpMethod::Put => self.request(reqwest::Method::Put, &url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), + HttpMethod::Patch => self.request(reqwest::Method::Patch, &url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), } } } diff --git a/tests/mod.rs b/tests/mod.rs index 3999cdf8f..fe043751a 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1,14 +1,13 @@ -extern crate hyper; +extern crate reqwest; extern crate url; -extern crate elastic_hyper; +extern crate elastic_reqwest; -use hyper::header::*; -use elastic_hyper::RequestParams; +use reqwest::header::*; +use elastic_reqwest::RequestParams; #[test] fn request_params_has_default_content_type() { let req = RequestParams::default(); - assert_eq!(Some(&ContentType::json()), req.headers.get::()); } From a9cc9a36774c2d812e6d79a22c225e50cdf2375f Mon Sep 17 00:00:00 2001 From: Stephan Buys Date: Wed, 28 Dec 2016 06:56:23 +0200 Subject: [PATCH 021/127] Fixes based on feedbank Remove orphaned dependency, add to authors and fix CI doc tests. --- Cargo.toml | 2 +- samples/basic/Cargo.toml | 2 +- src/lib.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca6367323..e3e2b8d1a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "elastic_reqwest" version = "0.1.0" -authors = ["Ashley Mannix "] +authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on Reqwest, derived from elastic-hyper." #documentation = "https://docs.rs/elastic_types/0.4.0/elastic_hyper/" diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index e0b1a4321..4587a3a24 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -10,4 +10,4 @@ nightly-testing = [] elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" json_str = "*" -hyper = "~0.9.0" + diff --git a/src/lib.rs b/src/lib.rs index 19d1e8c9c..44a16b308 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,7 @@ //! //! Ping the availability of your cluster: //! -//! ``` +//! ```no_run //! //HTTP HEAD / //! //! # extern crate elastic_requests as req; @@ -66,7 +66,7 @@ //! //! Execute a search query with a url parameter: //! -//! ``` +//! ```no_run //! //HTTP GET /myindex/mytype/_search?q='my string' //! //! extern crate reqwest; @@ -97,7 +97,7 @@ //! Using the [`json_str`](http://kodraus.github.io/rustdoc/json_str/) crate, you can execute //! queries using pure json: //! -//! ``` +//! ```no_run //! //HTTP POST /myindex/mytype/_search //! //! # From 3494e01b3a9a1b87114f253add09017ea913b4c8 Mon Sep 17 00:00:00 2001 From: Stephan Buys Date: Wed, 28 Dec 2016 08:38:18 +0200 Subject: [PATCH 022/127] WIP: Re-add macro, attempt to avoid copy. --- src/lib.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 44a16b308..9333b890d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -162,11 +162,13 @@ extern crate elastic_requests; extern crate reqwest; extern crate url; -use std::collections::BTreeMap; use elastic_requests::*; -use reqwest::Response; +use std::borrow::Borrow; +use std::collections::BTreeMap; +//use std::io::Cursor; use std::str; use reqwest::header::{Headers,ContentType}; +use reqwest::Response; use url::form_urlencoded::Serializer; /// Misc parameters for any request. @@ -285,6 +287,18 @@ pub fn default() -> (reqwest::Client, RequestParams) { (client, RequestParams::default()) } +macro_rules! req_with_body { + ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ + let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); + + let body: &[u8] = (*body).borrow(); +//FIXME: My current understanding of copying, etc. doesn't get me far enough to grok this +// let mut cursor = Cursor::new(body); + + $client.request(reqwest::Method::$method, &$url).headers($params.headers.to_owned()).body(&*body).send() + }) +} + /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. @@ -311,11 +325,11 @@ impl ElasticClient for reqwest::Client { match req.method { HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), - HttpMethod::Post => self.post(&url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), + HttpMethod::Post => req_with_body!(self, url, req, params, Post), HttpMethod::Head => self.head(&url).headers(params.headers.to_owned()).send(), HttpMethod::Delete => self.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()).send(), - HttpMethod::Put => self.request(reqwest::Method::Put, &url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), - HttpMethod::Patch => self.request(reqwest::Method::Patch, &url).headers(params.headers.to_owned()).body(&**req.body.unwrap().into_owned()).send(), + HttpMethod::Put => req_with_body!(self, url, req, params, Put), + HttpMethod::Patch => req_with_body!(self, url, req, params, Patch), } } } From 95b6299493bd03d29a05d7c070a230c705703095 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 16:10:06 +1000 Subject: [PATCH 023/127] avoid copying borrowed body --- Cargo.toml | 8 ++--- README.md | 32 +++++++++---------- samples/README.md | 2 +- samples/basic/src/main.rs | 2 +- samples/typed/src/main.rs | 2 +- src/lib.rs | 67 ++++++++++++++++++++------------------- 6 files changed, 56 insertions(+), 57 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3e2b8d1a..ef35b80f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,14 +4,10 @@ version = "0.1.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on Reqwest, derived from elastic-hyper." -#documentation = "https://docs.rs/elastic_types/0.4.0/elastic_hyper/" -#repository = "https://github.com/elastic-rs/elastic-hyper" +documentation = "https://docs.rs/elastic_reqwest/0.1.0/elastic_reqwest/" +repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] -#[features] -#default = [ "ssl" ] -#ssl = [ "hyper/ssl" ] - [dependencies] elastic_requests = "~0.1.0" reqwest = "*" diff --git a/README.md b/README.md index a2f880cf2..6ca3ea28d 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,38 @@ -# [`elastic_hyper`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_hyper.svg)](https://crates.io/crates/elastic_hyper) +# [`elastic_reqwest`](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) [![Latest Version](https://img.shields.io/crates/v/elastic_reqwest.svg)](https://crates.io/crates/elastic_reqwest) -Provides a synchronous [`hyper`](https://github.com/hyperium/hyper) implementation of the Elasticsearch REST API. The `hyper` client is simple to use; there's basically no setup needed besides creating a `hyper::Client` object to use for requests. The `hyper` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. +Provides a synchronous [`reqwest`](https://github.com/reqwestium/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). ## Build Status Platform | Channel | Status ------------- | ------------- | ------------- -Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-hyper.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-hyper) -Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-hyper) +Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-reqwest.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-reqwest) +Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-reqwest) ## Documentation Version | Docs ------------- | ------------- -`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-hyper/elastic_hyper/) -`current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_hyper/*/elastic_hyper/) +`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-reqwest/elastic_reqwest/) +`current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) ## Example -The `elastic_hyper` client is a thin layer over `hyper`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. +The `elastic_reqwest` client is a thin layer over `reqwest`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. - For query serialisation, the [`json_str`](https://github.com/KodrAus/json_str) crate provides the `json_str!` macro for creating ad-hoc API queries. - For type serialisation / deserialisation, see [`elastic_types`](https://github.com/elastic-rs/elastic-types). Currently targeting the `master` Elasticsearch branch, aiming for `5.x`. This will be stabilised through features in the future. -Add `elastic_hyper` and `json_str` to your `Cargo.toml`: +Add `elastic_reqwest` and `json_str` to your `Cargo.toml`: ``` [dependencies] elastic_requests = "*" -elastic_hyper = "*" -hyper = "*" +elastic_reqwest = "*" +reqwest = "*" # Optional json_str = "*" @@ -42,13 +42,13 @@ Ping the availability of your cluster: ```rust extern crate elastic_requests as req; -extern crate elastic_hyper as cli; -extern crate hyper; +extern crate elastic_reqwest as cli; +extern crate reqwest; use cli::ElasticClient; use req::PingRequest; -let (client, params) = cli::default(); +let (client, params) = cli::default().unwrap(); client.elastic_req(¶ms, PingRequest::new()).unwrap(); ``` @@ -59,13 +59,13 @@ A query DSL query: #[macro_use] extern crate json_str; extern crate elastic_requests as req; -extern crate elastic_hyper as cli; -extern crate hyper; +extern crate elastic_reqwest as cli; +extern crate reqwest; use cli::ElasticClient; use req::SearchRequest; -let (client, params) = cli::default(); +let (client, params) = cli::default().unwrap(); let search = SearchRequest::for_index_ty( "myindex", "mytype", diff --git a/samples/README.md b/samples/README.md index fddd6c9f3..b9f6d55c6 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,3 +1,3 @@ -# `elastic_hyper` samples +# `elastic_reqwest` samples This repo contains a few samples for the `elastic_hyper` crate. diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index d544208db..8c972e4e6 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -16,7 +16,7 @@ use std::io::Read; fn main() { - let (client, _) = elastic_reqwest::default(); + let (client, _) = elastic_reqwest::default().unwrap(); let params = RequestParams::default().url_params(vec![("pretty", String::from("true"))]); diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 6e3bc6b1e..b03332bd1 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -37,7 +37,7 @@ const INDEX: &'static str = "testidx"; fn main() { // Create a new client - let (client, _) = elastic_reqwest::default(); + let (client, _) = elastic_reqwest::default().unwrap(); // Default request parameters let params = RequestParams::default(); diff --git a/src/lib.rs b/src/lib.rs index 9333b890d..87eeb7bab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,7 +54,7 @@ //! # extern crate elastic_reqwest as cli; //! use cli::ElasticClient; //! use req::PingRequest; -//! +//! //! # fn main() { //! let (client, params) = cli::default(); //! @@ -74,20 +74,20 @@ //! extern crate elastic_reqwest as cli; //! use cli::{ ElasticClient, RequestParams }; //! use req::SimpleSearchRequest; -//! +//! //! # fn main() { //! let (client, _) = cli::default(); -//! +//! //! let params = RequestParams::default() -//! .url_params(vec![ -//! ("q", "'my string'".to_owned()), -//! ("pretty", "true".to_owned()) -//! ]); +//! .url_params(vec![ +//! ("q", "'my string'".to_owned()), +//! ("pretty", "true".to_owned()) +//! ]); //! //! let search = SimpleSearchRequest::for_index_ty( //! "myindex", "mytype" //! ); -//! +//! //! client.elastic_req(¶ms, search).unwrap(); //! # } //! ``` @@ -107,12 +107,12 @@ //! extern crate elastic_reqwest as cli; //! use cli::ElasticClient; //! use req::SearchRequest; -//! +//! //! # fn main() { //! let (client, params) = cli::default(); //! //! let search = SearchRequest::for_index_ty( -//! "myindex", "mytype", +//! "myindex", "mytype", //! json_str!({ //! query: { //! filtered: { @@ -132,7 +132,7 @@ //! } //! }) //! ); -//! +//! //! client.elastic_req(¶ms, search).unwrap(); //! # } //! ``` @@ -163,11 +163,11 @@ extern crate reqwest; extern crate url; use elastic_requests::*; -use std::borrow::Borrow; +use std::borrow::Cow; use std::collections::BTreeMap; -//use std::io::Cursor; +use std::io::Cursor; use std::str; -use reqwest::header::{Headers,ContentType}; +use reqwest::header::{Headers, ContentType}; use reqwest::Response; use url::form_urlencoded::Serializer; @@ -205,10 +205,10 @@ use url::form_urlencoded::Serializer; /// extern crate elastic_reqwest as elastic; /// /// let params = elastic::RequestParams::default() -/// .url_params(vec![ -/// ("pretty", "true".to_owned()), -/// ("q", "*".to_owned()) -/// ]); +/// .url_params(vec![ +/// ("pretty", "true".to_owned()), +/// ("q", "*".to_owned()) +/// ]); /// ``` /// /// With a custom base url: @@ -281,34 +281,37 @@ impl Default for RequestParams { } /// Get a default `Client` and `RequestParams`. -pub fn default() -> (reqwest::Client, RequestParams) { - //FIXME: Bad in libs - let client = reqwest::Client::new().unwrap(); - (client, RequestParams::default()) +pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { + reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } macro_rules! req_with_body { ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ - let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); + let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body: &[u8] = (*body).borrow(); -//FIXME: My current understanding of copying, etc. doesn't get me far enough to grok this -// let mut cursor = Cursor::new(body); + let body = match **body { + Cow::Borrowed(ref body) => reqwest::Body::new(Cursor::new(*body)), + Cow::Owned(ref body) => (*body).to_owned().into() + }; - $client.request(reqwest::Method::$method, &$url).headers($params.headers.to_owned()).body(&*body).send() - }) + $client + .request(reqwest::Method::$method, &$url) + .headers($params.headers.to_owned()) + .body(body) + .send() + }) } /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. - fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result - where I: Into>; + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>; } impl ElasticClient for reqwest::Client { - fn elastic_req<'a, I>(&self, params: &RequestParams, req: I) -> Result - where I: Into> + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into> { let req = req.into(); From 7ce444992b4351918bfaaaff972d6eb116872405 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 16:15:11 +1000 Subject: [PATCH 024/127] fix doc tests --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 87eeb7bab..5816d960e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,7 +56,7 @@ //! use req::PingRequest; //! //! # fn main() { -//! let (client, params) = cli::default(); +//! let (client, params) = cli::default().unwrap(); //! //! client.elastic_req(¶ms, PingRequest::new()).unwrap(); //! # } @@ -76,7 +76,7 @@ //! use req::SimpleSearchRequest; //! //! # fn main() { -//! let (client, _) = cli::default(); +//! let (client, _) = cli::default().unwrap(); //! //! let params = RequestParams::default() //! .url_params(vec![ @@ -109,7 +109,7 @@ //! use req::SearchRequest; //! //! # fn main() { -//! let (client, params) = cli::default(); +//! let (client, params) = cli::default().unwrap(); //! //! let search = SearchRequest::for_index_ty( //! "myindex", "mytype", From a610f575c8e7dc35bb4a88a3965dbd657740ece4 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 16:46:17 +1000 Subject: [PATCH 025/127] fix link to reqwest --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6ca3ea28d..285cd2059 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [`elastic_reqwest`](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) [![Latest Version](https://img.shields.io/crates/v/elastic_reqwest.svg)](https://crates.io/crates/elastic_reqwest) -Provides a synchronous [`reqwest`](https://github.com/reqwestium/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. +Provides a synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). From 3473bc555adf26d66136e264df7843ff1184ab18 Mon Sep 17 00:00:00 2001 From: Stephan Buys Date: Thu, 29 Dec 2016 08:52:23 +0200 Subject: [PATCH 026/127] Update README.md --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a2f880cf2..5f44b2e85 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# [`elastic_hyper`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_hyper.svg)](https://crates.io/crates/elastic_hyper) +# [`elastic_reqwest`](https://docs.rs/elastic_hyper/*/elastic_hyper/) [![Latest Version](https://img.shields.io/crates/v/elastic_hyper.svg)](https://crates.io/crates/elastic_hyper) -Provides a synchronous [`hyper`](https://github.com/hyperium/hyper) implementation of the Elasticsearch REST API. The `hyper` client is simple to use; there's basically no setup needed besides creating a `hyper::Client` object to use for requests. The `hyper` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. +Provides a synchronous [`reqwest`](https://github.com/seanmonstar/reqwest/) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `elastic_reqwest::ElasticClient` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). @@ -19,20 +19,20 @@ Version | Docs ## Example -The `elastic_hyper` client is a thin layer over `hyper`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. +The `elastic_reqwest` client is a thin layer over `reqwest`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. - For query serialisation, the [`json_str`](https://github.com/KodrAus/json_str) crate provides the `json_str!` macro for creating ad-hoc API queries. - For type serialisation / deserialisation, see [`elastic_types`](https://github.com/elastic-rs/elastic-types). Currently targeting the `master` Elasticsearch branch, aiming for `5.x`. This will be stabilised through features in the future. -Add `elastic_hyper` and `json_str` to your `Cargo.toml`: +Add `elastic_reqwest` and `json_str` to your `Cargo.toml`: ``` [dependencies] elastic_requests = "*" -elastic_hyper = "*" -hyper = "*" +elastic_reqwest = "*" +reqwest = "*" # Optional json_str = "*" @@ -42,8 +42,8 @@ Ping the availability of your cluster: ```rust extern crate elastic_requests as req; -extern crate elastic_hyper as cli; -extern crate hyper; +extern crate elastic_reqwest as cli; +extern crate reqwest; use cli::ElasticClient; use req::PingRequest; @@ -59,8 +59,8 @@ A query DSL query: #[macro_use] extern crate json_str; extern crate elastic_requests as req; -extern crate elastic_hyper as cli; -extern crate hyper; +extern crate elastic_reqwest as cli; +extern crate reqwest; use cli::ElasticClient; use req::SearchRequest; From 2122f8c869ea501b8dedb6d0af763b289cd45309 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 16:53:34 +1000 Subject: [PATCH 027/127] update meta --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ef35b80f5..3a688cedf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "elastic_reqwest" version = "0.1.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" -description = "A lightweight implementation of the Elasticsearch API based on Reqwest, derived from elastic-hyper." +description = "A lightweight implementation of the Elasticsearch API based on reqwest." documentation = "https://docs.rs/elastic_reqwest/0.1.0/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] From ee55053aa5036ef7917dfb5a5c776ff558797127 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 16:59:54 +1000 Subject: [PATCH 028/127] cargo/0.1.0 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a688cedf..de9d0fb4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,8 @@ exclude = [ "samples" ] [dependencies] elastic_requests = "~0.1.0" -reqwest = "*" -url = "*" +reqwest = "~0.2.0" +url = "~1.1.0" [dev-dependencies] json_str = "*" From dc814d03ddfc641be54829092f36dd5831a1940d Mon Sep 17 00:00:00 2001 From: Stephan Buys Date: Thu, 29 Dec 2016 09:08:32 +0200 Subject: [PATCH 029/127] Add an example of customising the ES cluster url --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 5f44b2e85..12b634d7a 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,13 @@ let (client, params) = cli::default(); client.elastic_req(¶ms, PingRequest::new()).unwrap(); ``` +Customise the location of the Elasticsearch cluster: + + ```rust + let (mut client, mut params) = elastic::default(); + params.base_url = String::from("http://eshost:9200"); + ``` + A query DSL query: ```rust From 498bfe09b20d4b756e4e1ae9f6fd69cd35912604 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 17:15:22 +1000 Subject: [PATCH 030/127] loosen url bound --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index de9d0fb4a..1e2f6786f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ exclude = [ "samples" ] [dependencies] elastic_requests = "~0.1.0" reqwest = "~0.2.0" -url = "~1.1.0" +url = "~1.1" [dev-dependencies] json_str = "*" From 61487aa096dda29a760ffa7e53c94a5d60f717a7 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 17:44:11 +1000 Subject: [PATCH 031/127] update deps --- Cargo.toml | 4 ++-- src/lib.rs | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e2f6786f..a577b3c16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,9 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = "~0.1.0" +elastic_requests = "~0.1.2" reqwest = "~0.2.0" -url = "~1.1" +url = "~1" [dev-dependencies] json_str = "*" diff --git a/src/lib.rs b/src/lib.rs index 5816d960e..fb4b22b1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -286,12 +286,12 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { } macro_rules! req_with_body { - ($client:ident, $url:ident, $req:ident, $params:ident, $method:ident) => ({ - let body = $req.body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); + ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ + let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body = match **body { - Cow::Borrowed(ref body) => reqwest::Body::new(Cursor::new(*body)), - Cow::Owned(ref body) => (*body).to_owned().into() + let body = match body.into_owned().into() { + Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), + Cow::Owned(b) => b.into() }; $client @@ -326,13 +326,21 @@ impl ElasticClient for reqwest::Client { url.push_str(&qry); } - match req.method { + let method = req.method; + let body = req.body; + + match method { HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), - HttpMethod::Post => req_with_body!(self, url, req, params, Post), + + HttpMethod::Post => req_with_body!(self, url, body, params, Post), + HttpMethod::Head => self.head(&url).headers(params.headers.to_owned()).send(), + HttpMethod::Delete => self.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()).send(), - HttpMethod::Put => req_with_body!(self, url, req, params, Put), - HttpMethod::Patch => req_with_body!(self, url, req, params, Patch), + + HttpMethod::Put => req_with_body!(self, url, body, params, Put), + + HttpMethod::Patch => req_with_body!(self, url, body, params, Patch), } } } From 03a3da668dacbdb9bf3c699d0d4c139c62c2dcd4 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 17:47:55 +1000 Subject: [PATCH 032/127] specifyy json_str version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a577b3c16..6f59cf6df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,4 +14,4 @@ reqwest = "~0.2.0" url = "~1" [dev-dependencies] -json_str = "*" +json_str = "~0.3" From f254e07697f56cbb09e91fe7602ce994fc149177 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 17:49:04 +1000 Subject: [PATCH 033/127] fix build badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 285cd2059..d39e3bc04 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, ## Build Status Platform | Channel | Status ------------- | ------------- | ------------- -Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-reqwest.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-reqwest) -Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-reqwest) +Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-hyper.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-hyper) +Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-hyper) ## Documentation From 5f6749435b92c305db01d519d450ff2608d04868 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 17:50:54 +1000 Subject: [PATCH 034/127] fix doc link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d39e3bc04..d7ba9cc75 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/statu Version | Docs ------------- | ------------- -`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-reqwest/elastic_reqwest/) +`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-hyper/elastic_reqwest/) `current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) ## Example From 88d024553ba06fcf152c5794ba7275918fc7a208 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 18:35:36 +1000 Subject: [PATCH 035/127] never copy req body --- Cargo.toml | 2 +- src/lib.rs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6f59cf6df..f51b60ca0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.1.0" +version = "0.1.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." diff --git a/src/lib.rs b/src/lib.rs index fb4b22b1b..d6e1566de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -285,13 +285,25 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } +use std::borrow::Borrow; + macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body = match body.into_owned().into() { - Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), - Cow::Owned(b) => b.into() + let body = match body { + Cow::Borrowed(b) => { + match **b { + Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), + Cow::Owned(ref b) => reqwest::Body::new(Cursor::new(b)) + } + }, + Cow::Owned(b) => { + match b.into() { + Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), + Cow::Owned(b) => b.into() + } + } }; $client From b6cf157b8be45227962295fe7237842021c3a77e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 18:37:03 +1000 Subject: [PATCH 036/127] tidy imports --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d6e1566de..9c0856ae5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,7 +163,7 @@ extern crate reqwest; extern crate url; use elastic_requests::*; -use std::borrow::Cow; +use std::borrow::{Cow, Borrow}; use std::collections::BTreeMap; use std::io::Cursor; use std::str; @@ -285,8 +285,6 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } -use std::borrow::Borrow; - macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); From ee455ddf4663df068171d3e66a00737778736def Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 19:03:41 +1000 Subject: [PATCH 037/127] remove unused import --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9c0856ae5..fa5991c68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,7 +163,7 @@ extern crate reqwest; extern crate url; use elastic_requests::*; -use std::borrow::{Cow, Borrow}; +use std::borrow::Cow; use std::collections::BTreeMap; use std::io::Cursor; use std::str; From 4f7cc9b53cd05eb7b4e82cd8c2a047ee33fbb31e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 29 Dec 2016 19:22:43 +1000 Subject: [PATCH 038/127] add bulk sample --- .travis.yml | 2 ++ samples/basic/Cargo.toml | 5 +-- samples/basic/src/main.rs | 8 +++-- samples/bulk/.gitignore | 2 ++ samples/bulk/Cargo.toml | 13 +++++++ samples/bulk/src/main.rs | 72 +++++++++++++++++++++++++++++++++++++++ samples/typed/Cargo.toml | 12 +++---- samples/typed/src/main.rs | 6 +--- 8 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 samples/bulk/.gitignore create mode 100644 samples/bulk/Cargo.toml create mode 100644 samples/bulk/src/main.rs diff --git a/.travis.yml b/.travis.yml index a37a7b200..9f6b44d00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,8 @@ script: travis-cargo bench && cd samples/basic && travis-cargo build && + cd ../bulk && + travis-cargo build && cd ../typed && travis-cargo --only nightly build && cd ../../ && diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index 4587a3a24..568da0d21 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -3,11 +3,8 @@ name = "elastic_hyper_samples" version = "0.1.0" authors = ["Ashley Mannix "] -[features] -nightly-testing = [] - [dependencies] elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" -json_str = "*" +json_str = "*" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 8c972e4e6..f88fe5451 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -15,11 +15,14 @@ use elastic_requests::SearchRequest; use std::io::Read; fn main() { - + // Get a new default client. let (client, _) = elastic_reqwest::default().unwrap(); - let params = RequestParams::default().url_params(vec![("pretty", String::from("true"))]); + // Create a new set of params with pretty printing. + let params = RequestParams::default(). + url_params(vec![("pretty", String::from("true"))]); + // Create a query DSL request body. let body = json_str!({ query: { query_string: { @@ -28,6 +31,7 @@ fn main() { } }); + // Send the request and read the response. let mut res = client.elastic_req(¶ms, SearchRequest::for_index("_all", body)).unwrap(); let mut message = String::new(); diff --git a/samples/bulk/.gitignore b/samples/bulk/.gitignore new file mode 100644 index 000000000..ab22063e1 --- /dev/null +++ b/samples/bulk/.gitignore @@ -0,0 +1,2 @@ +/target/ +/obj/ \ No newline at end of file diff --git a/samples/bulk/Cargo.toml b/samples/bulk/Cargo.toml new file mode 100644 index 000000000..deeb2ba5c --- /dev/null +++ b/samples/bulk/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "elastic_hyper_samples" +version = "0.1.0" +authors = ["Ashley Mannix "] + +[features] +profiling = [] + +[dependencies] +elastic_reqwest = { version = "*", path = "../../" } +elastic_requests = "*" + +lazy_static = { version = "*", optional = true } diff --git a/samples/bulk/src/main.rs b/samples/bulk/src/main.rs new file mode 100644 index 000000000..4191a88b6 --- /dev/null +++ b/samples/bulk/src/main.rs @@ -0,0 +1,72 @@ +//! Elasticsearch Reqwest Client Samples +//! +//! This sample assumes you have a node running on `localhost`. +//! +//! This sample demonstrates a request with a large body. +//! +//! If you compile with `--features profiling` then it uses the system allocator +//! to play nicely with valgrind for profiling. +//! +//! If you compile with `--features lazy_static` then the sample uses a borrowed +//! request instead of an owned one. +//! This will avoid allocating multiple copies of the request if the same body +//! is used multiple times. + +#![cfg_attr(feature="profiling", feature(alloc_system))] +#[cfg(feature="profiling")] +extern crate alloc_system; + +#[cfg(feature="lazy_static")] +#[cfg_attr(feature = "lazy_static", macro_use)] +extern crate lazy_static; + +extern crate elastic_requests; +extern crate elastic_reqwest; + +use elastic_reqwest::ElasticClient; +use elastic_requests::BulkRequest; + +// Create a bulk request to index a bunch of docs. +macro_rules! bulk_req { + () => ({ + let mut bulk = String::new(); + for i in 1..1000 { + let header = format!("{{ \"index\" : {{ \"_index\" : \"test\", \"_type\" : \"ty\", \"_id\" : \"{}\" }} }}", i); + let body = format!("{{ \"title\" : \"string value {}\" }}", i); + + bulk.push_str(&header); + bulk.push('\n'); + bulk.push_str(&body); + bulk.push('\n'); + } + + BulkRequest::new(bulk) + }) +} + +#[cfg(feature="lazy_static")] +lazy_static! { + static ref REQUEST: BulkRequest<'static> = { + bulk_req!() + }; +} + +#[cfg(not(feature="lazy_static"))] +fn get_req() -> BulkRequest<'static> { + bulk_req!() +} + +#[cfg(feature="lazy_static")] +fn get_req() -> &'static BulkRequest<'static> { + &REQUEST +} + +fn main() { + // Get a new default client. + let (client, params) = elastic_reqwest::default().unwrap(); + + // Send the bulk request. + let res = client.elastic_req(¶ms, get_req()).unwrap(); + + println!("{:?}", res); +} diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 638cf9348..a60313ef7 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -3,16 +3,14 @@ name = "elastic_hyper_samples" version = "0.1.0" authors = ["Ashley Mannix "] -[features] -nightly-testing = [] - [dependencies] -reqwest = "*" elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" -elastic_types = { version = "*", features = ["nightly"]} -elastic_types_derive = "*" -json_str = { version = "*", features = ["nightly"]} + serde = "~0.8.0" serde_derive = "~0.8.0" serde_json = "~0.8.0" +elastic_types = { version = "*", features = ["nightly"]} +elastic_types_derive = "*" + +json_str = { version = "*", features = ["nightly"]} diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index b03332bd1..1f552523c 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -10,7 +10,6 @@ extern crate serde; extern crate serde_json; -extern crate reqwest; #[macro_use] extern crate serde_derive; @@ -37,10 +36,7 @@ const INDEX: &'static str = "testidx"; fn main() { // Create a new client - let (client, _) = elastic_reqwest::default().unwrap(); - - // Default request parameters - let params = RequestParams::default(); + let (client, params) = elastic_reqwest::default().unwrap(); // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. From 00cf2cac1625cdbc8e0b5060895a8b6202cc76b9 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 31 Dec 2016 09:47:30 +1000 Subject: [PATCH 039/127] fix typed sample --- samples/basic/Cargo.toml | 2 +- samples/bulk/Cargo.toml | 2 +- samples/typed/Cargo.toml | 3 ++- samples/typed/src/main.rs | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index 568da0d21..cf24883a0 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "elastic_hyper_samples" +name = "basic" version = "0.1.0" authors = ["Ashley Mannix "] diff --git a/samples/bulk/Cargo.toml b/samples/bulk/Cargo.toml index deeb2ba5c..48db213f0 100644 --- a/samples/bulk/Cargo.toml +++ b/samples/bulk/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "elastic_hyper_samples" +name = "bulk" version = "0.1.0" authors = ["Ashley Mannix "] diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index a60313ef7..4ea66f550 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "elastic_hyper_samples" +name = "typed" version = "0.1.0" authors = ["Ashley Mannix "] @@ -7,6 +7,7 @@ authors = ["Ashley Mannix "] elastic_reqwest = { version = "*", path = "../../" } elastic_requests = "*" +reqwest = "~0.2.0" serde = "~0.8.0" serde_derive = "~0.8.0" serde_json = "~0.8.0" diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 1f552523c..4f436e3ce 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -10,14 +10,14 @@ extern crate serde; extern crate serde_json; - +extern crate reqwest; #[macro_use] extern crate serde_derive; -#[macro_use] -extern crate elastic_types_derive; #[macro_use] extern crate elastic_types; +#[macro_use] +extern crate elastic_types_derive; extern crate elastic_reqwest; extern crate elastic_requests; From 44c79579f9fe5f987230670ce53c46defb961f69 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 31 Dec 2016 10:13:56 +1000 Subject: [PATCH 040/127] using new into_raw method --- Cargo.toml | 2 +- src/lib.rs | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f51b60ca0..58c26a7dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = "~0.1.2" +elastic_requests = "~0.1.3" reqwest = "~0.2.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index fa5991c68..d3778a1db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -289,19 +289,9 @@ macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body = match body { - Cow::Borrowed(b) => { - match **b { - Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), - Cow::Owned(ref b) => reqwest::Body::new(Cursor::new(b)) - } - }, - Cow::Owned(b) => { - match b.into() { - Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), - Cow::Owned(b) => b.into() - } - } + let body = match body.into_raw() { + Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), + Cow::Owned(b) => b.into() }; $client From 890c316a30f4fc09f07a55e737d3df55732e0475 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 31 Dec 2016 10:26:05 +1000 Subject: [PATCH 041/127] cargo/0.1.2 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 58c26a7dd..f4d97fc90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elastic_reqwest" -version = "0.1.1" +version = "0.1.2" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/0.1.0/elastic_reqwest/" +documentation = "https://docs.rs/elastic_reqwest/0.1.2/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] From 58986737841a477577091450154244b5b0acde96 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 6 Jan 2017 11:58:59 +1000 Subject: [PATCH 042/127] update for latest types --- samples/typed/src/data.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs index 32c556758..8ebdb9ba7 100644 --- a/samples/typed/src/data.rs +++ b/samples/typed/src/data.rs @@ -1,5 +1,4 @@ use std::net::Ipv4Addr; -use serde::ser::{Serializer, Error}; use elastic_types::prelude::*; // The type we want to index in Elasticsearch @@ -25,5 +24,5 @@ pub struct Index { #[derive(Default, Serialize)] struct Mappings { - mystruct: TypeMapping + mystruct: Document } \ No newline at end of file From fb2cec6a5e5cec1746f31d7dc65f9905a97a6c60 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 18:16:31 +1000 Subject: [PATCH 043/127] work on api --- Cargo.toml | 4 +-- samples/basic/src/main.rs | 5 +-- samples/typed/src/main.rs | 4 ++- src/lib.rs | 66 +++++++++++++++++++++++++++++---------- tests/mod.rs | 7 +++-- 5 files changed, 62 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f4d97fc90..37044d911 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elastic_reqwest" -version = "0.1.2" +version = "0.2.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/0.1.2/elastic_reqwest/" +documentation = "https://docs.rs/elastic_reqwest/0.2.0/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index f88fe5451..4d95b5773 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -7,6 +7,7 @@ #[macro_use] extern crate json_str; +#[macro_use] extern crate elastic_reqwest; extern crate elastic_requests; @@ -19,8 +20,8 @@ fn main() { let (client, _) = elastic_reqwest::default().unwrap(); // Create a new set of params with pretty printing. - let params = RequestParams::default(). - url_params(vec![("pretty", String::from("true"))]); + let params = RequestParams::default() + .url_params(params![pretty: true]); // Create a query DSL request body. let body = json_str!({ diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 4f436e3ce..f5e60efd8 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -18,6 +18,7 @@ extern crate serde_derive; extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; +#[macro_use] extern crate elastic_reqwest; extern crate elastic_requests; @@ -40,7 +41,8 @@ fn main() { // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. - let index_params = RequestParams::default().url_params(vec![("refresh", String::from("true"))]); + let index_params = RequestParams::default() + .url_params(params![refresh: true]); // Create an index and map our type create_index(&client, ¶ms); diff --git a/src/lib.rs b/src/lib.rs index d3778a1db..ad150326b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,10 +167,17 @@ use std::borrow::Cow; use std::collections::BTreeMap; use std::io::Cursor; use std::str; -use reqwest::header::{Headers, ContentType}; +use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; use reqwest::Response; use url::form_urlencoded::Serializer; +#[macro_export] +macro_rules! params { + ($($name:ident : $value:expr),*) => ( + vec![$((stringify!($name), $value.to_string()),)*] + ) +} + /// Misc parameters for any request. /// /// The `RequestParams` struct allows you to set headers and url parameters for your requests. @@ -187,37 +194,56 @@ use url::form_urlencoded::Serializer; /// let params = elastic::RequestParams::default(); /// ``` /// +/// With a custom base url: +/// +/// ``` +/// extern crate reqwest; +/// extern crate elastic_reqwest as elastic; +/// +/// let params = elastic::RequestParams::new("http://mybaseurl:9200"); +/// ``` +/// /// With custom headers: /// /// ``` /// extern crate reqwest; /// extern crate elastic_reqwest as elastic; /// -/// let mut params = elastic::RequestParams::default(); +/// use reqwest::header::Authorization; /// -/// //Add your own headers -/// params.headers.set(reqwest::header::Authorization("let me in".to_owned())); +/// # fn main() { +/// let params = elastic::RequestParams::default() +/// .header(Authorization("let me in".to_owned())); +/// # } /// ``` /// -/// Add url query parameters to the request: +/// With url query parameters: /// /// ``` +/// #[macro_use] /// extern crate elastic_reqwest as elastic; /// +/// # fn main() { /// let params = elastic::RequestParams::default() -/// .url_params(vec![ -/// ("pretty", "true".to_owned()), -/// ("q", "*".to_owned()) -/// ]); +/// .url_params(params![ +/// pretty: true, +/// q: "*" +/// ]); +/// # } /// ``` /// -/// With a custom base url: +/// Url query parameters can also be added without using macros: /// /// ``` -/// extern crate reqwest; /// extern crate elastic_reqwest as elastic; /// -/// let params = elastic::RequestParams::new("http://mybaseurl:9200", reqwest::header::Headers::new()); +/// # fn main() { +/// let params = elastic::RequestParams::default() +/// .url_params(vec![ +/// ("pretty", String::from("true")), +/// ("q", String::from("*")) +/// ]); +/// # } /// ``` #[derive(Debug, Clone)] pub struct RequestParams { @@ -231,9 +257,8 @@ pub struct RequestParams { impl RequestParams { /// Create a new container for request parameters. - /// - /// Attempts to add `ContentType::json` to the passed in `headers` param. - pub fn new>(base: T, mut headers: Headers) -> Self { + pub fn new>(base: T) -> Self { + let mut headers = Headers::new(); headers.set(ContentType::json()); RequestParams { @@ -254,6 +279,15 @@ impl RequestParams { self } + /// Set a header value on the params. + pub fn header(mut self, header: H) -> Self + where H: Header + HeaderFormat + { + self.headers.set(header); + + self + } + /// Get the url params as a formatted string. /// /// Follows the `application/x-www-form-urlencoded` format. @@ -276,7 +310,7 @@ impl RequestParams { impl Default for RequestParams { fn default() -> Self { - RequestParams::new("http://localhost:9200", Headers::new()) + RequestParams::new("http://localhost:9200") } } diff --git a/tests/mod.rs b/tests/mod.rs index fe043751a..a88a9e6f3 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1,5 +1,6 @@ extern crate reqwest; extern crate url; +#[macro_use] extern crate elastic_reqwest; use reqwest::header::*; @@ -21,9 +22,9 @@ fn request_params_has_default_base_url() { #[test] fn request_params_has_url_query() { let req = RequestParams::default() - .url_params(vec![ - ("pretty", "true".to_owned()), - ("q", "*".to_owned()) + .url_params(params![ + pretty: true, + q: "*" ]); assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); From c6738cb5980a15cbf8eed51c6c03666a8131ff31 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 19:25:22 +1000 Subject: [PATCH 044/127] standardise builder methods --- src/lib.rs | 47 ++++++++++++----------------------------------- tests/mod.rs | 7 +++---- 2 files changed, 15 insertions(+), 39 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad150326b..6ccdfdca7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,10 +79,8 @@ //! let (client, _) = cli::default().unwrap(); //! //! let params = RequestParams::default() -//! .url_params(vec![ -//! ("q", "'my string'".to_owned()), -//! ("pretty", "true".to_owned()) -//! ]); +//! .url_param("pretty", "true") +//! .url_param("q", "*"); //! //! let search = SimpleSearchRequest::for_index_ty( //! "myindex", "mytype" @@ -171,13 +169,6 @@ use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; use reqwest::Response; use url::form_urlencoded::Serializer; -#[macro_export] -macro_rules! params { - ($($name:ident : $value:expr),*) => ( - vec![$((stringify!($name), $value.to_string()),)*] - ) -} - /// Misc parameters for any request. /// /// The `RequestParams` struct allows you to set headers and url parameters for your requests. @@ -220,29 +211,12 @@ macro_rules! params { /// With url query parameters: /// /// ``` -/// #[macro_use] -/// extern crate elastic_reqwest as elastic; -/// -/// # fn main() { -/// let params = elastic::RequestParams::default() -/// .url_params(params![ -/// pretty: true, -/// q: "*" -/// ]); -/// # } -/// ``` -/// -/// Url query parameters can also be added without using macros: -/// -/// ``` /// extern crate elastic_reqwest as elastic; /// /// # fn main() { /// let params = elastic::RequestParams::default() -/// .url_params(vec![ -/// ("pretty", String::from("true")), -/// ("q", String::from("*")) -/// ]); +/// .url_param("pretty", "true") +/// .url_param("q", "*"); /// # } /// ``` #[derive(Debug, Clone)] @@ -268,12 +242,15 @@ impl RequestParams { } } - /// Add a collection of url params. - pub fn url_params(mut self, url_params: I) -> Self - where I: IntoIterator + /// Set a url param value. + pub fn url_param>(mut self, key: &'static str, value: T) -> Self { - for (k, v) in url_params { - self.url_params.insert(k, v); + if self.url_params.contains_key(key) { + let mut entry = self.url_params.get_mut(key).unwrap(); + *entry = value.into(); + } + else { + self.url_params.insert(key, value.into()); } self diff --git a/tests/mod.rs b/tests/mod.rs index a88a9e6f3..13f4bf787 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -22,10 +22,9 @@ fn request_params_has_default_base_url() { #[test] fn request_params_has_url_query() { let req = RequestParams::default() - .url_params(params![ - pretty: true, - q: "*" - ]); + .url_param("pretty", "false") + .url_param("pretty", "true") + .url_param("q", "*"); assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); } From 42c04beb90766a35ef5fdaf7b45fa79df5c70881 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 19:48:44 +1000 Subject: [PATCH 045/127] use ToString for url_params --- samples/basic/src/main.rs | 2 +- samples/typed/src/main.rs | 2 +- src/lib.rs | 10 +++++----- tests/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 4d95b5773..3efc32829 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -21,7 +21,7 @@ fn main() { // Create a new set of params with pretty printing. let params = RequestParams::default() - .url_params(params![pretty: true]); + .url_param("pretty", true); // Create a query DSL request body. let body = json_str!({ diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index f5e60efd8..65f3ae465 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -42,7 +42,7 @@ fn main() { // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. let index_params = RequestParams::default() - .url_params(params![refresh: true]); + .url_param(refresh, true); // Create an index and map our type create_index(&client, ¶ms); diff --git a/src/lib.rs b/src/lib.rs index 6ccdfdca7..8f8173513 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ //! let (client, _) = cli::default().unwrap(); //! //! let params = RequestParams::default() -//! .url_param("pretty", "true") +//! .url_param("pretty", true) //! .url_param("q", "*"); //! //! let search = SimpleSearchRequest::for_index_ty( @@ -215,7 +215,7 @@ use url::form_urlencoded::Serializer; /// /// # fn main() { /// let params = elastic::RequestParams::default() -/// .url_param("pretty", "true") +/// .url_param("pretty", true) /// .url_param("q", "*"); /// # } /// ``` @@ -243,14 +243,14 @@ impl RequestParams { } /// Set a url param value. - pub fn url_param>(mut self, key: &'static str, value: T) -> Self + pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { let mut entry = self.url_params.get_mut(key).unwrap(); - *entry = value.into(); + *entry = value.to_string(); } else { - self.url_params.insert(key, value.into()); + self.url_params.insert(key, value.to_string()); } self diff --git a/tests/mod.rs b/tests/mod.rs index 13f4bf787..11f1ea122 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -22,8 +22,8 @@ fn request_params_has_default_base_url() { #[test] fn request_params_has_url_query() { let req = RequestParams::default() - .url_param("pretty", "false") - .url_param("pretty", "true") + .url_param("pretty", false) + .url_param("pretty", true) .url_param("q", "*"); assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); From 58969b8577812f93511cc5ff45b18c10ebdbee57 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 19:52:42 +1000 Subject: [PATCH 046/127] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d40bbc0cf..9ad5e0276 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ elastic_requests = "*" elastic_reqwest = "*" reqwest = "*" -# Optional +# Optional for request bodies json_str = "*" ``` From e4c5498e0196ba0511414486e4cd97a7eafe15ff Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 19:53:43 +1000 Subject: [PATCH 047/127] remove macro_use --- samples/basic/src/main.rs | 1 - samples/typed/src/main.rs | 1 - tests/mod.rs | 1 - 3 files changed, 3 deletions(-) diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 3efc32829..ae8b7e194 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -7,7 +7,6 @@ #[macro_use] extern crate json_str; -#[macro_use] extern crate elastic_reqwest; extern crate elastic_requests; diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 65f3ae465..ad307733c 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -18,7 +18,6 @@ extern crate serde_derive; extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; -#[macro_use] extern crate elastic_reqwest; extern crate elastic_requests; diff --git a/tests/mod.rs b/tests/mod.rs index 11f1ea122..be11831e8 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -1,6 +1,5 @@ extern crate reqwest; extern crate url; -#[macro_use] extern crate elastic_reqwest; use reqwest::header::*; From 2d1c6caad914932080b77f0b91d940d4618dfa45 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 10 Jan 2017 20:16:03 +1000 Subject: [PATCH 048/127] fix typed sample --- samples/typed/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index ad307733c..bea1bc689 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -41,7 +41,7 @@ fn main() { // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. let index_params = RequestParams::default() - .url_param(refresh, true); + .url_param("refresh", true); // Create an index and map our type create_index(&client, ¶ms); From 6a3196ff301e60c8a93da3cf6ce67c1410064bf3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Jan 2017 07:12:59 +1000 Subject: [PATCH 049/127] cargo/0.2.1 --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 37044d911..f9ec93471 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elastic_reqwest" -version = "0.2.0" +version = "0.2.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/0.2.0/elastic_reqwest/" +documentation = "https://docs.rs/elastic_reqwest/0.2.1/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] @@ -14,4 +14,4 @@ reqwest = "~0.2.0" url = "~1" [dev-dependencies] -json_str = "~0.3" +json_str = "^0.*" From a0bc4289720645f937c845e9dd8606f02589f0f4 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 12 Jan 2017 13:55:39 +1000 Subject: [PATCH 050/127] Update README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ad5e0276..90bac525f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Provides a synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. -If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). +This library is the HTTP backend for the higher-level [`elastic`](https://github.com/elastic-rs/elastic) client. ## Build Status Platform | Channel | Status @@ -17,6 +17,10 @@ Version | Docs `master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-hyper/elastic_reqwest/) `current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) +## Alternatives + +If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). + ## Example The `elastic_reqwest` client is a thin layer over `reqwest`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. @@ -97,4 +101,4 @@ let search = SearchRequest::for_index_ty( ); client.elastic_req(¶ms, search).unwrap(); -``` \ No newline at end of file +``` From 562460dd1859abbaefc7e00885261f1f29815ec0 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 14 Jan 2017 11:24:06 +1000 Subject: [PATCH 051/127] add base_url to builder --- src/lib.rs | 7 +++++++ tests/mod.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8f8173513..e23a0b416 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,6 +242,13 @@ impl RequestParams { } } + /// Set the base url for the node. + pub fn base_url>(mut self, base: T) -> Self { + self.base_url = base.into(); + + self + } + /// Set a url param value. pub fn url_param(mut self, key: &'static str, value: T) -> Self { diff --git a/tests/mod.rs b/tests/mod.rs index be11831e8..0bccc54a4 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -19,7 +19,15 @@ fn request_params_has_default_base_url() { } #[test] -fn request_params_has_url_query() { +fn request_params_can_set_base_url() { + let req = RequestParams::default() + .base_url("http://eshost:9200"); + + assert_eq!("http://eshost:9200", req.base_url); +} + +#[test] +fn request_params_can_set_url_query() { let req = RequestParams::default() .url_param("pretty", false) .url_param("pretty", true) From faa5dd49a57d65d0b0cfd58631fedffe55ebac09 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 14 Jan 2017 11:24:38 +1000 Subject: [PATCH 052/127] cargo/0.2.2 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9ec93471..2b1dbae19 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "elastic_reqwest" -version = "0.2.1" +version = "0.2.2" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/0.2.1/elastic_reqwest/" +documentation = "https://docs.rs/elastic_reqwest/0.2.2/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] From 2d8a4ad2b35af0190f88b9bfb4eec7cd15aa2e1f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 16 Jan 2017 07:29:01 +1000 Subject: [PATCH 053/127] update docs --- Cargo.toml | 2 +- src/lib.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2b1dbae19..dcfd729f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.2.2" +version = "0.2.3" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." diff --git a/src/lib.rs b/src/lib.rs index e23a0b416..18db57de1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -139,15 +139,14 @@ //! //! # See Also //! +//! ## [`elastic`](https://github.com/elastic-rs/elastic) +//! +//! A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. +//! //! ## [`rs-es`](https://github.com/benashford/rs-es) //! //! An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL. -//! -//! ## [`elastic_types`](https://github.com/elastic-rs/elastic-types) -//! -//! A library that implements the core datatypes in Elasticsearch -//! documents and automatically generates a json mapping from your Rust structures. -//! +//! //! ## [`json_str`](https://github.com/KodrAus/json_str) //! //! A library for generating minified json strings from Rust syntax. From 01ab9eb0190c27ae5e238fa885b1cb58a5dc901f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 20 Jan 2017 21:35:04 +1000 Subject: [PATCH 054/127] simplify url building --- src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 18db57de1..4226d130c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -276,15 +276,11 @@ impl RequestParams { /// Follows the `application/x-www-form-urlencoded` format. pub fn get_url_qry(&self) -> (usize, Option) { if self.url_params.len() > 0 { - let qry: String = Serializer::new(String::new()) + let qry: String = Serializer::for_suffix(String::from("?"), 1) .extend_pairs(self.url_params.iter()) .finish(); - let mut url_qry = String::with_capacity(qry.len() + 1); - url_qry.push('?'); - url_qry.push_str(&qry); - - (url_qry.len(), Some(url_qry)) + (qry.len(), Some(qry)) } else { (0, None) } From 28a09fa5d72969ccce3dfcf49c29979f92aa1fc3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 22 Jan 2017 09:57:03 +1000 Subject: [PATCH 055/127] line up fn calls --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4226d130c..6f5d683a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -307,11 +307,10 @@ macro_rules! req_with_body { Cow::Owned(b) => b.into() }; - $client - .request(reqwest::Method::$method, &$url) - .headers($params.headers.to_owned()) - .body(body) - .send() + $client.request(reqwest::Method::$method, &$url) + .headers($params.headers.to_owned()) + .body(body) + .send() }) } From c06e023bdb234977c25d572345739e20966ceebb Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 27 Jan 2017 14:08:29 +1000 Subject: [PATCH 056/127] update reqwest --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dcfd729f8..dbaf8254d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.2.3" +version = "0.3.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -10,7 +10,7 @@ exclude = [ "samples" ] [dependencies] elastic_requests = "~0.1.3" -reqwest = "~0.2.0" +reqwest = "~0.3.0" url = "~1" [dev-dependencies] From fb976c249adfdb44ffb9cbeda368ceb9853ab6cd Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 27 Jan 2017 14:20:53 +1000 Subject: [PATCH 057/127] re-export elastic_requests --- samples/basic/Cargo.toml | 1 - samples/basic/src/main.rs | 9 ++++----- samples/bulk/Cargo.toml | 1 - samples/bulk/src/main.rs | 9 ++++----- samples/typed/Cargo.toml | 3 +-- samples/typed/src/main.rs | 10 ++++------ src/lib.rs | 29 ++++++++++++----------------- 7 files changed, 25 insertions(+), 37 deletions(-) diff --git a/samples/basic/Cargo.toml b/samples/basic/Cargo.toml index cf24883a0..6bce7944b 100644 --- a/samples/basic/Cargo.toml +++ b/samples/basic/Cargo.toml @@ -5,6 +5,5 @@ authors = ["Ashley Mannix "] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -elastic_requests = "*" json_str = "*" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index ae8b7e194..48a68addc 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -7,16 +7,15 @@ #[macro_use] extern crate json_str; -extern crate elastic_reqwest; -extern crate elastic_requests; +extern crate elastic_reqwest as cli; -use elastic_reqwest::{ElasticClient, RequestParams}; -use elastic_requests::SearchRequest; +use cli::{ElasticClient, RequestParams}; +use cli::req::SearchRequest; use std::io::Read; fn main() { // Get a new default client. - let (client, _) = elastic_reqwest::default().unwrap(); + let (client, _) = cli::default().unwrap(); // Create a new set of params with pretty printing. let params = RequestParams::default() diff --git a/samples/bulk/Cargo.toml b/samples/bulk/Cargo.toml index 48db213f0..588b8d9e7 100644 --- a/samples/bulk/Cargo.toml +++ b/samples/bulk/Cargo.toml @@ -8,6 +8,5 @@ profiling = [] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -elastic_requests = "*" lazy_static = { version = "*", optional = true } diff --git a/samples/bulk/src/main.rs b/samples/bulk/src/main.rs index 4191a88b6..448e6cf56 100644 --- a/samples/bulk/src/main.rs +++ b/samples/bulk/src/main.rs @@ -20,11 +20,10 @@ extern crate alloc_system; #[cfg_attr(feature = "lazy_static", macro_use)] extern crate lazy_static; -extern crate elastic_requests; -extern crate elastic_reqwest; +extern crate elastic_reqwest as cli; -use elastic_reqwest::ElasticClient; -use elastic_requests::BulkRequest; +use cli::ElasticClient; +use cli::req::BulkRequest; // Create a bulk request to index a bunch of docs. macro_rules! bulk_req { @@ -63,7 +62,7 @@ fn get_req() -> &'static BulkRequest<'static> { fn main() { // Get a new default client. - let (client, params) = elastic_reqwest::default().unwrap(); + let (client, params) = cli::default().unwrap(); // Send the bulk request. let res = client.elastic_req(¶ms, get_req()).unwrap(); diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 4ea66f550..88f1e851b 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -5,9 +5,8 @@ authors = ["Ashley Mannix "] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -elastic_requests = "*" -reqwest = "~0.2.0" +reqwest = "~0.3.0" serde = "~0.8.0" serde_derive = "~0.8.0" serde_json = "~0.8.0" diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index bea1bc689..a3938787f 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -14,17 +14,15 @@ extern crate reqwest; #[macro_use] extern crate serde_derive; -#[macro_use] extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; -extern crate elastic_reqwest; -extern crate elastic_requests; +extern crate elastic_reqwest as cli; use std::net::Ipv4Addr; use reqwest::Client; -use elastic_reqwest::{ElasticClient, RequestParams}; -use elastic_requests::{IndicesCreateRequest, IndexRequest, SearchRequest}; +use cli::{ElasticClient, RequestParams}; +use cli::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; use elastic_types::prelude::*; mod data; @@ -36,7 +34,7 @@ const INDEX: &'static str = "testidx"; fn main() { // Create a new client - let (client, params) = elastic_reqwest::default().unwrap(); + let (client, params) = cli::default().unwrap(); // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. diff --git a/src/lib.rs b/src/lib.rs index 6f5d683a9..698bdfa3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,23 +23,13 @@ //! //! ```ignore //! [dependencies] -//! elastic_requests = "*" //! elastic_reqwest = "*" //! reqwest = "*" //! ``` //! -//! For `Windows`, you may need to exclude `openssl` or the build can fail: -//! -//! ```ignore -//! [dependencies] -//! elastic_requests = "*" -//! elastic_reqwest = { version = "*", default-features = false } -//! ``` -//! //! Then reference in your crate root: //! //! ``` -//! extern crate elastic_requests as req; //! extern crate elastic_reqwest as cli; //! ``` //! @@ -50,10 +40,9 @@ //! ```no_run //! //HTTP HEAD / //! -//! # extern crate elastic_requests as req; //! # extern crate elastic_reqwest as cli; //! use cli::ElasticClient; -//! use req::PingRequest; +//! use cli::req::PingRequest; //! //! # fn main() { //! let (client, params) = cli::default().unwrap(); @@ -70,10 +59,9 @@ //! //HTTP GET /myindex/mytype/_search?q='my string' //! //! extern crate reqwest; -//! extern crate elastic_requests as req; //! extern crate elastic_reqwest as cli; //! use cli::{ ElasticClient, RequestParams }; -//! use req::SimpleSearchRequest; +//! use cli::req::SimpleSearchRequest; //! //! # fn main() { //! let (client, _) = cli::default().unwrap(); @@ -101,10 +89,9 @@ //! # //! #[macro_use] //! extern crate json_str; -//! extern crate elastic_requests as req; //! extern crate elastic_reqwest as cli; //! use cli::ElasticClient; -//! use req::SearchRequest; +//! use cli::req::SearchRequest; //! //! # fn main() { //! let (client, params) = cli::default().unwrap(); @@ -159,7 +146,6 @@ extern crate elastic_requests; extern crate reqwest; extern crate url; -use elastic_requests::*; use std::borrow::Cow; use std::collections::BTreeMap; use std::io::Cursor; @@ -168,6 +154,15 @@ use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; use reqwest::Response; use url::form_urlencoded::Serializer; +/// Request types. +/// +/// These are re-exported from `elastic_requests` for convenience. +pub mod req { + pub use elastic_requests::*; +} + +use self::req::{HttpRequest, HttpMethod, RawBody}; + /// Misc parameters for any request. /// /// The `RequestParams` struct allows you to set headers and url parameters for your requests. From d717672e5daa0e58f16e58df00de24a2861e433f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 27 Jan 2017 14:21:54 +1000 Subject: [PATCH 058/127] update readme --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 90bac525f..5c2c399ba 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ Add `elastic_reqwest` and `json_str` to your `Cargo.toml`: ``` [dependencies] -elastic_requests = "*" elastic_reqwest = "*" reqwest = "*" @@ -45,12 +44,11 @@ json_str = "*" Ping the availability of your cluster: ```rust -extern crate elastic_requests as req; extern crate elastic_reqwest as cli; extern crate reqwest; use cli::ElasticClient; -use req::PingRequest; +use cli::req::PingRequest; let (client, params) = cli::default().unwrap(); @@ -69,12 +67,11 @@ A query DSL query: ```rust #[macro_use] extern crate json_str; -extern crate elastic_requests as req; extern crate elastic_reqwest as cli; extern crate reqwest; use cli::ElasticClient; -use req::SearchRequest; +use cli::req::SearchRequest; let (client, params) = cli::default().unwrap(); From f4a6a79a9e4197191769e36645d25a11e489624c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 2 Feb 2017 22:05:24 +1000 Subject: [PATCH 059/127] update requests --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dbaf8254d..3b987b22b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = "~0.1.3" +elastic_requests = { version = "~0.2", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/modules" } reqwest = "~0.3.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index 698bdfa3b..7cf12e31c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -158,7 +158,7 @@ use url::form_urlencoded::Serializer; /// /// These are re-exported from `elastic_requests` for convenience. pub mod req { - pub use elastic_requests::*; + pub use elastic_requests::prelude::*; } use self::req::{HttpRequest, HttpMethod, RawBody}; From 5ba14ad171fe7cd3675ac8f63aa2c3337ad794d3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 2 Feb 2017 22:07:48 +1000 Subject: [PATCH 060/127] cargo/0.3.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3b987b22b..8f2e6cdd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.3.0" +version = "0.3.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." From 7f197a28d885afc26775e2d258097091fc464fcb Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 4 Feb 2017 08:25:24 +1000 Subject: [PATCH 061/127] update requests --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8f2e6cdd1..cdf92107e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = { version = "~0.2", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/modules" } +elastic_requests = { version = "~0.1.7", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/modules" } reqwest = "~0.3.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index 7cf12e31c..698bdfa3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -158,7 +158,7 @@ use url::form_urlencoded::Serializer; /// /// These are re-exported from `elastic_requests` for convenience. pub mod req { - pub use elastic_requests::prelude::*; + pub use elastic_requests::*; } use self::req::{HttpRequest, HttpMethod, RawBody}; From 12f0174525a31b6a07e2effe237ef83134727964 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 6 Feb 2017 16:26:57 +1000 Subject: [PATCH 062/127] track stable requests --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cdf92107e..cfba67e23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = { version = "~0.1.7", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/modules" } +elastic_requests = "~0.1.7" reqwest = "~0.3.0" url = "~1" From 64af692fda757b84e99d578e33c56192e7c1188d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 7 Feb 2017 12:34:19 +1000 Subject: [PATCH 063/127] deny warnings --- src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 698bdfa3b..31005ff8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,6 +142,9 @@ //! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) //! - [Github](https://github.com/elastic-rs/elastic-hyper) +#![deny(warnings)] +#![deny(missing_docs)] + extern crate elastic_requests; extern crate reqwest; extern crate url; From 25f845c5336938dab2ae8215822dfb8d9156347c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 7 Feb 2017 12:50:12 +1000 Subject: [PATCH 064/127] update typed sample --- samples/typed/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 88f1e851b..32edd959f 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -7,9 +7,9 @@ authors = ["Ashley Mannix "] elastic_reqwest = { version = "*", path = "../../" } reqwest = "~0.3.0" -serde = "~0.8.0" -serde_derive = "~0.8.0" -serde_json = "~0.8.0" +serde = "~0.9.0" +serde_derive = "~0.9.0" +serde_json = "~0.9.0" elastic_types = { version = "*", features = ["nightly"]} elastic_types_derive = "*" From 33af81b6a94af199169cc1b3eb26d9dd79227799 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 8 Feb 2017 11:41:11 +1000 Subject: [PATCH 065/127] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c2c399ba..03babd78a 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,14 @@ This library is the HTTP backend for the higher-level [`elastic`](https://github ## Build Status Platform | Channel | Status ------------- | ------------- | ------------- -Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-hyper.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-hyper) +Linux / OSX | Stable / Nightly | [![Build Status](https://travis-ci.org/elastic-rs/elastic-reqwest.svg?branch=master)](https://travis-ci.org/elastic-rs/elastic-reqwest) Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/status/yvsqsyt4ioxa11g8?svg=true)](https://ci.appveyor.com/project/KodrAus/elastic-hyper) ## Documentation Version | Docs ------------- | ------------- -`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-hyper/elastic_reqwest/) +`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-reqwest/elastic_reqwest/) `current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) ## Alternatives From 27562f47a56c1dae4ea30ed93270c639a51f7572 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 8 Feb 2017 12:04:53 +1000 Subject: [PATCH 066/127] cargo/0.4.0 --- Cargo.toml | 6 +++--- samples/typed/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cfba67e23..b99d87c15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,16 @@ [package] name = "elastic_reqwest" -version = "0.3.1" +version = "0.4.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/0.2.2/elastic_reqwest/" +documentation = "https://docs.rs/elastic_reqwest/*/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] elastic_requests = "~0.1.7" -reqwest = "~0.3.0" +reqwest = "~0.4.0" url = "~1" [dev-dependencies] diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 32edd959f..b86992a22 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Ashley Mannix "] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -reqwest = "~0.3.0" +reqwest = "~0.4.0" serde = "~0.9.0" serde_derive = "~0.9.0" serde_json = "~0.9.0" From 1adb6cccb15bc69b4da5944f18abdd84838ea69c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 8 Feb 2017 12:16:33 +1000 Subject: [PATCH 067/127] update typed sample --- samples/typed/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index a3938787f..14513d5ee 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -5,7 +5,7 @@ //! This sample executes a simple search request against some indexed data. //! The data is provided by a struct with mapping generated by `elastic_types`. -#![feature(plugin, proc_macro)] +#![feature(plugin)] #![plugin(json_str)] extern crate serde; From d88c8daa763b84cc33ec87ef32f37e05a577ddb3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 13 Feb 2017 14:31:21 +1000 Subject: [PATCH 068/127] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 03babd78a..18f3e7d46 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [`elastic_reqwest`](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) [![Latest Version](https://img.shields.io/crates/v/elastic_reqwest.svg)](https://crates.io/crates/elastic_reqwest) -Provides a synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose, and suitable for any scenario where on-demand requests are sufficient. +Provides a no-fuss, ssynchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose and suitable for any scenario where on-demand requests are sufficient. This library is the HTTP backend for the higher-level [`elastic`](https://github.com/elastic-rs/elastic) client. @@ -21,6 +21,8 @@ Version | Docs If you'd prefer to call Elasticsearch using a strongly-typed Query DSL builder, see [`rs-es`](https://github.com/benashford/rs-es). +For a higher-level client that supports strongly-typed response parsing, document mapping see [`elastic`](https://github.com/elastic-rs/elastic). It uses `elastic_reqwest` as its HTTP layer. + ## Example The `elastic_reqwest` client is a thin layer over `reqwest`; it just maps functions to routes. It's up to the caller to serialise and deserialise HTTP content. From f9dc63eff5751a4eb9dfc0583cf6e64858dbb073 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 13 Feb 2017 14:56:34 +1000 Subject: [PATCH 069/127] update docs --- src/lib.rs | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 31005ff8d..80973798a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -126,21 +126,16 @@ //! //! # See Also //! -//! ## [`elastic`](https://github.com/elastic-rs/elastic) -//! +//! - [`elastic`](https://github.com/elastic-rs/elastic). //! A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. -//! -//! ## [`rs-es`](https://github.com/benashford/rs-es) -//! +//! - [`rs-es`](https://github.com/benashford/rs-es). //! An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL. -//! -//! ## [`json_str`](https://github.com/KodrAus/json_str) -//! +//! - [`json_str`](https://github.com/KodrAus/json_str) //! A library for generating minified json strings from Rust syntax. //! //! # Links //! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) -//! - [Github](https://github.com/elastic-rs/elastic-hyper) +//! - [Github](https://github.com/elastic-rs/elastic-reqwest) #![deny(warnings)] #![deny(missing_docs)] @@ -177,30 +172,27 @@ use self::req::{HttpRequest, HttpMethod, RawBody}; /// With default query parameters: /// /// ``` -/// extern crate elastic_reqwest as elastic; -/// -/// let params = elastic::RequestParams::default(); +/// # use elastic_reqwest::RequestParams; +/// let params = RequestParams::default(); /// ``` /// /// With a custom base url: /// /// ``` -/// extern crate reqwest; -/// extern crate elastic_reqwest as elastic; -/// -/// let params = elastic::RequestParams::new("http://mybaseurl:9200"); +/// # use elastic_reqwest::RequestParams; +/// let params = RequestParams::new("http://mybaseurl:9200"); /// ``` /// /// With custom headers: /// /// ``` -/// extern crate reqwest; -/// extern crate elastic_reqwest as elastic; -/// -/// use reqwest::header::Authorization; +/// # extern crate reqwest; +/// # extern crate elastic_reqwest; +/// # use elastic_reqwest::RequestParams; +/// # use reqwest::header::Authorization; /// /// # fn main() { -/// let params = elastic::RequestParams::default() +/// let params = RequestParams::default() /// .header(Authorization("let me in".to_owned())); /// # } /// ``` @@ -208,17 +200,17 @@ use self::req::{HttpRequest, HttpMethod, RawBody}; /// With url query parameters: /// /// ``` -/// extern crate elastic_reqwest as elastic; -/// +/// # extern crate elastic_reqwest; +/// # use elastic_reqwest::RequestParams; /// # fn main() { -/// let params = elastic::RequestParams::default() +/// let params = RequestParams::default() /// .url_param("pretty", true) /// .url_param("q", "*"); /// # } /// ``` #[derive(Debug, Clone)] pub struct RequestParams { - /// Base url for Elasticsearch + /// Base url for Elasticsearch. pub base_url: String, /// Simple key-value store for url query params. pub url_params: BTreeMap<&'static str, String>, @@ -228,6 +220,10 @@ pub struct RequestParams { impl RequestParams { /// Create a new container for request parameters. + /// + /// This method takes a fully-qualified url for the Elasticsearch + /// node. + /// It will also set the `Content-Type` header to `application/json`. pub fn new>(base: T) -> Self { let mut headers = Headers::new(); headers.set(ContentType::json()); @@ -239,7 +235,7 @@ impl RequestParams { } } - /// Set the base url for the node. + /// Set the base url for the Elasticsearch node. pub fn base_url>(mut self, base: T) -> Self { self.base_url = base.into(); @@ -247,6 +243,8 @@ impl RequestParams { } /// Set a url param value. + /// + /// These parameters are added as query parameters to request urls. pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { @@ -269,9 +267,12 @@ impl RequestParams { self } - /// Get the url params as a formatted string. + /// Get the url query params as a formatted string. /// /// Follows the `application/x-www-form-urlencoded` format. + /// This method returns the length of the query string and an optional + /// value. + /// If the value is `None`, then the length will be `0`. pub fn get_url_qry(&self) -> (usize, Option) { if self.url_params.len() > 0 { let qry: String = Serializer::for_suffix(String::from("?"), 1) From 47e7c5a12eb30f926a419c7f55c7e74d8f570545 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 13 Feb 2017 17:45:18 +1000 Subject: [PATCH 070/127] update docs and tests --- src/lib.rs | 185 +++++++++++++++++++++++++++++++++++++++++++-------- tests/mod.rs | 44 ------------ 2 files changed, 157 insertions(+), 72 deletions(-) delete mode 100644 tests/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 80973798a..58e2e4218 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -149,7 +149,7 @@ use std::collections::BTreeMap; use std::io::Cursor; use std::str; use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; -use reqwest::Response; +use reqwest::{RequestBuilder, Response}; use url::form_urlencoded::Serializer; /// Request types. @@ -190,7 +190,6 @@ use self::req::{HttpRequest, HttpMethod, RawBody}; /// # extern crate elastic_reqwest; /// # use elastic_reqwest::RequestParams; /// # use reqwest::header::Authorization; -/// /// # fn main() { /// let params = RequestParams::default() /// .header(Authorization("let me in".to_owned())); @@ -297,6 +296,13 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } +/// Represents a client that can send Elasticsearch requests. +pub trait ElasticClient { + /// Send a request and get a response. + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>; +} + macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); @@ -309,49 +315,172 @@ macro_rules! req_with_body { $client.request(reqwest::Method::$method, &$url) .headers($params.headers.to_owned()) .body(body) - .send() }) } -/// Represents a client that can send Elasticsearch requests. -pub trait ElasticClient { - /// Send a request and get a response. - fn elastic_req(&self, params: &RequestParams, req: I) -> Result - where I: Into>; +fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder + where I: Into> +{ + let req = req.into(); + + let (qry_len, qry) = params.get_url_qry(); + + let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry_len); + + url.push_str(¶ms.base_url); + url.push_str(&req.url); + + if let Some(qry) = qry { + url.push_str(&qry); + } + + let method = req.method; + let body = req.body; + + match method { + HttpMethod::Get => client.get(&url).headers(params.headers.to_owned()), + + HttpMethod::Post => req_with_body!(client, url, body, params, Post), + + HttpMethod::Head => client.head(&url).headers(params.headers.to_owned()), + + HttpMethod::Delete => client.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()), + + HttpMethod::Put => req_with_body!(client, url, body, params, Put), + + HttpMethod::Patch => req_with_body!(client, url, body, params, Patch), + } } impl ElasticClient for reqwest::Client { fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into> { - let req = req.into(); + build_req(&self, params, req).send() + } +} - let (qry_len, qry) = params.get_url_qry(); +#[cfg(test)] +mod tests { + use reqwest::{Client, RequestBuilder, Method}; + use super::*; + use super::req::*; - let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry_len); + fn params() -> RequestParams { + RequestParams::new("eshost:9200/path") + .url_param("pretty", true) + .url_param("q", "*") + } - url.push_str(¶ms.base_url); - url.push_str(&req.url); + fn expected_req(cli: &Client, method: Method, url: &str, body: Option>) -> RequestBuilder { + let req = cli.request(method, url) + .header(ContentType::json()); - if let Some(qry) = qry { - url.push_str(&qry); + match body { + Some(body) => req.body(body), + None => req } + } - let method = req.method; - let body = req.body; + fn assert_req(expected: RequestBuilder, actual: RequestBuilder) { + assert_eq!(format!("{:?}", expected), format!("{:?}", actual)); + } - match method { - HttpMethod::Get => self.get(&url).headers(params.headers.to_owned()).send(), + #[test] + fn head_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), PingRequest::new()); - HttpMethod::Post => req_with_body!(self, url, body, params, Post), + let url = "eshost:9200/path/?pretty=true&q=*"; - HttpMethod::Head => self.head(&url).headers(params.headers.to_owned()).send(), + let expected = expected_req(&cli, Method::Head, url, None); - HttpMethod::Delete => self.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()).send(), - - HttpMethod::Put => req_with_body!(self, url, body, params, Put), - - HttpMethod::Patch => req_with_body!(self, url, body, params, Patch), - } + assert_req(expected, req); } -} + + #[test] + fn get_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); + + let url = "eshost:9200/path/_search?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Get, url, None); + + assert_req(expected, req); + } + + #[test] + fn post_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); + + let url = "eshost:9200/path/idx/ty/_percolate?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Post, url, Some(vec![])); + + assert_req(expected, req); + } + + #[test] + fn put_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Put, url, Some(vec![])); + + assert_req(expected, req); + } + + #[test] + fn delete_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Delete, url, None); + + assert_req(expected, req); + } + + #[test] + fn request_params_has_default_content_type() { + let req = RequestParams::default(); + assert_eq!(Some(&ContentType::json()), req.headers.get::()); + } + + #[test] + fn request_params_has_default_base_url() { + let req = RequestParams::default(); + + assert_eq!("http://localhost:9200", req.base_url); + } + + #[test] + fn request_params_can_set_base_url() { + let req = RequestParams::default() + .base_url("http://eshost:9200"); + + assert_eq!("http://eshost:9200", req.base_url); + } + + #[test] + fn request_params_can_set_url_query() { + let req = RequestParams::default() + .url_param("pretty", false) + .url_param("pretty", true) + .url_param("q", "*"); + + assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); + } + + #[test] + fn empty_request_params_returns_empty_string() { + let req = RequestParams::default(); + + assert_eq!((0, None), req.get_url_qry()); + } +} \ No newline at end of file diff --git a/tests/mod.rs b/tests/mod.rs deleted file mode 100644 index 0bccc54a4..000000000 --- a/tests/mod.rs +++ /dev/null @@ -1,44 +0,0 @@ -extern crate reqwest; -extern crate url; -extern crate elastic_reqwest; - -use reqwest::header::*; -use elastic_reqwest::RequestParams; - -#[test] -fn request_params_has_default_content_type() { - let req = RequestParams::default(); - assert_eq!(Some(&ContentType::json()), req.headers.get::()); -} - -#[test] -fn request_params_has_default_base_url() { - let req = RequestParams::default(); - - assert_eq!("http://localhost:9200", req.base_url); -} - -#[test] -fn request_params_can_set_base_url() { - let req = RequestParams::default() - .base_url("http://eshost:9200"); - - assert_eq!("http://eshost:9200", req.base_url); -} - -#[test] -fn request_params_can_set_url_query() { - let req = RequestParams::default() - .url_param("pretty", false) - .url_param("pretty", true) - .url_param("q", "*"); - - assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); -} - -#[test] -fn empty_request_params_returns_empty_string() { - let req = RequestParams::default(); - - assert_eq!((0, None), req.get_url_qry()); -} \ No newline at end of file From b1c33b58943c827a354898ac3788f38c4b42f990 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 13 Feb 2017 17:46:18 +1000 Subject: [PATCH 071/127] cargo/0.4.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b99d87c15..883692436 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.4.0" +version = "0.4.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." From faea16a08deaa97a50c0b50b15bb84fadbbf47e1 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 13 Feb 2017 17:55:01 +1000 Subject: [PATCH 072/127] update readme sample --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03babd78a..906323e91 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,8 @@ use cli::req::SearchRequest; let (client, params) = cli::default().unwrap(); -let search = SearchRequest::for_index_ty( - "myindex", "mytype", - json_str!({ +let search = { + let body = json_str!({ query: { filtered: { query: { @@ -94,8 +93,10 @@ let search = SearchRequest::for_index_ty( } } } - }) -); + }); + + SearchRequest::for_index_ty("myindex", "mytype", body) +}; client.elastic_req(¶ms, search).unwrap(); ``` From 93bd2d972911962d2723ab785cccfd447c3990c3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Mar 2017 16:06:03 +1000 Subject: [PATCH 073/127] update elastic_requests --- Cargo.toml | 2 +- src/lib.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 883692436..17990a77a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = "~0.1.7" +elastic_requests = { version = "*", path = "../elastic-requests" } reqwest = "~0.4.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index 58e2e4218..0f8589443 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,7 +159,7 @@ pub mod req { pub use elastic_requests::*; } -use self::req::{HttpRequest, HttpMethod, RawBody}; +use self::req::{HttpRequest, HttpMethod}; /// Misc parameters for any request. /// @@ -306,8 +306,9 @@ pub trait ElasticClient { macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - - let body = match body.into_raw() { + let body_cow = body.into(); + + let body = match body_cow { Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), Cow::Owned(b) => b.into() }; From cf02d1de48e31c30d9e31b5292205dedfd04133d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Mar 2017 16:09:17 +1000 Subject: [PATCH 074/127] use into_inner --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f8589443..29ca61f7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -306,8 +306,8 @@ pub trait ElasticClient { macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body_cow = body.into(); - + let body_cow = body.into_inner(); + let body = match body_cow { Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), Cow::Owned(b) => b.into() From 8eb74c8c354d6e8c0c6bba584b6ddf0075132ddf Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Mar 2017 16:35:21 +1000 Subject: [PATCH 075/127] use stable requests --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 17990a77a..f8164d311 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.4.1" +version = "0.5.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = { version = "*", path = "../elastic-requests" } +elastic_requests = "~0.2.0" reqwest = "~0.4.0" url = "~1" From 71118ee0b7773de281f1702ce35c10efdabd902d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Mar 2017 16:45:17 +1000 Subject: [PATCH 076/127] update types --- samples/typed/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index b86992a22..7e99e90e9 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -10,7 +10,7 @@ reqwest = "~0.4.0" serde = "~0.9.0" serde_derive = "~0.9.0" serde_json = "~0.9.0" -elastic_types = { version = "*", features = ["nightly"]} +elastic_types = "*" elastic_types_derive = "*" json_str = { version = "*", features = ["nightly"]} From 08491d57b8858cad695d31eeaad24db825edfbd1 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 17 Mar 2017 06:36:11 +1000 Subject: [PATCH 077/127] update to generic requests --- Cargo.toml | 4 ++-- src/lib.rs | 27 +++++++++++---------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f8164d311..b379a1e7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.5.0" +version = "0.6.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -9,7 +9,7 @@ repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] [dependencies] -elastic_requests = "~0.2.0" +elastic_requests = { version = "~0.3.0", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/generic-body" } reqwest = "~0.4.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index 29ca61f7e..4c1abed1e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -144,9 +144,7 @@ extern crate elastic_requests; extern crate reqwest; extern crate url; -use std::borrow::Cow; use std::collections::BTreeMap; -use std::io::Cursor; use std::str; use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; use reqwest::{RequestBuilder, Response}; @@ -299,28 +297,24 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. - fn elastic_req(&self, params: &RequestParams, req: I) -> Result - where I: Into>; + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>, + B: Into; } macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - let body_cow = body.into_inner(); - - let body = match body_cow { - Cow::Borrowed(b) => reqwest::Body::new(Cursor::new(b)), - Cow::Owned(b) => b.into() - }; $client.request(reqwest::Method::$method, &$url) .headers($params.headers.to_owned()) - .body(body) + .body(body.into()) }) } -fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder - where I: Into> +fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder + where I: Into>, + B: Into { let req = req.into(); @@ -354,8 +348,9 @@ fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> Req } impl ElasticClient for reqwest::Client { - fn elastic_req(&self, params: &RequestParams, req: I) -> Result - where I: Into> + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>, + B: Into { build_req(&self, params, req).send() } @@ -484,4 +479,4 @@ mod tests { assert_eq!((0, None), req.get_url_qry()); } -} \ No newline at end of file +} From 16695e289bcdabed7b881094c5200f147a743fea Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 16 Mar 2017 21:08:23 +1000 Subject: [PATCH 078/127] fix bulk sample --- samples/bulk/src/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/samples/bulk/src/main.rs b/samples/bulk/src/main.rs index 448e6cf56..6d5d93c6f 100644 --- a/samples/bulk/src/main.rs +++ b/samples/bulk/src/main.rs @@ -39,24 +39,22 @@ macro_rules! bulk_req { bulk.push('\n'); } - BulkRequest::new(bulk) + bulk }) } #[cfg(feature="lazy_static")] lazy_static! { - static ref REQUEST: BulkRequest<'static> = { - bulk_req!() - }; + static ref REQUEST: String = bulk_req!(); } #[cfg(not(feature="lazy_static"))] -fn get_req() -> BulkRequest<'static> { +fn get_req() -> String { bulk_req!() } #[cfg(feature="lazy_static")] -fn get_req() -> &'static BulkRequest<'static> { +fn get_req() -> &'static str { &REQUEST } @@ -65,7 +63,7 @@ fn main() { let (client, params) = cli::default().unwrap(); // Send the bulk request. - let res = client.elastic_req(¶ms, get_req()).unwrap(); + let res = client.elastic_req(¶ms, BulkRequest::new(get_req())).unwrap(); println!("{:?}", res); } From 52eab1e9c5ec254720df4391d6ffd54843c08e70 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 17 Mar 2017 16:16:23 +1000 Subject: [PATCH 079/127] specialise body conversion --- .travis.yml | 1 + Cargo.toml | 3 +++ samples/bulk/Cargo.toml | 1 + src/lib.rs | 53 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9f6b44d00..0f7f6ae28 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ before_script: script: - | + travis-cargo --only nightly build --features nightly && travis-cargo build && travis-cargo test && travis-cargo bench && diff --git a/Cargo.toml b/Cargo.toml index b379a1e7a..a027d84f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,9 @@ documentation = "https://docs.rs/elastic_reqwest/*/elastic_reqwest/" repository = "https://github.com/elastic-rs/elastic-hyper" exclude = [ "samples" ] +[features] +nightly = [] + [dependencies] elastic_requests = { version = "~0.3.0", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/generic-body" } reqwest = "~0.4.0" diff --git a/samples/bulk/Cargo.toml b/samples/bulk/Cargo.toml index 588b8d9e7..278e1df3c 100644 --- a/samples/bulk/Cargo.toml +++ b/samples/bulk/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Ashley Mannix "] [features] +nightly = ["elastic_reqwest/nightly"] profiling = [] [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 4c1abed1e..3f3248f3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,15 @@ //! elastic_reqwest = "*" //! reqwest = "*" //! ``` +//! +//! On the `nightly` channel, you can use the `nightly` feature +//! to avoid copying borrowed body buffers: +//! +//! ```ignore +//! [dependencies] +//! elastic_reqwest = { version = "*", features = ["nightly"] } +//! reqwest = "*" +//! ``` //! //! Then reference in your crate root: //! @@ -137,6 +146,8 @@ //! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) //! - [Github](https://github.com/elastic-rs/elastic-reqwest) +#![cfg_attr(feature = "nightly", feature(specialization))] + #![deny(warnings)] #![deny(missing_docs)] @@ -144,6 +155,8 @@ extern crate elastic_requests; extern crate reqwest; extern crate url; +#[cfg(feature = "nightly")] +use std::io::Cursor; use std::collections::BTreeMap; use std::str; use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; @@ -294,12 +307,44 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } +/// A type that can be converted into a `reqwest::Body`. +pub trait IntoReqwestBody { + /// Convert self into a body. + fn into_body(self) -> reqwest::Body; +} + +impl> IntoReqwestBody for B { + #[cfg(feature = "nightly")] + default fn into_body(self) -> reqwest::Body { + self.into() + } + + #[cfg(not(feature = "nightly"))] + fn into_body(self) -> reqwest::Body { + self.into() + } +} + +#[cfg(feature = "nightly")] +impl IntoReqwestBody for &'static [u8] { + fn into_body(self) -> reqwest::Body { + reqwest::Body::new(Cursor::new(self)) + } +} + +#[cfg(feature = "nightly")] +impl IntoReqwestBody for &'static str { + fn into_body(self) -> reqwest::Body { + reqwest::Body::new(Cursor::new(self)) + } +} + /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, - B: Into; + B: IntoReqwestBody; } macro_rules! req_with_body { @@ -308,13 +353,13 @@ macro_rules! req_with_body { $client.request(reqwest::Method::$method, &$url) .headers($params.headers.to_owned()) - .body(body.into()) + .body(body.into_body()) }) } fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder where I: Into>, - B: Into + B: IntoReqwestBody { let req = req.into(); @@ -350,7 +395,7 @@ fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> impl ElasticClient for reqwest::Client { fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, - B: Into + B: IntoReqwestBody { build_req(&self, params, req).send() } From b8be9d82bf294a16ac87f228ebcdcb69c714e91e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 17 Mar 2017 16:33:15 +1000 Subject: [PATCH 080/127] tweak command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0f7f6ae28..ec338ac4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_script: script: - | - travis-cargo --only nightly build --features nightly && + travis-cargo --only nightly cargo build --features nightly && travis-cargo build && travis-cargo test && travis-cargo bench && From 03f50b0a41cd7d95e8b0c670800cc657197a50f3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 17 Mar 2017 16:35:21 +1000 Subject: [PATCH 081/127] try again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ec338ac4d..bc5656cd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ before_script: script: - | - travis-cargo --only nightly cargo build --features nightly && + travis-cargo --only nightly build -- --features nightly && travis-cargo build && travis-cargo test && travis-cargo bench && From 1c834a8a1c6ecabddc76aedc5e765602285338a7 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 20 Mar 2017 18:08:07 +1000 Subject: [PATCH 082/127] use stable requests --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a027d84f2..c557b3cf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ exclude = [ "samples" ] nightly = [] [dependencies] -elastic_requests = { version = "~0.3.0", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/generic-body" } +elastic_requests = "~0.3.0" reqwest = "~0.4.0" url = "~1" From 557f07e36cf8d1fb8cc3000e3dc56b7830d7a4b8 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 20 Mar 2017 18:17:12 +1000 Subject: [PATCH 083/127] test common types --- .travis.yml | 3 +-- src/lib.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bc5656cd7..9a1b28d1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,7 @@ before_script: script: - | - travis-cargo --only nightly build -- --features nightly && - travis-cargo build && + travis-cargo --only nightly test -- --features nightly && travis-cargo test && travis-cargo bench && cd samples/basic && diff --git a/src/lib.rs b/src/lib.rs index 3f3248f3f..d4a9fe386 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -487,6 +487,28 @@ mod tests { assert_req(expected, req); } + #[test] + fn owned_string_into_body() { + String::new().into_body(); + } + + #[test] + fn borrowed_string_into_body() { + "abc".into_body(); + } + + #[test] + fn owned_vec_into_body() { + Vec::new().into_body(); + } + + #[test] + fn borrowed_vec_into_body() { + static BODY: &'static [u8] = &[0, 1, 2]; + + (&BODY).into_body(); + } + #[test] fn request_params_has_default_content_type() { let req = RequestParams::default(); From 25680c3148a00a515451a55b1700b834a24fdbb4 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 27 Mar 2017 17:16:37 +1000 Subject: [PATCH 084/127] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 57d8348f3..c77305041 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [`elastic_reqwest`](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) [![Latest Version](https://img.shields.io/crates/v/elastic_reqwest.svg)](https://crates.io/crates/elastic_reqwest) -Provides a no-fuss, ssynchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose and suitable for any scenario where on-demand requests are sufficient. +Provides a no-fuss, synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose and suitable for any scenario where on-demand requests are sufficient. This library is the HTTP backend for the higher-level [`elastic`](https://github.com/elastic-rs/elastic) client. From 12ac2f3c72b0a1067d7390db17816293fc4cdb6d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 7 Apr 2017 19:41:22 +1000 Subject: [PATCH 085/127] update elastic_requests --- Cargo.toml | 4 ++-- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c557b3cf3..8c28031a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.6.0" +version = "0.7.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -12,7 +12,7 @@ exclude = [ "samples" ] nightly = [] [dependencies] -elastic_requests = "~0.3.0" +elastic_requests = { version = "~0.4.0", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/ping-get" } reqwest = "~0.4.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index d4a9fe386..6958b21db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -430,7 +430,7 @@ mod tests { #[test] fn head_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), PingRequest::new()); + let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); let url = "eshost:9200/path/?pretty=true&q=*"; From 1b892df63d43ceec51c90d3f41e220fc5e8ac76e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 8 Apr 2017 08:47:13 +1000 Subject: [PATCH 086/127] use stable requests --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8c28031a9..236aa9f5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ exclude = [ "samples" ] nightly = [] [dependencies] -elastic_requests = { version = "~0.4.0", git = "https://github.com/elastic-rs/elastic-requests.git", branch = "feat/ping-get" } +elastic_requests = "~0.4.0" reqwest = "~0.4.0" url = "~1" From 00c2c016514ae5323e9c7392d054e8b1131880dc Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 1 May 2017 18:10:36 +1000 Subject: [PATCH 087/127] update requests --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 236aa9f5f..9794977e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.7.0" +version = "0.7.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -12,7 +12,7 @@ exclude = [ "samples" ] nightly = [] [dependencies] -elastic_requests = "~0.4.0" +elastic_requests = "~0.4.1" reqwest = "~0.4.0" url = "~1" From 449f34fd597b0beb47c2059fd568ee85cc887a0c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 1 May 2017 18:17:28 +1000 Subject: [PATCH 088/127] cargo/0.7.1 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9794977e1..5fc236f9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,8 @@ version = "0.7.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." -documentation = "https://docs.rs/elastic_reqwest/*/elastic_reqwest/" -repository = "https://github.com/elastic-rs/elastic-hyper" +documentation = "https://docs.rs/elastic_reqwest/" +repository = "https://github.com/elastic-rs/elastic-reqwest" exclude = [ "samples" ] [features] From 368fce019c9e1e334add42959f344523e8f9fe9f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 5 May 2017 20:02:18 +1000 Subject: [PATCH 089/127] update typed dependencies --- samples/typed/Cargo.toml | 7 ++-- samples/typed/src/data.rs | 4 +- samples/typed/src/main.rs | 22 +++++------ samples/typed/src/response.rs | 69 ----------------------------------- 4 files changed, 17 insertions(+), 85 deletions(-) delete mode 100644 samples/typed/src/response.rs diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 7e99e90e9..0bbbc3c85 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -7,10 +7,11 @@ authors = ["Ashley Mannix "] elastic_reqwest = { version = "*", path = "../../" } reqwest = "~0.4.0" -serde = "~0.9.0" -serde_derive = "~0.9.0" -serde_json = "~0.9.0" +serde = "~1" +serde_derive = "~1" +serde_json = "~1" elastic_types = "*" elastic_types_derive = "*" +elastic_responses = "*" json_str = { version = "*", features = ["nightly"]} diff --git a/samples/typed/src/data.rs b/samples/typed/src/data.rs index 8ebdb9ba7..ad0a508ed 100644 --- a/samples/typed/src/data.rs +++ b/samples/typed/src/data.rs @@ -24,5 +24,5 @@ pub struct Index { #[derive(Default, Serialize)] struct Mappings { - mystruct: Document -} \ No newline at end of file + mystruct: Document, +} diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index 14513d5ee..f84842db6 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -17,6 +17,7 @@ extern crate serde_derive; extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; +extern crate elastic_responses; extern crate elastic_reqwest as cli; use std::net::Ipv4Addr; @@ -24,11 +25,10 @@ use reqwest::Client; use cli::{ElasticClient, RequestParams}; use cli::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; use elastic_types::prelude::*; +use elastic_responses::{HttpResponse, SearchResponseOf, Hit}; mod data; use data::*; -mod response; -use response::*; const INDEX: &'static str = "testidx"; @@ -38,8 +38,7 @@ fn main() { // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. - let index_params = RequestParams::default() - .url_param("refresh", true); + let index_params = RequestParams::default().url_param("refresh", true); // Create an index and map our type create_index(&client, ¶ms); @@ -55,10 +54,8 @@ fn main() { println!("results: {}", res.hits.total); - for hit in res.hits.hits { - if let Some(hit) = hit.source { - println!("hit: {:?}", hit); - } + for hit in res.hits() { + println!("hit: {:?}", hit); } } @@ -99,7 +96,7 @@ fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { client.elastic_req(¶ms, req).unwrap(); } -fn query(client: &Client, params: &RequestParams) -> SearchResponse { +fn query(client: &Client, params: &RequestParams) -> SearchResponseOf> { let req = SearchRequest::for_index_ty(INDEX, MyStruct::name(), json_lit!({ @@ -110,7 +107,10 @@ fn query(client: &Client, params: &RequestParams) -> SearchResponse { } })); - let res = client.elastic_req(¶ms, req).unwrap(); + let res = { + let res = client.elastic_req(¶ms, req).unwrap(); + HttpResponse::from_read(res.status().to_u16(), res) + }; - serde_json::de::from_reader(res).unwrap() + res.into_response().unwrap() } diff --git a/samples/typed/src/response.rs b/samples/typed/src/response.rs deleted file mode 100644 index 6cbb37598..000000000 --- a/samples/typed/src/response.rs +++ /dev/null @@ -1,69 +0,0 @@ -// NOTE: This module lives here until we have a proper crate for Elasticsearch responses - -use serde::Deserialize; - -/// A successful response from a Query DSL query. -#[derive(Debug, Deserialize)] -pub struct SearchResponse - where T: Deserialize -{ - /// The time taken to complete a query in ms. - pub took: u64, - /// Whether or not the query timed out. - pub timed_out: bool, - /// Metadata on shard activity. - #[serde(rename="_shards")] - pub shards: Shards, - /// Document results. - pub hits: SearchHits, -} - -/// Metadata on shard activity for a Query DSL query. -#[derive(Debug, Deserialize)] -pub struct Shards { - /// The total number of shards involved in this query. - pub total: u64, - /// The total number of shards that successfully executed the query. - pub successful: u64, - /// The total number of shards that failed to execute the query. - pub failed: u64, -} - -/// A collection of hits for a Query DSL query. -#[derive(Debug, Deserialize)] -pub struct SearchHits - where T: Deserialize -{ - /// The total number of hits. - pub total: u64, - /// Document results. - pub hits: Vec>, -} - -/// An individual hit for a Query DSL query. -#[derive(Debug, Deserialize)] -pub struct Hit - where T: Deserialize -{ - /// The index of the hit. - #[serde(rename="_index")] - pub index: String, - /// The type of the hit. - #[serde(rename="_type")] - pub doc_type: String, - /// The id of the hit. - #[serde(rename="_id")] - pub id: String, - /// The relevance score of the hit. - #[serde(rename="_score")] - pub score: Option, - /// The source document data. - #[serde(rename="_source")] - pub source: Option, - /// The index timestamp of the hit. - #[serde(rename="_timestamp")] - pub timestamp: Option, - /// The routing value of the hit. - #[serde(rename="_routing")] - pub routing: Option, -} From e1a6bf3a9599386599a22021578192a104870f2e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 8 May 2017 17:02:41 +1000 Subject: [PATCH 090/127] update typed deps --- samples/typed/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/typed/Cargo.toml b/samples/typed/Cargo.toml index 0bbbc3c85..cc07c5d88 100644 --- a/samples/typed/Cargo.toml +++ b/samples/typed/Cargo.toml @@ -10,8 +10,8 @@ reqwest = "~0.4.0" serde = "~1" serde_derive = "~1" serde_json = "~1" -elastic_types = "*" -elastic_types_derive = "*" -elastic_responses = "*" +elastic_types = "~0.15" +elastic_types_derive = "~0.15" +elastic_responses = "~0.7" json_str = { version = "*", features = ["nightly"]} From 9f9d2b177f427f81de28d7b3d8bc230ba9a2c273 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 19 May 2017 19:48:26 +1000 Subject: [PATCH 091/127] update reqwest --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5fc236f9f..bcff7c1e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.7.1" +version = "0.8.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -13,7 +13,7 @@ nightly = [] [dependencies] elastic_requests = "~0.4.1" -reqwest = "~0.4.0" +reqwest = "~0.6.0" url = "~1" [dev-dependencies] From fbf3bc4862679addd51922716c2b2d0a7cfe2ad0 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 20 May 2017 16:34:25 +1000 Subject: [PATCH 092/127] add elastic_responses --- Cargo.toml | 1 + samples/basic/src/main.rs | 28 ++++++++++++++++------------ src/lib.rs | 8 ++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bcff7c1e3..7caec326b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ nightly = [] [dependencies] elastic_requests = "~0.4.1" +elastic_responses = { version = "~0.8.0", path = "../../elastic-responses" } reqwest = "~0.6.0" url = "~1" diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index 48a68addc..bbf0ce905 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -18,23 +18,27 @@ fn main() { let (client, _) = cli::default().unwrap(); // Create a new set of params with pretty printing. - let params = RequestParams::default() - .url_param("pretty", true); + let params = RequestParams::default().url_param("pretty", true); // Create a query DSL request body. - let body = json_str!({ - query: { - query_string: { - query: "*" + let req = { + let body = json_str!({ + query: { + query_string: { + query: "*" + } } - } - }); + }); + + SearchRequest::for_index("_all", body) + }; // Send the request and read the response. - let mut res = client.elastic_req(¶ms, SearchRequest::for_index("_all", body)).unwrap(); + let res = { + let res = client.elastic_req(¶ms, req).unwrap(); - let mut message = String::new(); - res.read_to_string(&mut message).unwrap(); + cli::res::parse::().from_reader(res.status().to_u16(), res).unwrap() + }; - println!("Got response: {}", message); + println!("Got response: {:?}", res); } diff --git a/src/lib.rs b/src/lib.rs index 6958b21db..2d433396f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -152,6 +152,7 @@ #![deny(missing_docs)] extern crate elastic_requests; +extern crate elastic_responses; extern crate reqwest; extern crate url; @@ -170,6 +171,13 @@ pub mod req { pub use elastic_requests::*; } +/// Response types. +/// +/// These are re-exported from `elastic_responses` for convenience. +pub mod res { + pub use elastic_resonses::*; +} + use self::req::{HttpRequest, HttpMethod}; /// Misc parameters for any request. From 33ec8e5f554c2d3047729e8cb15d2b67d2aad17c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 20 May 2017 16:39:24 +1000 Subject: [PATCH 093/127] fix import issues --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7caec326b..d44316690 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ nightly = [] [dependencies] elastic_requests = "~0.4.1" -elastic_responses = { version = "~0.8.0", path = "../../elastic-responses" } +elastic_responses = { version = "~0.8.0", path = "../elastic-responses" } reqwest = "~0.6.0" url = "~1" diff --git a/src/lib.rs b/src/lib.rs index 2d433396f..07ca3e3f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,7 @@ pub mod req { /// /// These are re-exported from `elastic_responses` for convenience. pub mod res { - pub use elastic_resonses::*; + pub use elastic_responses::*; } use self::req::{HttpRequest, HttpMethod}; From d6ae4f89088760f793ce178f98667249c3dbd4fd Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 22 May 2017 19:22:12 +1000 Subject: [PATCH 094/127] update response parsing --- samples/basic/src/main.rs | 9 ++++----- samples/bulk/src/main.rs | 7 +++++-- samples/typed/src/main.rs | 19 ++++++++++--------- src/lib.rs | 24 ++++++++++++++++++++---- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/samples/basic/src/main.rs b/samples/basic/src/main.rs index bbf0ce905..251dc82f5 100644 --- a/samples/basic/src/main.rs +++ b/samples/basic/src/main.rs @@ -9,8 +9,9 @@ extern crate json_str; extern crate elastic_reqwest as cli; -use cli::{ElasticClient, RequestParams}; +use cli::{ElasticClient, ParseResponse, RequestParams}; use cli::req::SearchRequest; +use cli::res::{parse, SearchResponse}; use std::io::Read; fn main() { @@ -34,11 +35,9 @@ fn main() { }; // Send the request and read the response. - let res = { - let res = client.elastic_req(¶ms, req).unwrap(); + let http_res = client.elastic_req(¶ms, req).unwrap(); - cli::res::parse::().from_reader(res.status().to_u16(), res).unwrap() - }; + let res = parse::().from_response(http_res).unwrap(); println!("Got response: {:?}", res); } diff --git a/samples/bulk/src/main.rs b/samples/bulk/src/main.rs index 6d5d93c6f..293c86daa 100644 --- a/samples/bulk/src/main.rs +++ b/samples/bulk/src/main.rs @@ -22,8 +22,9 @@ extern crate lazy_static; extern crate elastic_reqwest as cli; -use cli::ElasticClient; +use cli::{ElasticClient, ParseResponse}; use cli::req::BulkRequest; +use cli::res::{parse, BulkResponse}; // Create a bulk request to index a bunch of docs. macro_rules! bulk_req { @@ -63,7 +64,9 @@ fn main() { let (client, params) = cli::default().unwrap(); // Send the bulk request. - let res = client.elastic_req(¶ms, BulkRequest::new(get_req())).unwrap(); + let http_res = client.elastic_req(¶ms, BulkRequest::new(get_req())).unwrap(); + + let res = parse::().from_response(http_res).unwrap(); println!("{:?}", res); } diff --git a/samples/typed/src/main.rs b/samples/typed/src/main.rs index f84842db6..8b745df75 100644 --- a/samples/typed/src/main.rs +++ b/samples/typed/src/main.rs @@ -22,10 +22,10 @@ extern crate elastic_reqwest as cli; use std::net::Ipv4Addr; use reqwest::Client; -use cli::{ElasticClient, RequestParams}; +use cli::{ElasticClient, ParseResponse, RequestParams}; use cli::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; +use cli::res::{parse, CommandResponse, IndexResponse, SearchResponseOf, Hit}; use elastic_types::prelude::*; -use elastic_responses::{HttpResponse, SearchResponseOf, Hit}; mod data; use data::*; @@ -63,7 +63,9 @@ fn create_index(client: &Client, params: &RequestParams) { let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&Index::default()).unwrap()); // Create index - client.elastic_req(¶ms, req).unwrap(); + let res = client.elastic_req(¶ms, req).unwrap(); + + parse::().from_response(res).unwrap(); } fn get_data() -> Vec { @@ -93,7 +95,9 @@ fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { datum.id.to_string(), serde_json::to_string(&datum).unwrap()); - client.elastic_req(¶ms, req).unwrap(); + let res = client.elastic_req(¶ms, req).unwrap(); + + parse::().from_response(res).unwrap(); } fn query(client: &Client, params: &RequestParams) -> SearchResponseOf> { @@ -107,10 +111,7 @@ fn query(client: &Client, params: &RequestParams) -> SearchResponseOf().from_response(http_res).unwrap(); //! # } //! ``` //! @@ -99,8 +101,9 @@ //! #[macro_use] //! extern crate json_str; //! extern crate elastic_reqwest as cli; -//! use cli::ElasticClient; +//! use cli::{ElasticClient, ParseResponse}; //! use cli::req::SearchRequest; +//! use cli::res::{parse, SearchResponse}; //! //! # fn main() { //! let (client, params) = cli::default().unwrap(); @@ -127,7 +130,8 @@ //! }) //! ); //! -//! client.elastic_req(¶ms, search).unwrap(); +//! let http_res = client.elastic_req(¶ms, search).unwrap(); +//! let search_res = parse::().from_response(http_res).unwrap(); //! # } //! ``` //! @@ -355,6 +359,18 @@ pub trait ElasticClient { B: IntoReqwestBody; } +/// Represents a response that can be parsed into a concrete Elasticsearch response. +pub trait ParseResponse { + /// Parse a response into a concrete response type. + fn from_response(self, response: Response) -> Result; +} + +impl ParseResponse for Parse { + fn from_response(self, response: Response) -> Result { + self.from_reader(response.status().to_u16(), response) + } +} + macro_rules! req_with_body { ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); From c3243023f9817dd0adad510905d57efa4f34de7b Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 24 May 2017 17:28:51 +1000 Subject: [PATCH 095/127] work on some docs --- Cargo.toml | 1 + src/lib.rs | 87 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 65 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d44316690..190c47be2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ exclude = [ "samples" ] nightly = [] [dependencies] +serde = "~1" elastic_requests = "~0.4.1" elastic_responses = { version = "~0.8.0", path = "../elastic-responses" } reqwest = "~0.6.0" diff --git a/src/lib.rs b/src/lib.rs index bb326cbdc..69371f897 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,14 @@ //! Elasticsearch REST API Client //! //! A lightweight implementation of the Elasticsearch API based on the -//! [`reqwest`](https://github.com/seanmonstar/reqwest/) HTTP client. +//! [`reqwest`][reqwest] HTTP client. //! -//! Each API endpoint is represented as its own function, -//! so each possible http route gets its own function. +//! Each API endpoint is represented as its own type, that only accept a valid combination +//! of route parameters. //! This library makes very few assumptions, leaving it up to you to decide what to invest your //! precious CPU cycles into. //! -//! The entire API is generated from the official Elasticsearch spec, so it's always current. +//! The API is generated from the official Elasticsearch spec, so it's always current. //! //! # Supported Versions //! @@ -18,7 +18,7 @@ //! //! # Usage //! -//! This crate is on [crates.io](https://crates.io/crates/reqwest). +//! This crate is on [crates.io][crates]. //! To get started, add `elastic_reqwest` and `reqwest` to your `Cargo.toml`: //! //! ```ignore @@ -39,8 +39,18 @@ //! Then reference in your crate root: //! //! ``` +//! extern crate reqwest; //! extern crate elastic_reqwest as cli; +//! +//! use cli::{ElasticClient, ParseResponse, parse}; //! ``` +//! +//! ## The Gist +//! +//! - Create a [`reqwest::Client`][default] +//! - Call [`elastic_req`][elastic_req] on the client +//! - Work with the raw http response +//! - Or call [`parse`][parse] to get a concrete response or API error //! //! ## Minimal Example //! @@ -65,13 +75,13 @@ //! Execute a search query with a url parameter: //! //! ```no_run -//! //HTTP GET /myindex/mytype/_search?q='my string' +//! //HTTP GET /myindex/mytype/_search?q=* //! -//! extern crate reqwest; //! extern crate elastic_reqwest as cli; -//! use cli::{ ElasticClient, ParseResponse, RequestParams }; +//! +//! use cli::{ ElasticClient, ParseResponse, RequestParams, parse }; //! use cli::req::SimpleSearchRequest; -//! use cli::res::{parse, SearchResponse}; +//! use cli::res::SearchResponse; //! //! # fn main() { //! let (client, _) = cli::default().unwrap(); @@ -91,19 +101,19 @@ //! //! ## Search Request with Json //! -//! Using the [`json_str`](http://kodraus.github.io/rustdoc/json_str/) crate, you can execute +//! Using the [`json_str`][json_str] crate, you can execute //! queries using pure json: //! //! ```no_run //! //HTTP POST /myindex/mytype/_search //! -//! # //! #[macro_use] //! extern crate json_str; //! extern crate elastic_reqwest as cli; -//! use cli::{ElasticClient, ParseResponse}; +//! +//! use cli::{ElasticClient, ParseResponse, parse}; //! use cli::req::SearchRequest; -//! use cli::res::{parse, SearchResponse}; +//! use cli::res::SearchResponse; //! //! # fn main() { //! let (client, params) = cli::default().unwrap(); @@ -135,20 +145,29 @@ //! # } //! ``` //! -//! See more [examples](https://github.com/KodrAus/elasticsearch-rs/tree/master/hyper/samples). -//! //! # See Also //! -//! - [`elastic`](https://github.com/elastic-rs/elastic). +//! - [`elastic`][elastic]. //! A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. -//! - [`rs-es`](https://github.com/benashford/rs-es). -//! An alternative Elasticsearch client for Rust that provides an implementation of the Query DSL. -//! - [`json_str`](https://github.com/KodrAus/json_str) +//! - [`rs-es`][rs-es]. +//! A higher-level Elasticsearch client that provides strongly-typed Query DSL buiilders. +//! - [`json_str`][json_str] //! A library for generating minified json strings from Rust syntax. //! //! # Links -//! - [Elasticsearch Docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html) -//! - [Github](https://github.com/elastic-rs/elastic-reqwest) +//! - [Elasticsearch Docs][es-docs] +//! - [Github][repo] +//! +//! [default]: fn.default.html +//! [elastic_req]: trait.ElasticClient.html#tymethod.elastic_req +//! [parse]: fn.parse.html +//! [elastic]: https://github.com/elastic-rs/elastic +//! [rs-es]: https://github.com/benashford/rs-es +//! [json_str]: https://github.com/KodrAus/json_str +//! [reqwest]: https://github.com/seanmonstar/reqwest/ +//! [es-docs]: https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html +//! [repo]: https://github.com/elastic-rs/elastic-reqwest +//! [crates]: https://crates.io/crates/elastic_reqwest #![cfg_attr(feature = "nightly", feature(specialization))] @@ -157,6 +176,7 @@ extern crate elastic_requests; extern crate elastic_responses; +extern crate serde; extern crate reqwest; extern crate url; @@ -164,6 +184,7 @@ extern crate url; use std::io::Cursor; use std::collections::BTreeMap; use std::str; +use serde::de::DeserializeOwned; use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; use reqwest::{RequestBuilder, Response}; use url::form_urlencoded::Serializer; @@ -182,7 +203,11 @@ pub mod res { pub use elastic_responses::*; } +pub use self::res::parse; + use self::req::{HttpRequest, HttpMethod}; +use self::res::parsing::{Parse, IsOk}; +use self::res::error::ResponseError; /// Misc parameters for any request. /// @@ -319,7 +344,7 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } -/// A type that can be converted into a `reqwest::Body`. +/// A type that can be converted into a request body. pub trait IntoReqwestBody { /// Convert self into a body. fn into_body(self) -> reqwest::Body; @@ -354,6 +379,22 @@ impl IntoReqwestBody for &'static str { /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. + /// + /// # Examples + /// + /// Bring the `ElasticClient` trait into scope and call `elastic_req` with any type that + /// can be converted into a `req::HttpRequest`. + /// This method returns a raw `reqwest::Response`. + /// + /// ``` + /// # use elastic_reqwest::req::SimpleSearchRequest; + /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); + /// use elastic_reqwest::ElasticClient; + /// + /// let (client, params) = elastic_reqwest::default().unwrap(); + /// + /// let http_res = client.elastic_req(¶ms, request).unwrap(); + /// ``` fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoReqwestBody; @@ -362,7 +403,7 @@ pub trait ElasticClient { /// Represents a response that can be parsed into a concrete Elasticsearch response. pub trait ParseResponse { /// Parse a response into a concrete response type. - fn from_response(self, response: Response) -> Result; + fn from_response(self, response: Response) -> Result; } impl ParseResponse for Parse { From 2cead2c226ac106722dc52a382ae0af1d120cc02 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 24 May 2017 08:53:56 +1000 Subject: [PATCH 096/127] track stable elastic_responses --- Cargo.toml | 2 +- elastic_hyper.rsproj | 39 --------------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 elastic_hyper.rsproj diff --git a/Cargo.toml b/Cargo.toml index 190c47be2..ba0b4f8d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ nightly = [] [dependencies] serde = "~1" elastic_requests = "~0.4.1" -elastic_responses = { version = "~0.8.0", path = "../elastic-responses" } +elastic_responses = "~0.8.0" reqwest = "~0.6.0" url = "~1" diff --git a/elastic_hyper.rsproj b/elastic_hyper.rsproj deleted file mode 100644 index 3c80c65f3..000000000 --- a/elastic_hyper.rsproj +++ /dev/null @@ -1,39 +0,0 @@ - - - - Debug - default - {e7571d90-a65d-43a6-acf7-52d62fccf1c9} - library - elastic_hyper - elastic_hyper - elastic_hyper - - - false - true - 0 - default - - - false - false - 2 - default - - - - - - - - - - - - - - - - - \ No newline at end of file From 0dae4c93e0e32fb7735e0c0870de18067f542a2d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 24 May 2017 16:43:12 +1000 Subject: [PATCH 097/127] fix up failing tests --- src/lib.rs | 71 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 69371f897..e92a6ce5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,10 +26,10 @@ //! elastic_reqwest = "*" //! reqwest = "*" //! ``` -//! +//! //! On the `nightly` channel, you can use the `nightly` feature //! to avoid copying borrowed body buffers: -//! +//! //! ```ignore //! [dependencies] //! elastic_reqwest = { version = "*", features = ["nightly"] } @@ -41,12 +41,13 @@ //! ``` //! extern crate reqwest; //! extern crate elastic_reqwest as cli; -//! +//! //! use cli::{ElasticClient, ParseResponse, parse}; +//! # fn main() {} //! ``` -//! +//! //! ## The Gist -//! +//! //! - Create a [`reqwest::Client`][default] //! - Call [`elastic_req`][elastic_req] on the client //! - Work with the raw http response @@ -78,7 +79,7 @@ //! //HTTP GET /myindex/mytype/_search?q=* //! //! extern crate elastic_reqwest as cli; -//! +//! //! use cli::{ ElasticClient, ParseResponse, RequestParams, parse }; //! use cli::req::SimpleSearchRequest; //! use cli::res::SearchResponse; @@ -110,7 +111,7 @@ //! #[macro_use] //! extern crate json_str; //! extern crate elastic_reqwest as cli; -//! +//! //! use cli::{ElasticClient, ParseResponse, parse}; //! use cli::req::SearchRequest; //! use cli::res::SearchResponse; @@ -147,7 +148,7 @@ //! //! # See Also //! -//! - [`elastic`][elastic]. +//! - [`elastic`][elastic]. //! A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. //! - [`rs-es`][rs-es]. //! A higher-level Elasticsearch client that provides strongly-typed Query DSL buiilders. @@ -157,7 +158,7 @@ //! # Links //! - [Elasticsearch Docs][es-docs] //! - [Github][repo] -//! +//! //! [default]: fn.default.html //! [elastic_req]: trait.ElasticClient.html#tymethod.elastic_req //! [parse]: fn.parse.html @@ -190,14 +191,14 @@ use reqwest::{RequestBuilder, Response}; use url::form_urlencoded::Serializer; /// Request types. -/// +/// /// These are re-exported from `elastic_requests` for convenience. pub mod req { pub use elastic_requests::*; } /// Response types. -/// +/// /// These are re-exported from `elastic_responses` for convenience. pub mod res { pub use elastic_responses::*; @@ -267,7 +268,7 @@ pub struct RequestParams { impl RequestParams { /// Create a new container for request parameters. - /// + /// /// This method takes a fully-qualified url for the Elasticsearch /// node. /// It will also set the `Content-Type` header to `application/json`. @@ -290,15 +291,13 @@ impl RequestParams { } /// Set a url param value. - /// + /// /// These parameters are added as query parameters to request urls. - pub fn url_param(mut self, key: &'static str, value: T) -> Self - { + pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { let mut entry = self.url_params.get_mut(key).unwrap(); *entry = value.to_string(); - } - else { + } else { self.url_params.insert(key, value.to_string()); } @@ -379,23 +378,23 @@ impl IntoReqwestBody for &'static str { /// Represents a client that can send Elasticsearch requests. pub trait ElasticClient { /// Send a request and get a response. - /// + /// /// # Examples - /// + /// /// Bring the `ElasticClient` trait into scope and call `elastic_req` with any type that /// can be converted into a `req::HttpRequest`. /// This method returns a raw `reqwest::Response`. - /// - /// ``` + /// + /// ```no_run /// # use elastic_reqwest::req::SimpleSearchRequest; /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); /// use elastic_reqwest::ElasticClient; - /// + /// /// let (client, params) = elastic_reqwest::default().unwrap(); - /// + /// /// let http_res = client.elastic_req(¶ms, request).unwrap(); /// ``` - fn elastic_req(&self, params: &RequestParams, req: I) -> Result + fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoReqwestBody; } @@ -422,7 +421,7 @@ macro_rules! req_with_body { }) } -fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder +fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder where I: Into>, B: IntoReqwestBody { @@ -450,9 +449,9 @@ fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> HttpMethod::Head => client.head(&url).headers(params.headers.to_owned()), HttpMethod::Delete => client.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()), - + HttpMethod::Put => req_with_body!(client, url, body, params, Put), - + HttpMethod::Patch => req_with_body!(client, url, body, params, Patch), } } @@ -480,11 +479,11 @@ mod tests { fn expected_req(cli: &Client, method: Method, url: &str, body: Option>) -> RequestBuilder { let req = cli.request(method, url) - .header(ContentType::json()); + .header(ContentType::json()); match body { Some(body) => req.body(body), - None => req + None => req, } } @@ -519,7 +518,9 @@ mod tests { #[test] fn post_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); + let req = build_req(&cli, + ¶ms(), + PercolateRequest::for_index_ty("idx", "ty", vec![])); let url = "eshost:9200/path/idx/ty/_percolate?pretty=true&q=*"; @@ -531,7 +532,9 @@ mod tests { #[test] fn put_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); + let req = build_req(&cli, + ¶ms(), + IndicesCreateRequest::for_index("idx", vec![])); let url = "eshost:9200/path/idx?pretty=true&q=*"; @@ -589,8 +592,7 @@ mod tests { #[test] fn request_params_can_set_base_url() { - let req = RequestParams::default() - .base_url("http://eshost:9200"); + let req = RequestParams::default().base_url("http://eshost:9200"); assert_eq!("http://eshost:9200", req.base_url); } @@ -602,7 +604,8 @@ mod tests { .url_param("pretty", true) .url_param("q", "*"); - assert_eq!((16, Some(String::from("?pretty=true&q=*"))), req.get_url_qry()); + assert_eq!((16, Some(String::from("?pretty=true&q=*"))), + req.get_url_qry()); } #[test] From 43c0c63381de5421c8606e2cf132af64f55a3d1c Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 24 May 2017 17:10:24 +1000 Subject: [PATCH 098/127] rename samples to examples --- .travis.yml | 2 +- {samples/basic => examples}/.gitignore | 0 examples/Cargo.toml | 6 ++++++ {samples => examples}/README.md | 0 {samples/bulk => examples/basic}/.gitignore | 0 {samples => examples}/basic/Cargo.toml | 0 {samples => examples}/basic/src/main.rs | 1 - {samples/typed => examples/bulk}/.gitignore | 0 {samples => examples}/bulk/Cargo.toml | 0 {samples => examples}/bulk/src/main.rs | 0 examples/typed/.gitignore | 2 ++ {samples => examples}/typed/Cargo.toml | 5 ++--- {samples => examples}/typed/src/data.rs | 0 {samples => examples}/typed/src/main.rs | 1 - 14 files changed, 11 insertions(+), 6 deletions(-) rename {samples/basic => examples}/.gitignore (100%) create mode 100644 examples/Cargo.toml rename {samples => examples}/README.md (100%) rename {samples/bulk => examples/basic}/.gitignore (100%) rename {samples => examples}/basic/Cargo.toml (100%) rename {samples => examples}/basic/src/main.rs (98%) rename {samples/typed => examples/bulk}/.gitignore (100%) rename {samples => examples}/bulk/Cargo.toml (100%) rename {samples => examples}/bulk/src/main.rs (100%) create mode 100644 examples/typed/.gitignore rename {samples => examples}/typed/Cargo.toml (78%) rename {samples => examples}/typed/src/data.rs (100%) rename {samples => examples}/typed/src/main.rs (99%) diff --git a/.travis.yml b/.travis.yml index 9a1b28d1e..54f086116 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ script: travis-cargo --only nightly test -- --features nightly && travis-cargo test && travis-cargo bench && - cd samples/basic && + cd examples/basic && travis-cargo build && cd ../bulk && travis-cargo build && diff --git a/samples/basic/.gitignore b/examples/.gitignore similarity index 100% rename from samples/basic/.gitignore rename to examples/.gitignore diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 000000000..364b0686e --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,6 @@ +[workspace] +members = [ + "basic", + "typed", + "bulk", +] \ No newline at end of file diff --git a/samples/README.md b/examples/README.md similarity index 100% rename from samples/README.md rename to examples/README.md diff --git a/samples/bulk/.gitignore b/examples/basic/.gitignore similarity index 100% rename from samples/bulk/.gitignore rename to examples/basic/.gitignore diff --git a/samples/basic/Cargo.toml b/examples/basic/Cargo.toml similarity index 100% rename from samples/basic/Cargo.toml rename to examples/basic/Cargo.toml diff --git a/samples/basic/src/main.rs b/examples/basic/src/main.rs similarity index 98% rename from samples/basic/src/main.rs rename to examples/basic/src/main.rs index 251dc82f5..f97f3bc93 100644 --- a/samples/basic/src/main.rs +++ b/examples/basic/src/main.rs @@ -12,7 +12,6 @@ extern crate elastic_reqwest as cli; use cli::{ElasticClient, ParseResponse, RequestParams}; use cli::req::SearchRequest; use cli::res::{parse, SearchResponse}; -use std::io::Read; fn main() { // Get a new default client. diff --git a/samples/typed/.gitignore b/examples/bulk/.gitignore similarity index 100% rename from samples/typed/.gitignore rename to examples/bulk/.gitignore diff --git a/samples/bulk/Cargo.toml b/examples/bulk/Cargo.toml similarity index 100% rename from samples/bulk/Cargo.toml rename to examples/bulk/Cargo.toml diff --git a/samples/bulk/src/main.rs b/examples/bulk/src/main.rs similarity index 100% rename from samples/bulk/src/main.rs rename to examples/bulk/src/main.rs diff --git a/examples/typed/.gitignore b/examples/typed/.gitignore new file mode 100644 index 000000000..ab22063e1 --- /dev/null +++ b/examples/typed/.gitignore @@ -0,0 +1,2 @@ +/target/ +/obj/ \ No newline at end of file diff --git a/samples/typed/Cargo.toml b/examples/typed/Cargo.toml similarity index 78% rename from samples/typed/Cargo.toml rename to examples/typed/Cargo.toml index cc07c5d88..e913577a7 100644 --- a/samples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -10,8 +10,7 @@ reqwest = "~0.4.0" serde = "~1" serde_derive = "~1" serde_json = "~1" -elastic_types = "~0.15" -elastic_types_derive = "~0.15" -elastic_responses = "~0.7" +elastic_types = "~0.18" +elastic_types_derive = "~0.18" json_str = { version = "*", features = ["nightly"]} diff --git a/samples/typed/src/data.rs b/examples/typed/src/data.rs similarity index 100% rename from samples/typed/src/data.rs rename to examples/typed/src/data.rs diff --git a/samples/typed/src/main.rs b/examples/typed/src/main.rs similarity index 99% rename from samples/typed/src/main.rs rename to examples/typed/src/main.rs index 8b745df75..85ab032c7 100644 --- a/samples/typed/src/main.rs +++ b/examples/typed/src/main.rs @@ -17,7 +17,6 @@ extern crate serde_derive; extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; -extern crate elastic_responses; extern crate elastic_reqwest as cli; use std::net::Ipv4Addr; From 5e67d7c3ed4ec578790544a3ef1c50389efd2d48 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 26 May 2017 02:56:57 +1000 Subject: [PATCH 099/127] update readme --- README.md | 16 +++++++++++----- examples/Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c77305041..260217836 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # [`elastic_reqwest`](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) [![Latest Version](https://img.shields.io/crates/v/elastic_reqwest.svg)](https://crates.io/crates/elastic_reqwest) -Provides a no-fuss, synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose and suitable for any scenario where on-demand requests are sufficient. +Provides a no-fuss, synchronous [`reqwest`](https://github.com/seanmonstar/reqwest) implementation of the Elasticsearch REST API. The `reqwest` client is simple to use; there's basically no setup needed besides creating a `reqwest::Client` object to use for requests. The `reqwest` client is general-purpose and suitable for any scenario where on-demand requests are sufficient. It also splits the request process into a few logical methods that could be easily split across asynchronous boundaries. This library is the HTTP backend for the higher-level [`elastic`](https://github.com/elastic-rs/elastic) client. @@ -49,12 +49,15 @@ Ping the availability of your cluster: extern crate elastic_reqwest as cli; extern crate reqwest; -use cli::ElasticClient; +use cli::{ElasticClient, ParseResponse, parse}; use cli::req::PingRequest; +use cli::res::PingResponse; let (client, params) = cli::default().unwrap(); -client.elastic_req(¶ms, PingRequest::new()).unwrap(); +let http_res = client.elastic_req(¶ms, PingRequest::new()).unwrap(); + +let parse_res = parse::().from_response(http_res).unwrap(); ``` Customise the location of the Elasticsearch cluster: @@ -72,8 +75,9 @@ extern crate json_str; extern crate elastic_reqwest as cli; extern crate reqwest; -use cli::ElasticClient; +use cli::{ElasticClient, ParseResponse, parse}; use cli::req::SearchRequest; +use cli::res::SearchResponse; let (client, params) = cli::default().unwrap(); @@ -100,5 +104,7 @@ let search = { SearchRequest::for_index_ty("myindex", "mytype", body) }; -client.elastic_req(¶ms, search).unwrap(); +let http_res = client.elastic_req(¶ms, search).unwrap(); + +let search_res = parse::().from_response(http_res).unwrap(); ``` diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 364b0686e..08deee55e 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "basic", + "basic", "typed", "bulk", ] \ No newline at end of file From 35048518eda92f67ba83751127147cce2a58af28 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 25 May 2017 17:03:01 +1000 Subject: [PATCH 100/127] fix typed sample --- examples/typed/Cargo.toml | 6 +++--- examples/typed/src/data.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml index e913577a7..6f6d65e8a 100644 --- a/examples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -6,11 +6,11 @@ authors = ["Ashley Mannix "] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -reqwest = "~0.4.0" +reqwest = "~0.6" serde = "~1" serde_derive = "~1" serde_json = "~1" -elastic_types = "~0.18" -elastic_types_derive = "~0.18" +elastic_types = "~0.17" +elastic_types_derive = "~0.17" json_str = { version = "*", features = ["nightly"]} diff --git a/examples/typed/src/data.rs b/examples/typed/src/data.rs index ad0a508ed..94f4b1782 100644 --- a/examples/typed/src/data.rs +++ b/examples/typed/src/data.rs @@ -24,5 +24,5 @@ pub struct Index { #[derive(Default, Serialize)] struct Mappings { - mystruct: Document, + mystruct: IndexDocumentMapping, } From d81d9fcf442bca84076bf6f2a2db1267d5d049fa Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 25 May 2017 17:09:06 +1000 Subject: [PATCH 101/127] nit: crate name --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index b9f6d55c6..d36977bee 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,3 +1,3 @@ # `elastic_reqwest` samples -This repo contains a few samples for the `elastic_hyper` crate. +This repo contains a few samples for the `elastic_reqwest` crate. From 0e076f5613e61eab31eae5493a17bd375eaefd05 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 22 Jun 2017 20:45:48 +1000 Subject: [PATCH 102/127] update to elastic_types 0.18.0 --- examples/typed/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml index 6f6d65e8a..d36742f2a 100644 --- a/examples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -10,7 +10,7 @@ reqwest = "~0.6" serde = "~1" serde_derive = "~1" serde_json = "~1" -elastic_types = "~0.17" -elastic_types_derive = "~0.17" +elastic_types = "~0.18" +elastic_types_derive = "~0.18" json_str = { version = "*", features = ["nightly"]} From 97c806ebba1cd8906f6136b58d0b9c2e15a2914d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 5 Jul 2017 17:10:35 +1000 Subject: [PATCH 103/127] move sync impl into sync module --- Cargo.toml | 6 +- examples/typed/Cargo.toml | 4 +- examples/typed/src/data.rs | 4 +- examples/typed/src/main.rs | 4 +- src/async.rs | 0 src/lib.rs | 267 +++++-------------------------------- src/sync.rs | 242 +++++++++++++++++++++++++++++++++ 7 files changed, 282 insertions(+), 245 deletions(-) create mode 100644 src/async.rs create mode 100644 src/sync.rs diff --git a/Cargo.toml b/Cargo.toml index ba0b4f8d4..e52ec66a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.8.0" +version = "0.9.0" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." @@ -14,8 +14,8 @@ nightly = [] [dependencies] serde = "~1" elastic_requests = "~0.4.1" -elastic_responses = "~0.8.0" -reqwest = "~0.6.0" +elastic_responses = "~0.9.0" +reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git" } url = "~1" [dev-dependencies] diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml index d36742f2a..0b7544215 100644 --- a/examples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -10,7 +10,7 @@ reqwest = "~0.6" serde = "~1" serde_derive = "~1" serde_json = "~1" -elastic_types = "~0.18" -elastic_types_derive = "~0.18" +elastic_types = "~0.19" +elastic_types_derive = "~0.19" json_str = { version = "*", features = ["nightly"]} diff --git a/examples/typed/src/data.rs b/examples/typed/src/data.rs index 94f4b1782..246723cd5 100644 --- a/examples/typed/src/data.rs +++ b/examples/typed/src/data.rs @@ -6,14 +6,14 @@ use elastic_types::prelude::*; pub struct MyStruct { pub id: i32, pub title: String, - pub timestamp: Date, + pub timestamp: Date, pub geo: GeoLocation, } #[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] pub struct GeoLocation { pub ip: Ipv4Addr, - pub loc: GeoPoint, + pub loc: GeoPoint, } // An index request type with mappings bundled in diff --git a/examples/typed/src/main.rs b/examples/typed/src/main.rs index 85ab032c7..017606195 100644 --- a/examples/typed/src/main.rs +++ b/examples/typed/src/main.rs @@ -23,7 +23,7 @@ use std::net::Ipv4Addr; use reqwest::Client; use cli::{ElasticClient, ParseResponse, RequestParams}; use cli::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; -use cli::res::{parse, CommandResponse, IndexResponse, SearchResponseOf, Hit}; +use cli::res::{parse, CommandResponse, IndexResponse, SearchResponse, Hit}; use elastic_types::prelude::*; mod data; @@ -99,7 +99,7 @@ fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { parse::().from_response(res).unwrap(); } -fn query(client: &Client, params: &RequestParams) -> SearchResponseOf> { +fn query(client: &Client, params: &RequestParams) -> SearchResponse { let req = SearchRequest::for_index_ty(INDEX, MyStruct::name(), json_lit!({ diff --git a/src/async.rs b/src/async.rs new file mode 100644 index 000000000..e69de29bb diff --git a/src/lib.rs b/src/lib.rs index e92a6ce5a..6feaf71d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ //! extern crate reqwest; //! extern crate elastic_reqwest as cli; //! -//! use cli::{ElasticClient, ParseResponse, parse}; +//! use cli::{ElasticClientSync, ParseResponse, parse}; //! # fn main() {} //! ``` //! @@ -61,7 +61,7 @@ //! //HTTP HEAD / //! //! # extern crate elastic_reqwest as cli; -//! use cli::ElasticClient; +//! use cli::ElasticClientSync; //! use cli::req::PingRequest; //! //! # fn main() { @@ -80,7 +80,7 @@ //! //! extern crate elastic_reqwest as cli; //! -//! use cli::{ ElasticClient, ParseResponse, RequestParams, parse }; +//! use cli::{ ElasticClientSync, ParseResponse, RequestParams, parse }; //! use cli::req::SimpleSearchRequest; //! use cli::res::SearchResponse; //! @@ -112,7 +112,7 @@ //! extern crate json_str; //! extern crate elastic_reqwest as cli; //! -//! use cli::{ElasticClient, ParseResponse, parse}; +//! use cli::{ElasticClientSync, ParseResponse, parse}; //! use cli::req::SearchRequest; //! use cli::res::SearchResponse; //! @@ -160,7 +160,7 @@ //! - [Github][repo] //! //! [default]: fn.default.html -//! [elastic_req]: trait.ElasticClient.html#tymethod.elastic_req +//! [elastic_req]: trait.ElasticClientSync.html#tymethod.elastic_req //! [parse]: fn.parse.html //! [elastic]: https://github.com/elastic-rs/elastic //! [rs-es]: https://github.com/benashford/rs-es @@ -181,14 +181,11 @@ extern crate serde; extern crate reqwest; extern crate url; -#[cfg(feature = "nightly")] -use std::io::Cursor; -use std::collections::BTreeMap; -use std::str; -use serde::de::DeserializeOwned; -use reqwest::header::{Header, HeaderFormat, Headers, ContentType}; -use reqwest::{RequestBuilder, Response}; -use url::form_urlencoded::Serializer; +mod sync; +mod async; + +pub use self::sync::*; +pub use self::async::*; /// Request types. /// @@ -206,9 +203,11 @@ pub mod res { pub use self::res::parse; -use self::req::{HttpRequest, HttpMethod}; -use self::res::parsing::{Parse, IsOk}; -use self::res::error::ResponseError; +use std::collections::BTreeMap; +use std::str; +use reqwest::header::{Header, Headers, ContentType}; +use url::form_urlencoded::Serializer; +use self::req::HttpMethod; /// Misc parameters for any request. /// @@ -259,11 +258,11 @@ use self::res::error::ResponseError; #[derive(Debug, Clone)] pub struct RequestParams { /// Base url for Elasticsearch. - pub base_url: String, + base_url: String, /// Simple key-value store for url query params. - pub url_params: BTreeMap<&'static str, String>, + url_params: BTreeMap<&'static str, String>, /// The complete set of headers that will be sent with the request. - pub headers: Headers, + headers: Headers, } impl RequestParams { @@ -306,7 +305,7 @@ impl RequestParams { /// Set a header value on the params. pub fn header(mut self, header: H) -> Self - where H: Header + HeaderFormat + where H: Header { self.headers.set(header); @@ -343,239 +342,35 @@ pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { reqwest::Client::new().map(|cli| (cli, RequestParams::default())) } -/// A type that can be converted into a request body. -pub trait IntoReqwestBody { - /// Convert self into a body. - fn into_body(self) -> reqwest::Body; -} - -impl> IntoReqwestBody for B { - #[cfg(feature = "nightly")] - default fn into_body(self) -> reqwest::Body { - self.into() - } - - #[cfg(not(feature = "nightly"))] - fn into_body(self) -> reqwest::Body { - self.into() - } -} - -#[cfg(feature = "nightly")] -impl IntoReqwestBody for &'static [u8] { - fn into_body(self) -> reqwest::Body { - reqwest::Body::new(Cursor::new(self)) - } -} - -#[cfg(feature = "nightly")] -impl IntoReqwestBody for &'static str { - fn into_body(self) -> reqwest::Body { - reqwest::Body::new(Cursor::new(self)) - } -} - -/// Represents a client that can send Elasticsearch requests. -pub trait ElasticClient { - /// Send a request and get a response. - /// - /// # Examples - /// - /// Bring the `ElasticClient` trait into scope and call `elastic_req` with any type that - /// can be converted into a `req::HttpRequest`. - /// This method returns a raw `reqwest::Response`. - /// - /// ```no_run - /// # use elastic_reqwest::req::SimpleSearchRequest; - /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); - /// use elastic_reqwest::ElasticClient; - /// - /// let (client, params) = elastic_reqwest::default().unwrap(); - /// - /// let http_res = client.elastic_req(¶ms, request).unwrap(); - /// ``` - fn elastic_req(&self, params: &RequestParams, req: I) -> Result - where I: Into>, - B: IntoReqwestBody; -} - -/// Represents a response that can be parsed into a concrete Elasticsearch response. -pub trait ParseResponse { - /// Parse a response into a concrete response type. - fn from_response(self, response: Response) -> Result; -} - -impl ParseResponse for Parse { - fn from_response(self, response: Response) -> Result { - self.from_reader(response.status().to_u16(), response) - } -} - -macro_rules! req_with_body { - ($client:ident, $url:ident, $body:ident, $params:ident, $method:ident) => ({ - let body = $body.expect("Expected this request to have a body. This is a bug, please file an issue on GitHub."); - - $client.request(reqwest::Method::$method, &$url) - .headers($params.headers.to_owned()) - .body(body.into_body()) - }) -} - -fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> RequestBuilder - where I: Into>, - B: IntoReqwestBody -{ - let req = req.into(); - +fn build_url<'a>(req_url: &str, params: &RequestParams) -> String { let (qry_len, qry) = params.get_url_qry(); - let mut url = String::with_capacity(params.base_url.len() + req.url.len() + qry_len); + let mut url = String::with_capacity(params.base_url.len() + req_url.len() + qry_len); url.push_str(¶ms.base_url); - url.push_str(&req.url); + url.push_str(&req_url); if let Some(qry) = qry { url.push_str(&qry); } - let method = req.method; - let body = req.body; - - match method { - HttpMethod::Get => client.get(&url).headers(params.headers.to_owned()), - - HttpMethod::Post => req_with_body!(client, url, body, params, Post), - - HttpMethod::Head => client.head(&url).headers(params.headers.to_owned()), - - HttpMethod::Delete => client.request(reqwest::Method::Delete, &url).headers(params.headers.to_owned()), - - HttpMethod::Put => req_with_body!(client, url, body, params, Put), - - HttpMethod::Patch => req_with_body!(client, url, body, params, Patch), - } + url } -impl ElasticClient for reqwest::Client { - fn elastic_req(&self, params: &RequestParams, req: I) -> Result - where I: Into>, - B: IntoReqwestBody - { - build_req(&self, params, req).send() +fn build_method(method: HttpMethod) -> reqwest::Method { + match method { + HttpMethod::Get => reqwest::Method::Get, + HttpMethod::Post => reqwest::Method::Post, + HttpMethod::Head => reqwest::Method::Head, + HttpMethod::Delete => reqwest::Method::Delete, + HttpMethod::Put => reqwest::Method::Put, + HttpMethod::Patch => reqwest::Method::Patch, } } #[cfg(test)] mod tests { - use reqwest::{Client, RequestBuilder, Method}; use super::*; - use super::req::*; - - fn params() -> RequestParams { - RequestParams::new("eshost:9200/path") - .url_param("pretty", true) - .url_param("q", "*") - } - - fn expected_req(cli: &Client, method: Method, url: &str, body: Option>) -> RequestBuilder { - let req = cli.request(method, url) - .header(ContentType::json()); - - match body { - Some(body) => req.body(body), - None => req, - } - } - - fn assert_req(expected: RequestBuilder, actual: RequestBuilder) { - assert_eq!(format!("{:?}", expected), format!("{:?}", actual)); - } - - #[test] - fn head_req() { - let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); - - let url = "eshost:9200/path/?pretty=true&q=*"; - - let expected = expected_req(&cli, Method::Head, url, None); - - assert_req(expected, req); - } - - #[test] - fn get_req() { - let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); - - let url = "eshost:9200/path/_search?pretty=true&q=*"; - - let expected = expected_req(&cli, Method::Get, url, None); - - assert_req(expected, req); - } - - #[test] - fn post_req() { - let cli = Client::new().unwrap(); - let req = build_req(&cli, - ¶ms(), - PercolateRequest::for_index_ty("idx", "ty", vec![])); - - let url = "eshost:9200/path/idx/ty/_percolate?pretty=true&q=*"; - - let expected = expected_req(&cli, Method::Post, url, Some(vec![])); - - assert_req(expected, req); - } - - #[test] - fn put_req() { - let cli = Client::new().unwrap(); - let req = build_req(&cli, - ¶ms(), - IndicesCreateRequest::for_index("idx", vec![])); - - let url = "eshost:9200/path/idx?pretty=true&q=*"; - - let expected = expected_req(&cli, Method::Put, url, Some(vec![])); - - assert_req(expected, req); - } - - #[test] - fn delete_req() { - let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); - - let url = "eshost:9200/path/idx?pretty=true&q=*"; - - let expected = expected_req(&cli, Method::Delete, url, None); - - assert_req(expected, req); - } - - #[test] - fn owned_string_into_body() { - String::new().into_body(); - } - - #[test] - fn borrowed_string_into_body() { - "abc".into_body(); - } - - #[test] - fn owned_vec_into_body() { - Vec::new().into_body(); - } - - #[test] - fn borrowed_vec_into_body() { - static BODY: &'static [u8] = &[0, 1, 2]; - - (&BODY).into_body(); - } #[test] fn request_params_has_default_content_type() { diff --git a/src/sync.rs b/src/sync.rs new file mode 100644 index 000000000..ed037d175 --- /dev/null +++ b/src/sync.rs @@ -0,0 +1,242 @@ +use std::io::Cursor; +use std::fs::File; +use serde::de::DeserializeOwned; +use reqwest::{self, RequestBuilder, Response}; + +use super::req::HttpRequest; +use super::res::parsing::{Parse, IsOk}; +use super::res::error::ResponseError; +use super::{RequestParams, build_url, build_method}; + +/// A type that can be converted into a request body. +pub trait IntoBodySync { + /// Convert self into a body. + fn into_body(self) -> reqwest::Body; +} + +impl IntoBodySync for reqwest::Body { + fn into_body(self) -> reqwest::Body { + self + } +} + +impl IntoBodySync for File { + fn into_body(self) -> reqwest::Body { + self.into() + } +} + +impl IntoBodySync for Vec { + fn into_body(self) -> reqwest::Body { + self.into() + } +} + +impl IntoBodySync for String { + fn into_body(self) -> reqwest::Body { + self.into() + } +} + +impl IntoBodySync for &'static [u8] { + fn into_body(self) -> reqwest::Body { + reqwest::Body::new(Cursor::new(self)) + } +} + +impl IntoBodySync for &'static str { + fn into_body(self) -> reqwest::Body { + reqwest::Body::new(Cursor::new(self)) + } +} + +/// Represents a client that can send Elasticsearch requests. +pub trait ElasticClientSync { + /// Send a request and get a response. + /// + /// # Examples + /// + /// Bring the `ElasticClientSync` trait into scope and call `elastic_req` with any type that + /// can be converted into a `req::HttpRequest`. + /// This method returns a raw `reqwest::Response`. + /// + /// ```no_run + /// # use elastic_reqwest::req::SimpleSearchRequest; + /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); + /// use elastic_reqwest::ElasticClientSync; + /// + /// let (client, params) = elastic_reqwest::default().unwrap(); + /// + /// let http_res = client.elastic_req(¶ms, request).unwrap(); + /// ``` + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>, + B: IntoBodySync; +} + +/// Represents a response that can be parsed into a concrete Elasticsearch response. +pub trait ParseResponse { + /// Parse a response into a concrete response type. + fn from_response(self, response: Response) -> Result; +} + +impl ParseResponse for Parse { + fn from_response(self, response: Response) -> Result { + let status: u16 = response.status().into(); + + self.from_reader(status, response) + } +} + +fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> Result + where I: Into>, + B: IntoBodySync +{ + let req = req.into(); + + let url = build_url(&req.url, ¶ms); + let method = build_method(req.method); + let body = req.body; + + let mut req = client.request(method, &url)?; + { + req.headers(params.headers.to_owned()); + + if let Some(body) = body { + req.body(body.into_body()); + } + } + + Ok(req) +} + +impl ElasticClientSync for reqwest::Client { + fn elastic_req(&self, params: &RequestParams, req: I) -> Result + where I: Into>, + B: IntoBodySync + { + build_req(&self, params, req)?.send() + } +} + +#[cfg(test)] +mod tests { + use reqwest::{Client, RequestBuilder, Method}; + use reqwest::header::ContentType; + use super::*; + use req::*; + + fn params() -> RequestParams { + RequestParams::new("eshost:9200/path") + .url_param("pretty", true) + .url_param("q", "*") + } + + fn expected_req(cli: &Client, method: Method, url: &str, body: Option>) -> RequestBuilder { + let mut req = cli.request(method, url).unwrap(); + { + req.header(ContentType::json()); + + if let Some(body) = body { + req.body(body); + } + } + + req + } + + fn assert_req(expected: RequestBuilder, actual: RequestBuilder) { + assert_eq!(format!("{:?}", expected), format!("{:?}", actual)); + } + + #[test] + fn head_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); + + let url = "eshost:9200/path/?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Head, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn get_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); + + let url = "eshost:9200/path/_search?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Get, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn post_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, + ¶ms(), + PercolateRequest::for_index_ty("idx", "ty", vec![])); + + let url = "eshost:9200/path/idx/ty/_percolate?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Post, url, Some(vec![])); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn put_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, + ¶ms(), + IndicesCreateRequest::for_index("idx", vec![])); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Put, url, Some(vec![])); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn delete_req() { + let cli = Client::new().unwrap(); + let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Delete, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn file_into_body() { + File::open("Cargo.toml").unwrap().into_body(); + } + + #[test] + fn owned_string_into_body() { + String::new().into_body(); + } + + #[test] + fn borrowed_string_into_body() { + "abc".into_body(); + } + + #[test] + fn owned_vec_into_body() { + Vec::new().into_body(); + } + + #[test] + fn borrowed_vec_into_body() { + static BODY: &'static [u8] = &[0, 1, 2]; + + (&BODY).into_body(); + } +} \ No newline at end of file From 45ce44b323607fc047abb0690ee1b90f47bc14e7 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 8 Jul 2017 17:41:35 +1000 Subject: [PATCH 104/127] work on async api --- Cargo.toml | 5 +- src/async.rs | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 74 +++++++++++++++--- src/sync.rs | 43 ++++++----- 4 files changed, 307 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e52ec66a9..e3fd0bd7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,11 @@ nightly = [] serde = "~1" elastic_requests = "~0.4.1" elastic_responses = "~0.9.0" -reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git" } +reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git", features = ["unstable"] } url = "~1" +bytes = "*" +futures = "*" [dev-dependencies] json_str = "^0.*" +tokio-core = "*" \ No newline at end of file diff --git a/src/async.rs b/src/async.rs index e69de29bb..f4f91aecf 100644 --- a/src/async.rs +++ b/src/async.rs @@ -0,0 +1,215 @@ +use bytes::Bytes; +use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; +use reqwest::Error; +use futures::{Future, IntoFuture}; + +use super::req::HttpRequest; +use super::{RequestParams, build_url, build_method}; + +/// A type that can be converted into a request body. +pub trait IntoBodyAsync { + /// Convert self into a body. + fn into_body(self) -> Body; +} + +impl IntoBodyAsync for Body { + fn into_body(self) -> Body { + self + } +} + +impl IntoBodyAsync for Vec { + fn into_body(self) -> Body { + self.into() + } +} + +impl IntoBodyAsync for String { + fn into_body(self) -> Body { + self.into() + } +} + +impl IntoBodyAsync for &'static [u8] { + fn into_body(self) -> Body { + Bytes::from(self).into() + } +} + +impl IntoBodyAsync for &'static str { + fn into_body(self) -> Body { + Bytes::from(self).into() + } +} + +/// Represents a client that can send Elasticsearch requests. +pub trait ElasticClientAsync { + /// Send a request and get a response. + fn elastic_req(&self, params: &RequestParams, req: I) -> Box> + where I: Into>, + B: IntoBodyAsync; +} + +fn build_req(client: &Client, params: &RequestParams, req: I) -> Result + where I: Into>, + B: IntoBodyAsync +{ + let req = req.into(); + + let url = build_url(&req.url, ¶ms); + let method = build_method(req.method); + let body = req.body; + + let mut req = client.request(method, &url)?; + { + req.headers(params.get_headers()); + + if let Some(body) = body { + req.body(body.into_body()); + } + } + + Ok(req) +} + +impl ElasticClientAsync for Client { + fn elastic_req(&self, params: &RequestParams, req: I) -> Box> + where I: Into>, + B: IntoBodyAsync + { + let fut = build_req(&self, params, req) + .into_future() + .and_then(|mut req| req.send()); + + Box::new(fut) + } +} + +#[cfg(test)] +mod tests { + use reqwest::Method; + use reqwest::unstable::async::{Client, RequestBuilder}; + use reqwest::header::ContentType; + use tokio_core::reactor::Core; + + use super::*; + use req::*; + + fn params() -> RequestParams { + RequestParams::new("eshost:9200/path") + .url_param("pretty", true) + .url_param("q", "*") + } + + fn expected_req(cli: &Client, method: Method, url: &str, body: Option>) -> RequestBuilder { + let mut req = cli.request(method, url).unwrap(); + { + req.header(ContentType::json()); + + if let Some(body) = body { + req.body(body); + } + } + + req + } + + fn assert_req(expected: RequestBuilder, actual: RequestBuilder) { + assert_eq!(format!("{:?}", expected), format!("{:?}", actual)); + } + + fn core() -> Core { + Core::new().unwrap() + } + + #[test] + fn head_req() { + let cli = Client::new(&core().handle()).unwrap(); + let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); + + let url = "eshost:9200/path/?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Head, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn get_req() { + let cli = Client::new(&core().handle()).unwrap(); + let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); + + let url = "eshost:9200/path/_search?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Get, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn post_req() { + let cli = Client::new(&core().handle()).unwrap(); + let req = build_req(&cli, + ¶ms(), + PercolateRequest::for_index_ty("idx", "ty", vec![])); + + let url = "eshost:9200/path/idx/ty/_percolate?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Post, url, Some(vec![])); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn put_req() { + let cli = Client::new(&core().handle()).unwrap(); + let req = build_req(&cli, + ¶ms(), + IndicesCreateRequest::for_index("idx", vec![])); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Put, url, Some(vec![])); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn delete_req() { + let cli = Client::new(&core().handle()).unwrap(); + let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + + let url = "eshost:9200/path/idx?pretty=true&q=*"; + + let expected = expected_req(&cli, Method::Delete, url, None); + + assert_req(expected, req.unwrap()); + } + + #[test] + fn owned_string_into_body() { + String::new().into_body(); + } + + #[test] + fn borrowed_string_into_body() { + "abc".into_body(); + } + + #[test] + fn owned_vec_into_body() { + Vec::new().into_body(); + } + + #[test] + fn borrowed_vec_into_body() { + static BODY: &'static [u8] = &[0, 1, 2]; + + (&BODY).into_body(); + } + + #[test] + fn empty_body_into_body() { + empty_body().into_body(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 6feaf71d2..79462f799 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -180,6 +180,11 @@ extern crate elastic_responses; extern crate serde; extern crate reqwest; extern crate url; +extern crate bytes; +extern crate futures; + +#[cfg(test)] +extern crate tokio_core; mod sync; mod async; @@ -205,7 +210,7 @@ pub use self::res::parse; use std::collections::BTreeMap; use std::str; -use reqwest::header::{Header, Headers, ContentType}; +use reqwest::header::{Headers, ContentType}; use url::form_urlencoded::Serializer; use self::req::HttpMethod; @@ -255,14 +260,13 @@ use self::req::HttpMethod; /// .url_param("q", "*"); /// # } /// ``` -#[derive(Debug, Clone)] pub struct RequestParams { /// Base url for Elasticsearch. base_url: String, /// Simple key-value store for url query params. url_params: BTreeMap<&'static str, String>, /// The complete set of headers that will be sent with the request. - headers: Headers, + headers: Box, } impl RequestParams { @@ -272,12 +276,11 @@ impl RequestParams { /// node. /// It will also set the `Content-Type` header to `application/json`. pub fn new>(base: T) -> Self { - let mut headers = Headers::new(); - headers.set(ContentType::json()); + let headers = |headers: &mut Headers| headers.set(ContentType::json()); RequestParams { base_url: base.into(), - headers: headers, + headers: Box::new(headers), url_params: BTreeMap::new(), } } @@ -294,6 +297,7 @@ impl RequestParams { /// These parameters are added as query parameters to request urls. pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { + // This is safe because we know here that the key exists let mut entry = self.url_params.get_mut(key).unwrap(); *entry = value.to_string(); } else { @@ -304,14 +308,34 @@ impl RequestParams { } /// Set a header value on the params. - pub fn header(mut self, header: H) -> Self - where H: Header + /// + /// Each call to `headers` will chain to the end of the last call. + /// This function allocates a new `Box` for each call, so it's recommended to just call it once + /// and configure multiple headers, rather than calling it once per header. + pub fn headers(mut self, headers_fn: F) -> Self + where F: Fn(&mut Headers) + Send + Sync + 'static { - self.headers.set(header); + let old_fn = self.headers; + + let headers = move |mut headers: &mut Headers| { + old_fn(&mut headers); + headers_fn(&mut headers); + }; + + self.headers = Box::new(headers); self } + /// Create a new `Headers` structure, and thread it through the configuration functions. + pub fn get_headers(&self) -> Headers { + let mut headers = Headers::new(); + + (self.headers)(&mut headers); + + headers + } + /// Get the url query params as a formatted string. /// /// Follows the `application/x-www-form-urlencoded` format. @@ -368,14 +392,44 @@ fn build_method(method: HttpMethod) -> reqwest::Method { } } +#[cfg(test)] +fn assert_send() {} + +#[cfg(test)] +fn assert_sync() {} + #[cfg(test)] mod tests { + use reqwest::header::{Referer, Authorization, ContentType}; use super::*; + #[test] + fn assert_send_sync() { + assert_send::(); + assert_sync::(); + } + #[test] fn request_params_has_default_content_type() { let req = RequestParams::default(); - assert_eq!(Some(&ContentType::json()), req.headers.get::()); + + let headers = req.get_headers(); + + assert_eq!(Some(&ContentType::json()), headers.get::()); + } + + #[test] + fn set_multiple_headers() { + let req = RequestParams::default() + .headers(|h| h.set(Referer::new("/not-the-value"))) + .headers(|h| h.set(Referer::new("/People.html#tim"))) + .headers(|h| h.set(Authorization("let me in".to_owned()))); + + let headers = req.get_headers(); + + assert_eq!(Some(&ContentType::json()), headers.get::()); + assert_eq!(Some(&Referer::new("/People.html#tim")), headers.get::()); + assert_eq!(Some(&Authorization("let me in".to_owned())), headers.get::>()); } #[test] diff --git a/src/sync.rs b/src/sync.rs index ed037d175..3866f9600 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,7 +1,7 @@ use std::io::Cursor; use std::fs::File; use serde::de::DeserializeOwned; -use reqwest::{self, RequestBuilder, Response}; +use reqwest::{Client, RequestBuilder, Response, Body, Error}; use super::req::HttpRequest; use super::res::parsing::{Parse, IsOk}; @@ -11,42 +11,42 @@ use super::{RequestParams, build_url, build_method}; /// A type that can be converted into a request body. pub trait IntoBodySync { /// Convert self into a body. - fn into_body(self) -> reqwest::Body; + fn into_body(self) -> Body; } -impl IntoBodySync for reqwest::Body { - fn into_body(self) -> reqwest::Body { +impl IntoBodySync for Body { + fn into_body(self) -> Body { self } } impl IntoBodySync for File { - fn into_body(self) -> reqwest::Body { + fn into_body(self) -> Body { self.into() } } impl IntoBodySync for Vec { - fn into_body(self) -> reqwest::Body { + fn into_body(self) -> Body { self.into() } } impl IntoBodySync for String { - fn into_body(self) -> reqwest::Body { + fn into_body(self) -> Body { self.into() } } impl IntoBodySync for &'static [u8] { - fn into_body(self) -> reqwest::Body { - reqwest::Body::new(Cursor::new(self)) + fn into_body(self) -> Body { + Body::new(Cursor::new(self)) } } impl IntoBodySync for &'static str { - fn into_body(self) -> reqwest::Body { - reqwest::Body::new(Cursor::new(self)) + fn into_body(self) -> Body { + Body::new(Cursor::new(self)) } } @@ -69,18 +69,18 @@ pub trait ElasticClientSync { /// /// let http_res = client.elastic_req(¶ms, request).unwrap(); /// ``` - fn elastic_req(&self, params: &RequestParams, req: I) -> Result + fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodySync; } /// Represents a response that can be parsed into a concrete Elasticsearch response. -pub trait ParseResponse { +pub trait ParseResponseSync { /// Parse a response into a concrete response type. fn from_response(self, response: Response) -> Result; } -impl ParseResponse for Parse { +impl ParseResponseSync for Parse { fn from_response(self, response: Response) -> Result { let status: u16 = response.status().into(); @@ -88,7 +88,7 @@ impl ParseResponse for Parse(client: &reqwest::Client, params: &RequestParams, req: I) -> Result +fn build_req(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodySync { @@ -100,7 +100,7 @@ fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> let mut req = client.request(method, &url)?; { - req.headers(params.headers.to_owned()); + req.headers(params.get_headers()); if let Some(body) = body { req.body(body.into_body()); @@ -110,8 +110,8 @@ fn build_req(client: &reqwest::Client, params: &RequestParams, req: I) -> Ok(req) } -impl ElasticClientSync for reqwest::Client { - fn elastic_req(&self, params: &RequestParams, req: I) -> Result +impl ElasticClientSync for Client { + fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodySync { @@ -239,4 +239,9 @@ mod tests { (&BODY).into_body(); } -} \ No newline at end of file + + #[test] + fn empty_body_into_body() { + empty_body().into_body(); + } +} From fac34ac2a247ece07656bb3b6a41a57959d3830f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 8 Jul 2017 19:39:05 +1000 Subject: [PATCH 105/127] add some benches --- benches/mod.rs | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 8 +-- src/sync.rs | 3 +- 3 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 benches/mod.rs diff --git a/benches/mod.rs b/benches/mod.rs new file mode 100644 index 000000000..2f0956165 --- /dev/null +++ b/benches/mod.rs @@ -0,0 +1,138 @@ +#![feature(test)] + +extern crate reqwest; +extern crate elastic_reqwest; +extern crate test; + +use reqwest::Client; +use reqwest::header::Referer; +use elastic_reqwest::{build_req, RequestParams}; +use elastic_reqwest::req::PingRequest; + +#[inline(always)] +fn with_headers_1(params: RequestParams) -> RequestParams { + params.headers(|h| h.set(Referer::new("/People.html#tim"))) +} + +#[inline(always)] +fn with_headers_5(params: RequestParams) -> RequestParams { + params.headers(|h| h.set(Referer::new("/People.html#tim"))) + .headers(|h| h.set(Referer::new("/People.html#tim"))) + .headers(|h| h.set(Referer::new("/People.html#tim"))) + .headers(|h| h.set(Referer::new("/People.html#tim"))) + .headers(|h| h.set(Referer::new("/People.html#tim"))) +} + +#[inline(always)] +fn with_params_1(params: RequestParams) -> RequestParams { + params.url_param("query", "*") +} + +#[inline(always)] +fn with_params_5(params: RequestParams) -> RequestParams { + params.url_param("query", "*") + .url_param("query", "*") + .url_param("query", "*") + .url_param("query", "*") + .url_param("query", "*") +} + +macro_rules! bench { + ($({$bench_name:ident, $bench_macro:ident}),*) => ( + $( + mod $bench_name { + use super::*; + + $bench_macro!( + { default, RequestParams::default() }, + { headers_1, with_headers_1(RequestParams::default()) }, + { headers_5, with_headers_5(RequestParams::default()) }, + { params_1, with_params_1(RequestParams::default()) }, + { params_5, with_params_5(RequestParams::default()) } + ); + } + )* + ) +} + +macro_rules! bench_new { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + b.iter(|| { + $params + }) + } + )* + ) +} + +macro_rules! bench_clone { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + let params = $params; + + b.iter(|| { + params.clone() + }) + } + )* + ) +} + +macro_rules! bench_get_headers { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + let params = $params; + + b.iter(|| { + params.get_headers() + }) + } + )* + ) +} + +macro_rules! bench_make_request { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + let params = RequestParams::default(); + let cli = Client::new().unwrap(); + + b.iter(|| { + build_req(&cli, ¶ms, PingRequest::new()) + }) + } + )* + ) +} + +macro_rules! get_url_query { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + let params = $params; + + b.iter(|| { + params.get_url_qry() + }) + } + )* + ) +} + +bench!( + { new, bench_new }, + { clone, bench_clone }, + { get_headers, bench_get_headers }, + { get_url_query, get_url_query }, + { make_request, bench_make_request } +); diff --git a/src/lib.rs b/src/lib.rs index 79462f799..c0178819f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,6 +208,7 @@ pub mod res { pub use self::res::parse; +use std::sync::Arc; use std::collections::BTreeMap; use std::str; use reqwest::header::{Headers, ContentType}; @@ -260,13 +261,14 @@ use self::req::HttpMethod; /// .url_param("q", "*"); /// # } /// ``` +#[derive(Clone)] pub struct RequestParams { /// Base url for Elasticsearch. base_url: String, /// Simple key-value store for url query params. url_params: BTreeMap<&'static str, String>, /// The complete set of headers that will be sent with the request. - headers: Box, + headers: Arc, } impl RequestParams { @@ -280,7 +282,7 @@ impl RequestParams { RequestParams { base_url: base.into(), - headers: Box::new(headers), + headers: Arc::new(headers), url_params: BTreeMap::new(), } } @@ -322,7 +324,7 @@ impl RequestParams { headers_fn(&mut headers); }; - self.headers = Box::new(headers); + self.headers = Arc::new(headers); self } diff --git a/src/sync.rs b/src/sync.rs index 3866f9600..d42058a99 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -88,7 +88,8 @@ impl ParseResponseSync for Parse< } } -fn build_req(client: &Client, params: &RequestParams, req: I) -> Result +#[doc(hidden)] +pub fn build_req(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodySync { From 07233217eee67f23fe8428022c013687f4ff940d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 9 Jul 2017 10:00:48 +1000 Subject: [PATCH 106/127] optimise default headers --- benches/mod.rs | 56 +++++++++++++++++++++++++++++++++++--------------- src/async.rs | 15 +++++++------- src/lib.rs | 29 ++++++++++++++------------ src/sync.rs | 16 +++++++-------- 4 files changed, 71 insertions(+), 45 deletions(-) diff --git a/benches/mod.rs b/benches/mod.rs index 2f0956165..4404319cd 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -1,12 +1,15 @@ #![feature(test)] extern crate reqwest; +extern crate tokio_core; extern crate elastic_reqwest; extern crate test; -use reqwest::Client; +use reqwest::Client as ClientSync; +use reqwest::unstable::async::Client as ClientAsync; use reqwest::header::Referer; -use elastic_reqwest::{build_req, RequestParams}; +use tokio_core::reactor::Core; +use elastic_reqwest::{build_req_sync, build_req_async, RequestParams}; use elastic_reqwest::req::PingRequest; #[inline(always)] @@ -38,12 +41,12 @@ fn with_params_5(params: RequestParams) -> RequestParams { } macro_rules! bench { - ($({$bench_name:ident, $bench_macro:ident}),*) => ( + ($($bench_name:ident),*) => ( $( mod $bench_name { use super::*; - $bench_macro!( + $bench_name!( { default, RequestParams::default() }, { headers_1, with_headers_1(RequestParams::default()) }, { headers_5, with_headers_5(RequestParams::default()) }, @@ -55,7 +58,7 @@ macro_rules! bench { ) } -macro_rules! bench_new { +macro_rules! new { ($({ $name:ident, $params:expr }),*) => ( $( #[bench] @@ -68,7 +71,7 @@ macro_rules! bench_new { ) } -macro_rules! bench_clone { +macro_rules! clone { ($({ $name:ident, $params:expr }),*) => ( $( #[bench] @@ -83,7 +86,7 @@ macro_rules! bench_clone { ) } -macro_rules! bench_get_headers { +macro_rules! get_headers { ($({ $name:ident, $params:expr }),*) => ( $( #[bench] @@ -98,16 +101,34 @@ macro_rules! bench_get_headers { ) } -macro_rules! bench_make_request { +macro_rules! build_request_sync { ($({ $name:ident, $params:expr }),*) => ( $( #[bench] fn $name(b: &mut test::Bencher) { let params = RequestParams::default(); - let cli = Client::new().unwrap(); + let cli = ClientSync::new().unwrap(); b.iter(|| { - build_req(&cli, ¶ms, PingRequest::new()) + build_req_sync(&cli, ¶ms, PingRequest::new()) + }) + } + )* + ) +} + +macro_rules! build_request_async { + ($({ $name:ident, $params:expr }),*) => ( + $( + #[bench] + fn $name(b: &mut test::Bencher) { + let core = Core::new().unwrap(); + + let params = RequestParams::default(); + let cli = ClientAsync::new(&core.handle()).unwrap(); + + b.iter(|| { + build_req_async(&cli, ¶ms, PingRequest::new()) }) } )* @@ -129,10 +150,11 @@ macro_rules! get_url_query { ) } -bench!( - { new, bench_new }, - { clone, bench_clone }, - { get_headers, bench_get_headers }, - { get_url_query, get_url_query }, - { make_request, bench_make_request } -); +bench![ + new, + clone, + get_headers, + get_url_query, + build_request_sync, + build_request_async +]; diff --git a/src/async.rs b/src/async.rs index f4f91aecf..29c74fb5a 100644 --- a/src/async.rs +++ b/src/async.rs @@ -50,7 +50,8 @@ pub trait ElasticClientAsync { B: IntoBodyAsync; } -fn build_req(client: &Client, params: &RequestParams, req: I) -> Result +/// Build an asynchronous `reqwest::RequestBuilder` from an Elasticsearch request. +pub fn build_req_async(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodyAsync { @@ -77,7 +78,7 @@ impl ElasticClientAsync for Client { where I: Into>, B: IntoBodyAsync { - let fut = build_req(&self, params, req) + let fut = build_req_async(&self, params, req) .into_future() .and_then(|mut req| req.send()); @@ -125,7 +126,7 @@ mod tests { #[test] fn head_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); + let req = build_req_async(&cli, ¶ms(), PingHeadRequest::new()); let url = "eshost:9200/path/?pretty=true&q=*"; @@ -137,7 +138,7 @@ mod tests { #[test] fn get_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); + let req = build_req_async(&cli, ¶ms(), SimpleSearchRequest::new()); let url = "eshost:9200/path/_search?pretty=true&q=*"; @@ -149,7 +150,7 @@ mod tests { #[test] fn post_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req(&cli, + let req = build_req_async(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); @@ -163,7 +164,7 @@ mod tests { #[test] fn put_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req(&cli, + let req = build_req_async(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); @@ -177,7 +178,7 @@ mod tests { #[test] fn delete_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + let req = build_req_async(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); let url = "eshost:9200/path/idx?pretty=true&q=*"; diff --git a/src/lib.rs b/src/lib.rs index c0178819f..6c1596be3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -268,7 +268,7 @@ pub struct RequestParams { /// Simple key-value store for url query params. url_params: BTreeMap<&'static str, String>, /// The complete set of headers that will be sent with the request. - headers: Arc, + headers_factory: Option>, } impl RequestParams { @@ -278,11 +278,9 @@ impl RequestParams { /// node. /// It will also set the `Content-Type` header to `application/json`. pub fn new>(base: T) -> Self { - let headers = |headers: &mut Headers| headers.set(ContentType::json()); - RequestParams { base_url: base.into(), - headers: Arc::new(headers), + headers_factory: None, url_params: BTreeMap::new(), } } @@ -314,17 +312,19 @@ impl RequestParams { /// Each call to `headers` will chain to the end of the last call. /// This function allocates a new `Box` for each call, so it's recommended to just call it once /// and configure multiple headers, rather than calling it once per header. - pub fn headers(mut self, headers_fn: F) -> Self + pub fn headers(mut self, headers_factory: F) -> Self where F: Fn(&mut Headers) + Send + Sync + 'static { - let old_fn = self.headers; - - let headers = move |mut headers: &mut Headers| { - old_fn(&mut headers); - headers_fn(&mut headers); - }; + if let Some(old_headers_factory) = self.headers_factory { + let headers_factory = move |mut headers: &mut Headers| { + old_headers_factory(&mut headers); + headers_factory(&mut headers); + }; - self.headers = Arc::new(headers); + self.headers_factory = Some(Arc::new(headers_factory)); + } else { + self.headers_factory = Some(Arc::new(headers_factory)); + } self } @@ -332,8 +332,11 @@ impl RequestParams { /// Create a new `Headers` structure, and thread it through the configuration functions. pub fn get_headers(&self) -> Headers { let mut headers = Headers::new(); + headers.set(ContentType::json()); - (self.headers)(&mut headers); + if let Some(ref headers_factory) = self.headers_factory { + headers_factory(&mut headers); + } headers } diff --git a/src/sync.rs b/src/sync.rs index d42058a99..48a8229b6 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -88,8 +88,8 @@ impl ParseResponseSync for Parse< } } -#[doc(hidden)] -pub fn build_req(client: &Client, params: &RequestParams, req: I) -> Result +/// Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. +pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: IntoBodySync { @@ -116,7 +116,7 @@ impl ElasticClientSync for Client { where I: Into>, B: IntoBodySync { - build_req(&self, params, req)?.send() + build_req_sync(&self, params, req)?.send() } } @@ -153,7 +153,7 @@ mod tests { #[test] fn head_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); + let req = build_req_sync(&cli, ¶ms(), PingHeadRequest::new()); let url = "eshost:9200/path/?pretty=true&q=*"; @@ -165,7 +165,7 @@ mod tests { #[test] fn get_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); + let req = build_req_sync(&cli, ¶ms(), SimpleSearchRequest::new()); let url = "eshost:9200/path/_search?pretty=true&q=*"; @@ -177,7 +177,7 @@ mod tests { #[test] fn post_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, + let req = build_req_sync(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); @@ -191,7 +191,7 @@ mod tests { #[test] fn put_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, + let req = build_req_sync(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); @@ -205,7 +205,7 @@ mod tests { #[test] fn delete_req() { let cli = Client::new().unwrap(); - let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + let req = build_req_sync(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); let url = "eshost:9200/path/idx?pretty=true&q=*"; From 53d03c79fc025c22c5457c705d9e6ee1b0ea6885 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 9 Jul 2017 11:47:54 +1000 Subject: [PATCH 107/127] add dedicated error type --- .travis.yml | 6 +- Cargo.toml | 2 + examples/basic/.gitignore | 2 - examples/basic/Cargo.toml | 9 --- examples/{basic/src/main.rs => basic_sync.rs} | 24 ++++--- examples/bulk/.gitignore | 2 - examples/bulk/Cargo.toml | 13 ---- examples/bulk/src/main.rs | 72 ------------------- examples/bulk_sync.rs | 43 +++++++++++ src/async.rs | 17 ++++- src/lib.rs | 35 ++++++++- src/sync.rs | 25 +++++-- 12 files changed, 126 insertions(+), 124 deletions(-) delete mode 100644 examples/basic/.gitignore delete mode 100644 examples/basic/Cargo.toml rename examples/{basic/src/main.rs => basic_sync.rs} (68%) delete mode 100644 examples/bulk/.gitignore delete mode 100644 examples/bulk/Cargo.toml delete mode 100644 examples/bulk/src/main.rs create mode 100644 examples/bulk_sync.rs diff --git a/.travis.yml b/.travis.yml index 54f086116..b0534a03f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,7 @@ script: travis-cargo --only nightly test -- --features nightly && travis-cargo test && travis-cargo bench && - cd examples/basic && - travis-cargo build && - cd ../bulk && - travis-cargo build && - cd ../typed && + cd examples/typed && travis-cargo --only nightly build && cd ../../ && travis-cargo --only stable doc diff --git a/Cargo.toml b/Cargo.toml index e3fd0bd7d..e2f9d9b45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,8 @@ reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git", f url = "~1" bytes = "*" futures = "*" +serde_json = "~1" +quick-error = "~1" [dev-dependencies] json_str = "^0.*" diff --git a/examples/basic/.gitignore b/examples/basic/.gitignore deleted file mode 100644 index ab22063e1..000000000 --- a/examples/basic/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/obj/ \ No newline at end of file diff --git a/examples/basic/Cargo.toml b/examples/basic/Cargo.toml deleted file mode 100644 index 6bce7944b..000000000 --- a/examples/basic/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "basic" -version = "0.1.0" -authors = ["Ashley Mannix "] - -[dependencies] -elastic_reqwest = { version = "*", path = "../../" } - -json_str = "*" diff --git a/examples/basic/src/main.rs b/examples/basic_sync.rs similarity index 68% rename from examples/basic/src/main.rs rename to examples/basic_sync.rs index f97f3bc93..cf2fd068e 100644 --- a/examples/basic/src/main.rs +++ b/examples/basic_sync.rs @@ -6,26 +6,28 @@ //! To make things readable, the `pretty` url param is provided. #[macro_use] -extern crate json_str; +extern crate serde_json; extern crate elastic_reqwest as cli; use cli::{ElasticClient, ParseResponse, RequestParams}; use cli::req::SearchRequest; use cli::res::{parse, SearchResponse}; -fn main() { +fn run() -> Result<(), Error> { // Get a new default client. - let (client, _) = cli::default().unwrap(); + let (client, _) = cli::default()?; // Create a new set of params with pretty printing. let params = RequestParams::default().url_param("pretty", true); // Create a query DSL request body. let req = { - let body = json_str!({ - query: { - query_string: { - query: "*" + let query = "*"; + + let body = json!({ + "query": { + "query_string": { + "query": $query } } }); @@ -34,9 +36,13 @@ fn main() { }; // Send the request and read the response. - let http_res = client.elastic_req(¶ms, req).unwrap(); + let http_res = client.elastic_req(¶ms, req)?; - let res = parse::().from_response(http_res).unwrap(); + let res = parse::().from_response(http_res)?; println!("Got response: {:?}", res); } + +fn main() { + run().unwrap(); +} diff --git a/examples/bulk/.gitignore b/examples/bulk/.gitignore deleted file mode 100644 index ab22063e1..000000000 --- a/examples/bulk/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/obj/ \ No newline at end of file diff --git a/examples/bulk/Cargo.toml b/examples/bulk/Cargo.toml deleted file mode 100644 index 278e1df3c..000000000 --- a/examples/bulk/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "bulk" -version = "0.1.0" -authors = ["Ashley Mannix "] - -[features] -nightly = ["elastic_reqwest/nightly"] -profiling = [] - -[dependencies] -elastic_reqwest = { version = "*", path = "../../" } - -lazy_static = { version = "*", optional = true } diff --git a/examples/bulk/src/main.rs b/examples/bulk/src/main.rs deleted file mode 100644 index 293c86daa..000000000 --- a/examples/bulk/src/main.rs +++ /dev/null @@ -1,72 +0,0 @@ -//! Elasticsearch Reqwest Client Samples -//! -//! This sample assumes you have a node running on `localhost`. -//! -//! This sample demonstrates a request with a large body. -//! -//! If you compile with `--features profiling` then it uses the system allocator -//! to play nicely with valgrind for profiling. -//! -//! If you compile with `--features lazy_static` then the sample uses a borrowed -//! request instead of an owned one. -//! This will avoid allocating multiple copies of the request if the same body -//! is used multiple times. - -#![cfg_attr(feature="profiling", feature(alloc_system))] -#[cfg(feature="profiling")] -extern crate alloc_system; - -#[cfg(feature="lazy_static")] -#[cfg_attr(feature = "lazy_static", macro_use)] -extern crate lazy_static; - -extern crate elastic_reqwest as cli; - -use cli::{ElasticClient, ParseResponse}; -use cli::req::BulkRequest; -use cli::res::{parse, BulkResponse}; - -// Create a bulk request to index a bunch of docs. -macro_rules! bulk_req { - () => ({ - let mut bulk = String::new(); - for i in 1..1000 { - let header = format!("{{ \"index\" : {{ \"_index\" : \"test\", \"_type\" : \"ty\", \"_id\" : \"{}\" }} }}", i); - let body = format!("{{ \"title\" : \"string value {}\" }}", i); - - bulk.push_str(&header); - bulk.push('\n'); - bulk.push_str(&body); - bulk.push('\n'); - } - - bulk - }) -} - -#[cfg(feature="lazy_static")] -lazy_static! { - static ref REQUEST: String = bulk_req!(); -} - -#[cfg(not(feature="lazy_static"))] -fn get_req() -> String { - bulk_req!() -} - -#[cfg(feature="lazy_static")] -fn get_req() -> &'static str { - &REQUEST -} - -fn main() { - // Get a new default client. - let (client, params) = cli::default().unwrap(); - - // Send the bulk request. - let http_res = client.elastic_req(¶ms, BulkRequest::new(get_req())).unwrap(); - - let res = parse::().from_response(http_res).unwrap(); - - println!("{:?}", res); -} diff --git a/examples/bulk_sync.rs b/examples/bulk_sync.rs new file mode 100644 index 000000000..8c1f8d015 --- /dev/null +++ b/examples/bulk_sync.rs @@ -0,0 +1,43 @@ +//! Elasticsearch Reqwest Client Samples +//! +//! This sample assumes you have a node running on `localhost`. +//! +//! This sample demonstrates a request with a large body. + +extern crate elastic_reqwest as cli; + +use cli::{ElasticClient, ParseResponse}; +use cli::req::BulkRequest; +use cli::res::{parse, BulkResponse}; + +// Create a bulk request to index a bunch of docs. +fn get_req() -> String { + let mut bulk = String::new(); + for i in 1..1000 { + let header = format!("{{ \"index\" : {{ \"_index\" : \"test\", \"_type\" : \"ty\", \"_id\" : \"{}\" }} }}", i); + let body = format!("{{ \"title\" : \"string value {}\" }}", i); + + bulk.push_str(&header); + bulk.push('\n'); + bulk.push_str(&body); + bulk.push('\n'); + } + + bulk +} + +fn run() -> Result<(), Error> { + // Get a new default client. + let (client, params) = cli::default()?; + + // Send the bulk request. + let http_res = client.elastic_req(¶ms, BulkRequest::new(get_req()))?; + + let res = parse::().from_response(http_res)?; + + println!("{:?}", res); +} + +fn main() { + run().unwrap(); +} diff --git a/src/async.rs b/src/async.rs index 29c74fb5a..b4139b7cc 100644 --- a/src/async.rs +++ b/src/async.rs @@ -1,10 +1,10 @@ use bytes::Bytes; +use serde_json::Value; use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; -use reqwest::Error; use futures::{Future, IntoFuture}; use super::req::HttpRequest; -use super::{RequestParams, build_url, build_method}; +use super::{Error, RequestParams, build_url, build_method}; /// A type that can be converted into a request body. pub trait IntoBodyAsync { @@ -30,6 +30,12 @@ impl IntoBodyAsync for String { } } +impl IntoBodyAsync for Value { + fn into_body(self) -> Body { + self.to_string().into() + } +} + impl IntoBodyAsync for &'static [u8] { fn into_body(self) -> Body { Bytes::from(self).into() @@ -80,7 +86,7 @@ impl ElasticClientAsync for Client { { let fut = build_req_async(&self, params, req) .into_future() - .and_then(|mut req| req.send()); + .and_then(|mut req| req.send().map_err(Into::into)); Box::new(fut) } @@ -213,4 +219,9 @@ mod tests { fn empty_body_into_body() { empty_body().into_body(); } + + #[test] + fn json_value_into_body() { + json!({}).into_body(); + } } diff --git a/src/lib.rs b/src/lib.rs index 6c1596be3..20114d94d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,9 +175,14 @@ #![deny(warnings)] #![deny(missing_docs)] +#[macro_use] +extern crate quick_error; + extern crate elastic_requests; extern crate elastic_responses; extern crate serde; +#[cfg_attr(test, macro_use)] +extern crate serde_json; extern crate reqwest; extern crate url; extern crate bytes; @@ -211,10 +216,34 @@ pub use self::res::parse; use std::sync::Arc; use std::collections::BTreeMap; use std::str; +use reqwest::Error as ReqwestError; use reqwest::header::{Headers, ContentType}; use url::form_urlencoded::Serializer; + +use self::res::error::ResponseError; use self::req::HttpMethod; +quick_error! { + /// An error sending a request or parsing a response. + #[derive(Debug)] + pub enum Error { + /// A http error. + Http(err: ReqwestError) { + from() + description("http error") + display("http error: {}", err) + cause(err) + } + /// A response error. + Response(err: ResponseError) { + from() + description("response error") + display("response error: {}", err) + cause(err) + } + } +} + /// Misc parameters for any request. /// /// The `RequestParams` struct allows you to set headers and url parameters for your requests. @@ -367,8 +396,10 @@ impl Default for RequestParams { } /// Get a default `Client` and `RequestParams`. -pub fn default() -> Result<(reqwest::Client, RequestParams), reqwest::Error> { - reqwest::Client::new().map(|cli| (cli, RequestParams::default())) +pub fn default() -> Result<(reqwest::Client, RequestParams), Error> { + reqwest::Client::new() + .map(|cli| (cli, RequestParams::default())) + .map_err(Into::into) } fn build_url<'a>(req_url: &str, params: &RequestParams) -> String { diff --git a/src/sync.rs b/src/sync.rs index 48a8229b6..a37dc5bd9 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,12 +1,12 @@ use std::io::Cursor; use std::fs::File; use serde::de::DeserializeOwned; -use reqwest::{Client, RequestBuilder, Response, Body, Error}; +use serde_json::Value; +use reqwest::{Client, RequestBuilder, Response, Body}; use super::req::HttpRequest; use super::res::parsing::{Parse, IsOk}; -use super::res::error::ResponseError; -use super::{RequestParams, build_url, build_method}; +use super::{Error, RequestParams, build_url, build_method}; /// A type that can be converted into a request body. pub trait IntoBodySync { @@ -38,6 +38,12 @@ impl IntoBodySync for String { } } +impl IntoBodySync for Value { + fn into_body(self) -> Body { + self.to_string().into() + } +} + impl IntoBodySync for &'static [u8] { fn into_body(self) -> Body { Body::new(Cursor::new(self)) @@ -77,14 +83,14 @@ pub trait ElasticClientSync { /// Represents a response that can be parsed into a concrete Elasticsearch response. pub trait ParseResponseSync { /// Parse a response into a concrete response type. - fn from_response(self, response: Response) -> Result; + fn from_response(self, response: Response) -> Result; } impl ParseResponseSync for Parse { - fn from_response(self, response: Response) -> Result { + fn from_response(self, response: Response) -> Result { let status: u16 = response.status().into(); - self.from_reader(status, response) + self.from_reader(status, response).map_err(Into::into) } } @@ -116,7 +122,7 @@ impl ElasticClientSync for Client { where I: Into>, B: IntoBodySync { - build_req_sync(&self, params, req)?.send() + build_req_sync(&self, params, req)?.send().map_err(Into::into) } } @@ -245,4 +251,9 @@ mod tests { fn empty_body_into_body() { empty_body().into_body(); } + + #[test] + fn json_value_into_body() { + json!({}).into_body(); + } } From 3f24bb96463f4e5125cb2925edba8c52bb799650 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 13 Jul 2017 18:08:11 +1000 Subject: [PATCH 108/127] add async fromresponse --- Cargo.toml | 7 +++-- examples/basic_async.rs | 61 +++++++++++++++++++++++++++++++++++++++++ examples/basic_sync.rs | 11 +++++--- src/async.rs | 25 +++++++++++++++++ src/lib.rs | 32 +++++++++++++++------ src/sync.rs | 28 +++++++++---------- 6 files changed, 134 insertions(+), 30 deletions(-) create mode 100644 examples/basic_async.rs diff --git a/Cargo.toml b/Cargo.toml index e2f9d9b45..ddd1d3bb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,13 +15,14 @@ nightly = [] serde = "~1" elastic_requests = "~0.4.1" elastic_responses = "~0.9.0" -reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git", features = ["unstable"] } +reqwest = { version = "*", git = "https://github.com/kodraus/reqwest.git", branch = "feat/async-decoder", features = ["unstable"] } url = "~1" bytes = "*" +tokio-core = "*" +tokio-io = "*" futures = "*" serde_json = "~1" quick-error = "~1" [dev-dependencies] -json_str = "^0.*" -tokio-core = "*" \ No newline at end of file +json_str = "^0.*" \ No newline at end of file diff --git a/examples/basic_async.rs b/examples/basic_async.rs new file mode 100644 index 000000000..fdcd261c8 --- /dev/null +++ b/examples/basic_async.rs @@ -0,0 +1,61 @@ +//! Elasticsearch Reqwest Client Samples +//! +//! This sample assumes you have a node running on `localhost`. +//! +//! This minimal sample executes a simple search request against all indices. +//! To make things readable, the `pretty` url param is provided. + +#[macro_use] +extern crate serde_json; +extern crate tokio_core; +extern crate futures; +extern crate elastic_reqwest as cli; + +use serde_json::Value; +use tokio_core::reactor::Core; +use futures::Future; +use cli::{ElasticClientAsync, ParseResponseAsync, RequestParams, Error}; +use cli::req::SearchRequest; +use cli::res::{parse, SearchResponse}; + +fn run() -> Result<(), Error> { + let mut core = Core::new().unwrap(); + + // Get a new default client. + let (client, _) = cli::default_async(&core.handle())?; + + // Create a new set of params with pretty printing. + let params = RequestParams::default().url_param("pretty", true); + + // Create a query DSL request body. + let req = { + let query = "*"; + + let body = json!({ + "query": { + "query_string": { + "query": query + } + } + }); + + SearchRequest::for_index("_all", body) + }; + + // Send the request and read the response. + let req_fut = client.elastic_req(¶ms, req) + .and_then(|http_res| parse::>().from_response(http_res)) + .and_then(|res| { + println!("Got response: {:?}", res); + + Ok(()) + }); + + core.run(req_fut).unwrap(); + + Ok(()) +} + +fn main() { + run().unwrap(); +} diff --git a/examples/basic_sync.rs b/examples/basic_sync.rs index cf2fd068e..9b6f60098 100644 --- a/examples/basic_sync.rs +++ b/examples/basic_sync.rs @@ -9,13 +9,14 @@ extern crate serde_json; extern crate elastic_reqwest as cli; -use cli::{ElasticClient, ParseResponse, RequestParams}; +use serde_json::Value; +use cli::{ElasticClientSync, ParseResponseSync, RequestParams, Error}; use cli::req::SearchRequest; use cli::res::{parse, SearchResponse}; fn run() -> Result<(), Error> { // Get a new default client. - let (client, _) = cli::default()?; + let (client, _) = cli::default_sync()?; // Create a new set of params with pretty printing. let params = RequestParams::default().url_param("pretty", true); @@ -27,7 +28,7 @@ fn run() -> Result<(), Error> { let body = json!({ "query": { "query_string": { - "query": $query + "query": query } } }); @@ -38,9 +39,11 @@ fn run() -> Result<(), Error> { // Send the request and read the response. let http_res = client.elastic_req(¶ms, req)?; - let res = parse::().from_response(http_res)?; + let res = parse::>().from_response(http_res)?; println!("Got response: {:?}", res); + + Ok(()) } fn main() { diff --git a/src/async.rs b/src/async.rs index b4139b7cc..df7334a46 100644 --- a/src/async.rs +++ b/src/async.rs @@ -1,9 +1,12 @@ use bytes::Bytes; +use serde::de::DeserializeOwned; use serde_json::Value; use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; use futures::{Future, IntoFuture}; +use tokio_io::io; use super::req::HttpRequest; +use super::res::parsing::{Parse, IsOk}; use super::{Error, RequestParams, build_url, build_method}; /// A type that can be converted into a request body. @@ -92,6 +95,28 @@ impl ElasticClientAsync for Client { } } +/// Represents a response that can be parsed into a concrete Elasticsearch response. +pub trait ParseResponseAsync { + /// Parse a response into a concrete response type. + fn from_response(self, response: Response) -> Box>; +} + +impl ParseResponseAsync for Parse { + fn from_response(self, response: Response) -> Box> { + let status: u16 = response.status().into(); + + let body_future = io::read_to_end(response, Vec::new()) + .map_err(Into::into); + + let de_future = body_future + .and_then(move |(_, body)| { + self.from_slice(status, &body).map_err(Into::into) + }); + + Box::new(de_future) + } +} + #[cfg(test)] mod tests { use reqwest::Method; diff --git a/src/lib.rs b/src/lib.rs index 20114d94d..1b730c6ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,7 @@ //! //! ## The Gist //! -//! - Create a [`reqwest::Client`][default] +//! - Create a [`ClientSync`][default] //! - Call [`elastic_req`][elastic_req] on the client //! - Work with the raw http response //! - Or call [`parse`][parse] to get a concrete response or API error @@ -170,8 +170,6 @@ //! [repo]: https://github.com/elastic-rs/elastic-reqwest //! [crates]: https://crates.io/crates/elastic_reqwest -#![cfg_attr(feature = "nightly", feature(specialization))] - #![deny(warnings)] #![deny(missing_docs)] @@ -186,10 +184,9 @@ extern crate serde_json; extern crate reqwest; extern crate url; extern crate bytes; -extern crate futures; - -#[cfg(test)] extern crate tokio_core; +extern crate tokio_io; +extern crate futures; mod sync; mod async; @@ -213,10 +210,13 @@ pub mod res { pub use self::res::parse; +use std::io::Error as IoError; use std::sync::Arc; use std::collections::BTreeMap; use std::str; -use reqwest::Error as ReqwestError; +use tokio_core::reactor::Handle; +use reqwest::{Client as ClientSync, Error as ReqwestError}; +use reqwest::unstable::async::Client as ClientAsync; use reqwest::header::{Headers, ContentType}; use url::form_urlencoded::Serializer; @@ -234,6 +234,13 @@ quick_error! { display("http error: {}", err) cause(err) } + /// An io error. + Io(err: IoError) { + from() + description("io error") + display("io error: {}", err) + cause(err) + } /// A response error. Response(err: ResponseError) { from() @@ -396,8 +403,15 @@ impl Default for RequestParams { } /// Get a default `Client` and `RequestParams`. -pub fn default() -> Result<(reqwest::Client, RequestParams), Error> { - reqwest::Client::new() +pub fn default_sync() -> Result<(ClientSync, RequestParams), Error> { + ClientSync::new() + .map(|cli| (cli, RequestParams::default())) + .map_err(Into::into) +} + +/// Get a default `Client` and `RequestParams`. +pub fn default_async(handle: &Handle) -> Result<(ClientAsync, RequestParams), Error> { + ClientAsync::new(handle) .map(|cli| (cli, RequestParams::default())) .map_err(Into::into) } diff --git a/src/sync.rs b/src/sync.rs index a37dc5bd9..1d73af783 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -80,20 +80,6 @@ pub trait ElasticClientSync { B: IntoBodySync; } -/// Represents a response that can be parsed into a concrete Elasticsearch response. -pub trait ParseResponseSync { - /// Parse a response into a concrete response type. - fn from_response(self, response: Response) -> Result; -} - -impl ParseResponseSync for Parse { - fn from_response(self, response: Response) -> Result { - let status: u16 = response.status().into(); - - self.from_reader(status, response).map_err(Into::into) - } -} - /// Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, @@ -126,6 +112,20 @@ impl ElasticClientSync for Client { } } +/// Represents a response that can be parsed into a concrete Elasticsearch response. +pub trait ParseResponseSync { + /// Parse a response into a concrete response type. + fn from_response(self, response: Response) -> Result; +} + +impl ParseResponseSync for Parse { + fn from_response(self, response: Response) -> Result { + let status: u16 = response.status().into(); + + self.from_reader(status, response).map_err(Into::into) + } +} + #[cfg(test)] mod tests { use reqwest::{Client, RequestBuilder, Method}; From 264fcb2f1713325ae671d6c75da6ffbb21b92e01 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 21 Jul 2017 19:45:04 +1000 Subject: [PATCH 109/127] track unstable reqwest --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ddd1d3bb9..12d7fb7a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ nightly = [] serde = "~1" elastic_requests = "~0.4.1" elastic_responses = "~0.9.0" -reqwest = { version = "*", git = "https://github.com/kodraus/reqwest.git", branch = "feat/async-decoder", features = ["unstable"] } +reqwest = { version = "*", git = "https://github.com/KodrAus/reqwest.git", branch = "feat/async-decoder", features = ["unstable"] } url = "~1" bytes = "*" tokio-core = "*" From 1350f1c7b0f304a67b85a193fcd8869dba72742e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 21 Jul 2017 21:34:11 +1000 Subject: [PATCH 110/127] rework sync and async split a bit --- examples/basic_async.rs | 2 +- examples/basic_sync.rs | 2 +- examples/bulk_sync.rs | 6 ++- src/async.rs | 85 +++++++++++++++++++++--------------- src/lib.rs | 18 ++++---- src/sync.rs | 97 ++++++++++++++++++++++++----------------- 6 files changed, 121 insertions(+), 89 deletions(-) diff --git a/examples/basic_async.rs b/examples/basic_async.rs index fdcd261c8..0c36eba7f 100644 --- a/examples/basic_async.rs +++ b/examples/basic_async.rs @@ -14,7 +14,7 @@ extern crate elastic_reqwest as cli; use serde_json::Value; use tokio_core::reactor::Core; use futures::Future; -use cli::{ElasticClientAsync, ParseResponseAsync, RequestParams, Error}; +use cli::{AsyncElasticClient, AsyncFromResponse, RequestParams, Error}; use cli::req::SearchRequest; use cli::res::{parse, SearchResponse}; diff --git a/examples/basic_sync.rs b/examples/basic_sync.rs index 9b6f60098..4a3717c23 100644 --- a/examples/basic_sync.rs +++ b/examples/basic_sync.rs @@ -10,7 +10,7 @@ extern crate serde_json; extern crate elastic_reqwest as cli; use serde_json::Value; -use cli::{ElasticClientSync, ParseResponseSync, RequestParams, Error}; +use cli::{SyncElasticClient, SyncFromResponse, RequestParams, Error}; use cli::req::SearchRequest; use cli::res::{parse, SearchResponse}; diff --git a/examples/bulk_sync.rs b/examples/bulk_sync.rs index 8c1f8d015..6d2c4fdfb 100644 --- a/examples/bulk_sync.rs +++ b/examples/bulk_sync.rs @@ -6,7 +6,7 @@ extern crate elastic_reqwest as cli; -use cli::{ElasticClient, ParseResponse}; +use cli::{SyncElasticClient, SyncFromResponse, Error}; use cli::req::BulkRequest; use cli::res::{parse, BulkResponse}; @@ -28,7 +28,7 @@ fn get_req() -> String { fn run() -> Result<(), Error> { // Get a new default client. - let (client, params) = cli::default()?; + let (client, params) = cli::default_sync()?; // Send the bulk request. let http_res = client.elastic_req(¶ms, BulkRequest::new(get_req()))?; @@ -36,6 +36,8 @@ fn run() -> Result<(), Error> { let res = parse::().from_response(http_res)?; println!("{:?}", res); + + Ok(()) } fn main() { diff --git a/src/async.rs b/src/async.rs index df7334a46..8206b921a 100644 --- a/src/async.rs +++ b/src/async.rs @@ -1,3 +1,6 @@ +/*! Asynchronous http client. */ + +use std::ops::Deref; use bytes::Bytes; use serde::de::DeserializeOwned; use serde_json::Value; @@ -10,59 +13,71 @@ use super::res::parsing::{Parse, IsOk}; use super::{Error, RequestParams, build_url, build_method}; /// A type that can be converted into a request body. -pub trait IntoBodyAsync { - /// Convert self into a body. - fn into_body(self) -> Body; +pub struct AsyncBody(Body); + +impl AsyncBody { + /// Convert the body into its inner value. + pub fn into_inner(self) -> Body { + self.0 + } +} + +impl Deref for AsyncBody { + type Target = Body; + + fn deref(&self) -> &Self::Target { + &self.0 + } } -impl IntoBodyAsync for Body { - fn into_body(self) -> Body { - self +impl From for AsyncBody { + fn from(body: Body) -> AsyncBody { + AsyncBody(body) } } -impl IntoBodyAsync for Vec { - fn into_body(self) -> Body { - self.into() +impl From> for AsyncBody { + fn from(body: Vec) -> AsyncBody { + AsyncBody(body.into()) } } -impl IntoBodyAsync for String { - fn into_body(self) -> Body { - self.into() +impl From for AsyncBody { + fn from(body: String) -> AsyncBody { + AsyncBody(body.into()) } } -impl IntoBodyAsync for Value { - fn into_body(self) -> Body { - self.to_string().into() +impl From for AsyncBody { + fn from(body: Value) -> AsyncBody { + AsyncBody(body.to_string().into()) } } -impl IntoBodyAsync for &'static [u8] { - fn into_body(self) -> Body { - Bytes::from(self).into() +impl From<&'static [u8]> for AsyncBody { + fn from(body: &'static [u8]) -> AsyncBody { + AsyncBody(Bytes::from(body).into()) } } -impl IntoBodyAsync for &'static str { - fn into_body(self) -> Body { - Bytes::from(self).into() +impl From<&'static str> for AsyncBody { + fn from(body: &'static str) -> AsyncBody { + AsyncBody(Bytes::from(body).into()) } } /// Represents a client that can send Elasticsearch requests. -pub trait ElasticClientAsync { +pub trait AsyncElasticClient { /// Send a request and get a response. fn elastic_req(&self, params: &RequestParams, req: I) -> Box> where I: Into>, - B: IntoBodyAsync; + B: Into; } /// Build an asynchronous `reqwest::RequestBuilder` from an Elasticsearch request. pub fn build_req_async(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, - B: IntoBodyAsync + B: Into { let req = req.into(); @@ -75,17 +90,17 @@ pub fn build_req_async(client: &Client, params: &RequestParams, req: I) -> req.headers(params.get_headers()); if let Some(body) = body { - req.body(body.into_body()); + req.body(body.into().into_inner()); } } Ok(req) } -impl ElasticClientAsync for Client { +impl AsyncElasticClient for Client { fn elastic_req(&self, params: &RequestParams, req: I) -> Box> where I: Into>, - B: IntoBodyAsync + B: Into { let fut = build_req_async(&self, params, req) .into_future() @@ -96,12 +111,12 @@ impl ElasticClientAsync for Client { } /// Represents a response that can be parsed into a concrete Elasticsearch response. -pub trait ParseResponseAsync { +pub trait AsyncFromResponse { /// Parse a response into a concrete response type. fn from_response(self, response: Response) -> Box>; } -impl ParseResponseAsync for Parse { +impl AsyncFromResponse for Parse { fn from_response(self, response: Response) -> Box> { let status: u16 = response.status().into(); @@ -220,33 +235,33 @@ mod tests { #[test] fn owned_string_into_body() { - String::new().into_body(); + AsyncBody::from(String::new()); } #[test] fn borrowed_string_into_body() { - "abc".into_body(); + AsyncBody::from("abc"); } #[test] fn owned_vec_into_body() { - Vec::new().into_body(); + AsyncBody::from(Vec::new()); } #[test] fn borrowed_vec_into_body() { static BODY: &'static [u8] = &[0, 1, 2]; - (&BODY).into_body(); + AsyncBody::from(BODY); } #[test] fn empty_body_into_body() { - empty_body().into_body(); + AsyncBody::from(empty_body()); } #[test] fn json_value_into_body() { - json!({}).into_body(); + AsyncBody::from(json!({})); } } diff --git a/src/lib.rs b/src/lib.rs index 1b730c6ff..cb86f0649 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ //! extern crate reqwest; //! extern crate elastic_reqwest as cli; //! -//! use cli::{ElasticClientSync, ParseResponse, parse}; +//! use cli::{SyncElasticClient, ParseResponse, parse}; //! # fn main() {} //! ``` //! @@ -61,7 +61,7 @@ //! //HTTP HEAD / //! //! # extern crate elastic_reqwest as cli; -//! use cli::ElasticClientSync; +//! use cli::SyncElasticClient; //! use cli::req::PingRequest; //! //! # fn main() { @@ -80,7 +80,7 @@ //! //! extern crate elastic_reqwest as cli; //! -//! use cli::{ ElasticClientSync, ParseResponse, RequestParams, parse }; +//! use cli::{ SyncElasticClient, ParseResponse, RequestParams, parse }; //! use cli::req::SimpleSearchRequest; //! use cli::res::SearchResponse; //! @@ -112,7 +112,7 @@ //! extern crate json_str; //! extern crate elastic_reqwest as cli; //! -//! use cli::{ElasticClientSync, ParseResponse, parse}; +//! use cli::{SyncElasticClient, ParseResponse, parse}; //! use cli::req::SearchRequest; //! use cli::res::SearchResponse; //! @@ -160,7 +160,7 @@ //! - [Github][repo] //! //! [default]: fn.default.html -//! [elastic_req]: trait.ElasticClientSync.html#tymethod.elastic_req +//! [elastic_req]: trait.SyncElasticClient.html#tymethod.elastic_req //! [parse]: fn.parse.html //! [elastic]: https://github.com/elastic-rs/elastic //! [rs-es]: https://github.com/benashford/rs-es @@ -188,11 +188,11 @@ extern crate tokio_core; extern crate tokio_io; extern crate futures; -mod sync; -mod async; +pub mod sync; +pub mod async; -pub use self::sync::*; -pub use self::async::*; +pub use self::sync::{SyncElasticClient, SyncBody, SyncFromResponse}; +pub use self::async::{AsyncElasticClient, AsyncBody, AsyncFromResponse}; /// Request types. /// diff --git a/src/sync.rs b/src/sync.rs index 1d73af783..f56c61ce5 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,3 +1,6 @@ +/*! Synchronous http client. */ + +use std::ops::Deref; use std::io::Cursor; use std::fs::File; use serde::de::DeserializeOwned; @@ -9,67 +12,79 @@ use super::res::parsing::{Parse, IsOk}; use super::{Error, RequestParams, build_url, build_method}; /// A type that can be converted into a request body. -pub trait IntoBodySync { - /// Convert self into a body. - fn into_body(self) -> Body; +pub struct SyncBody(Body); + +impl SyncBody { + /// Convert the body into its inner value. + pub fn into_inner(self) -> Body { + self.0 + } +} + +impl Deref for SyncBody { + type Target = Body; + + fn deref(&self) -> &Self::Target { + &self.0 + } } -impl IntoBodySync for Body { - fn into_body(self) -> Body { - self +impl From for SyncBody { + fn from(body: Body) -> SyncBody { + SyncBody(body) } } -impl IntoBodySync for File { - fn into_body(self) -> Body { - self.into() +impl From for SyncBody { + fn from(body: File) -> SyncBody { + SyncBody(body.into()) } } -impl IntoBodySync for Vec { - fn into_body(self) -> Body { - self.into() +impl From> for SyncBody { + fn from(body: Vec) -> SyncBody { + SyncBody(body.into()) } } -impl IntoBodySync for String { - fn into_body(self) -> Body { - self.into() +impl From for SyncBody { + fn from(body: String) -> SyncBody { + SyncBody(body.into()) } } -impl IntoBodySync for Value { - fn into_body(self) -> Body { - self.to_string().into() +impl From for SyncBody { + fn from(body: Value) -> SyncBody { + SyncBody(body.to_string().into()) } } -impl IntoBodySync for &'static [u8] { - fn into_body(self) -> Body { - Body::new(Cursor::new(self)) +impl From<&'static [u8]> for SyncBody { + fn from(body: &'static [u8]) -> SyncBody { + SyncBody(Body::new(Cursor::new(body))) } } -impl IntoBodySync for &'static str { - fn into_body(self) -> Body { - Body::new(Cursor::new(self)) +impl From<&'static str> for SyncBody { + fn from(body: &'static str) -> SyncBody { + SyncBody(Body::new(Cursor::new(body))) } } /// Represents a client that can send Elasticsearch requests. -pub trait ElasticClientSync { +pub trait SyncElasticClient { /// Send a request and get a response. /// /// # Examples /// - /// Bring the `ElasticClientSync` trait into scope and call `elastic_req` with any type that + /// Bring the `SyncElasticClient` trait into scope and call `elastic_req` with any type that /// can be converted into a `req::HttpRequest`. /// This method returns a raw `reqwest::Response`. /// /// ```no_run /// # use elastic_reqwest::req::SimpleSearchRequest; /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); - /// use elastic_reqwest::ElasticClientSync; + /// use elastic_reqwest::SyncElasticClient; /// /// let (client, params) = elastic_reqwest::default().unwrap(); /// @@ -77,13 +92,13 @@ pub trait ElasticClientSync { /// ``` fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, - B: IntoBodySync; + B: Into; } /// Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, - B: IntoBodySync + B: Into { let req = req.into(); @@ -96,29 +111,29 @@ pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> req.headers(params.get_headers()); if let Some(body) = body { - req.body(body.into_body()); + req.body(body.into().into_inner()); } } Ok(req) } -impl ElasticClientSync for Client { +impl SyncElasticClient for Client { fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, - B: IntoBodySync + B: Into { build_req_sync(&self, params, req)?.send().map_err(Into::into) } } /// Represents a response that can be parsed into a concrete Elasticsearch response. -pub trait ParseResponseSync { +pub trait SyncFromResponse { /// Parse a response into a concrete response type. fn from_response(self, response: Response) -> Result; } -impl ParseResponseSync for Parse { +impl SyncFromResponse for Parse { fn from_response(self, response: Response) -> Result { let status: u16 = response.status().into(); @@ -222,38 +237,38 @@ mod tests { #[test] fn file_into_body() { - File::open("Cargo.toml").unwrap().into_body(); + SyncBody::from(File::open("Cargo.toml").unwrap()); } #[test] fn owned_string_into_body() { - String::new().into_body(); + SyncBody::from(String::new()); } #[test] fn borrowed_string_into_body() { - "abc".into_body(); + SyncBody::from("abc"); } #[test] fn owned_vec_into_body() { - Vec::new().into_body(); + SyncBody::from(Vec::new()); } #[test] fn borrowed_vec_into_body() { static BODY: &'static [u8] = &[0, 1, 2]; - (&BODY).into_body(); + SyncBody::from(BODY); } #[test] fn empty_body_into_body() { - empty_body().into_body(); + SyncBody::from(empty_body()); } #[test] fn json_value_into_body() { - json!({}).into_body(); + SyncBody::from(json!({})); } } From 997950a61fd7308cc82eed169750787201a17e75 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Thu, 27 Jul 2017 19:56:18 +1000 Subject: [PATCH 111/127] update docs --- examples/basic_async.rs | 10 +- examples/basic_sync.rs | 10 +- examples/bulk_sync.rs | 10 +- examples/typed/src/main.rs | 10 +- src/async.rs | 46 ++- src/lib.rs | 571 ++++++++++++++++++++----------------- src/sync.rs | 58 ++-- 7 files changed, 397 insertions(+), 318 deletions(-) diff --git a/examples/basic_async.rs b/examples/basic_async.rs index 0c36eba7f..a8ecc3030 100644 --- a/examples/basic_async.rs +++ b/examples/basic_async.rs @@ -9,20 +9,20 @@ extern crate serde_json; extern crate tokio_core; extern crate futures; -extern crate elastic_reqwest as cli; +extern crate elastic_reqwest; use serde_json::Value; use tokio_core::reactor::Core; use futures::Future; -use cli::{AsyncElasticClient, AsyncFromResponse, RequestParams, Error}; -use cli::req::SearchRequest; -use cli::res::{parse, SearchResponse}; +use elastic_reqwest::{AsyncElasticClient, AsyncFromResponse, RequestParams, Error}; +use elastic_reqwest::req::SearchRequest; +use elastic_reqwest::res::{parse, SearchResponse}; fn run() -> Result<(), Error> { let mut core = Core::new().unwrap(); // Get a new default client. - let (client, _) = cli::default_async(&core.handle())?; + let (client, _) = elastic_reqwest::async::default(&core.handle())?; // Create a new set of params with pretty printing. let params = RequestParams::default().url_param("pretty", true); diff --git a/examples/basic_sync.rs b/examples/basic_sync.rs index 4a3717c23..9cdfebfc3 100644 --- a/examples/basic_sync.rs +++ b/examples/basic_sync.rs @@ -7,16 +7,16 @@ #[macro_use] extern crate serde_json; -extern crate elastic_reqwest as cli; +extern crate elastic_reqwest; use serde_json::Value; -use cli::{SyncElasticClient, SyncFromResponse, RequestParams, Error}; -use cli::req::SearchRequest; -use cli::res::{parse, SearchResponse}; +use elastic_reqwest::{SyncElasticClient, SyncFromResponse, RequestParams, Error}; +use elastic_reqwest::req::SearchRequest; +use elastic_reqwest::res::{parse, SearchResponse}; fn run() -> Result<(), Error> { // Get a new default client. - let (client, _) = cli::default_sync()?; + let (client, _) = elastic_reqwest::sync::default()?; // Create a new set of params with pretty printing. let params = RequestParams::default().url_param("pretty", true); diff --git a/examples/bulk_sync.rs b/examples/bulk_sync.rs index 6d2c4fdfb..002a347cf 100644 --- a/examples/bulk_sync.rs +++ b/examples/bulk_sync.rs @@ -4,11 +4,11 @@ //! //! This sample demonstrates a request with a large body. -extern crate elastic_reqwest as cli; +extern crate elastic_reqwest; -use cli::{SyncElasticClient, SyncFromResponse, Error}; -use cli::req::BulkRequest; -use cli::res::{parse, BulkResponse}; +use elastic_reqwest::{SyncElasticClient, SyncFromResponse, Error}; +use elastic_reqwest::req::BulkRequest; +use elastic_reqwest::res::{parse, BulkResponse}; // Create a bulk request to index a bunch of docs. fn get_req() -> String { @@ -28,7 +28,7 @@ fn get_req() -> String { fn run() -> Result<(), Error> { // Get a new default client. - let (client, params) = cli::default_sync()?; + let (client, params) = elastic_reqwest::sync::default()?; // Send the bulk request. let http_res = client.elastic_req(¶ms, BulkRequest::new(get_req()))?; diff --git a/examples/typed/src/main.rs b/examples/typed/src/main.rs index 017606195..59b75be44 100644 --- a/examples/typed/src/main.rs +++ b/examples/typed/src/main.rs @@ -17,13 +17,13 @@ extern crate serde_derive; extern crate elastic_types; #[macro_use] extern crate elastic_types_derive; -extern crate elastic_reqwest as cli; +extern crate elastic_reqwest; use std::net::Ipv4Addr; use reqwest::Client; -use cli::{ElasticClient, ParseResponse, RequestParams}; -use cli::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; -use cli::res::{parse, CommandResponse, IndexResponse, SearchResponse, Hit}; +use elastic_reqwest::{ElasticClient, ParseResponse, RequestParams}; +use elastic_reqwest::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; +use elastic_reqwest::res::{parse, CommandResponse, IndexResponse, SearchResponse, Hit}; use elastic_types::prelude::*; mod data; @@ -33,7 +33,7 @@ const INDEX: &'static str = "testidx"; fn main() { // Create a new client - let (client, params) = cli::default().unwrap(); + let (client, params) = elastic_reqwest::sync::default().unwrap(); // Wait for refresh when indexing data. // Normally this isn't a good idea, but is ok for this example. diff --git a/src/async.rs b/src/async.rs index 8206b921a..b0344cf67 100644 --- a/src/async.rs +++ b/src/async.rs @@ -6,17 +6,25 @@ use serde::de::DeserializeOwned; use serde_json::Value; use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; use futures::{Future, IntoFuture}; +use tokio_core::reactor::Handle; use tokio_io::io; use super::req::HttpRequest; use super::res::parsing::{Parse, IsOk}; use super::{Error, RequestParams, build_url, build_method}; -/// A type that can be converted into a request body. +/** Get a default `Client` and `RequestParams`. */ +pub fn default(handle: &Handle) -> Result<(Client, RequestParams), Error> { + Client::new(handle) + .map(|cli| (cli, RequestParams::default())) + .map_err(Into::into) +} + +/** A type that can be converted into a request body. */ pub struct AsyncBody(Body); impl AsyncBody { - /// Convert the body into its inner value. + /** Convert the body into its inner value. */ pub fn into_inner(self) -> Body { self.0 } @@ -66,15 +74,39 @@ impl From<&'static str> for AsyncBody { } } -/// Represents a client that can send Elasticsearch requests. +/** Represents a client that can send Elasticsearch requests asynchronously. */ pub trait AsyncElasticClient { - /// Send a request and get a response. + /** + Send a request and get a response. + + # Examples + + Bring the `AsyncElasticClient` trait into scope and call `elastic_req` with any type that can be converted into a `req::HttpRequest`. + This method returns a raw `reqwest::Response`. + + ```no_run + # extern crate elastic_reqwest; + # extern crate tokio_core; + # use elastic_reqwest::req::SimpleSearchRequest; + # fn main() { + # let mut core = tokio_core::reactor::Core::new().unwrap(); + # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); + use elastic_reqwest::AsyncElasticClient; + + let (client, params) = elastic_reqwest::async::default(&core.handle()).unwrap(); + + let http_future = client.elastic_req(¶ms, request); + + core.run(http_future).unwrap(); + # } + ``` + */ fn elastic_req(&self, params: &RequestParams, req: I) -> Box> where I: Into>, B: Into; } -/// Build an asynchronous `reqwest::RequestBuilder` from an Elasticsearch request. +/** Build an asynchronous `reqwest::RequestBuilder` from an Elasticsearch request. */ pub fn build_req_async(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: Into @@ -110,9 +142,9 @@ impl AsyncElasticClient for Client { } } -/// Represents a response that can be parsed into a concrete Elasticsearch response. +/** Represents a response that can be parsed into a concrete Elasticsearch response. */ pub trait AsyncFromResponse { - /// Parse a response into a concrete response type. + /** Parse a response into a concrete response type. */ fn from_response(self, response: Response) -> Box>; } diff --git a/src/lib.rs b/src/lib.rs index cb86f0649..1dc325a8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,174 +1,214 @@ -//! Elasticsearch REST API Client -//! -//! A lightweight implementation of the Elasticsearch API based on the -//! [`reqwest`][reqwest] HTTP client. -//! -//! Each API endpoint is represented as its own type, that only accept a valid combination -//! of route parameters. -//! This library makes very few assumptions, leaving it up to you to decide what to invest your -//! precious CPU cycles into. -//! -//! The API is generated from the official Elasticsearch spec, so it's always current. -//! -//! # Supported Versions -//! -//! `elastic_types` | Elasticsearch -//! --------------- | ------------- -//! `0.x` | `5.x` -//! -//! # Usage -//! -//! This crate is on [crates.io][crates]. -//! To get started, add `elastic_reqwest` and `reqwest` to your `Cargo.toml`: -//! -//! ```ignore -//! [dependencies] -//! elastic_reqwest = "*" -//! reqwest = "*" -//! ``` -//! -//! On the `nightly` channel, you can use the `nightly` feature -//! to avoid copying borrowed body buffers: -//! -//! ```ignore -//! [dependencies] -//! elastic_reqwest = { version = "*", features = ["nightly"] } -//! reqwest = "*" -//! ``` -//! -//! Then reference in your crate root: -//! -//! ``` -//! extern crate reqwest; -//! extern crate elastic_reqwest as cli; -//! -//! use cli::{SyncElasticClient, ParseResponse, parse}; -//! # fn main() {} -//! ``` -//! -//! ## The Gist -//! -//! - Create a [`ClientSync`][default] -//! - Call [`elastic_req`][elastic_req] on the client -//! - Work with the raw http response -//! - Or call [`parse`][parse] to get a concrete response or API error -//! -//! ## Minimal Example -//! -//! Ping the availability of your cluster: -//! -//! ```no_run -//! //HTTP HEAD / -//! -//! # extern crate elastic_reqwest as cli; -//! use cli::SyncElasticClient; -//! use cli::req::PingRequest; -//! -//! # fn main() { -//! let (client, params) = cli::default().unwrap(); -//! -//! client.elastic_req(¶ms, PingRequest::new()).unwrap(); -//! # } -//! ``` -//! -//! ## Search Request with Url Param -//! -//! Execute a search query with a url parameter: -//! -//! ```no_run -//! //HTTP GET /myindex/mytype/_search?q=* -//! -//! extern crate elastic_reqwest as cli; -//! -//! use cli::{ SyncElasticClient, ParseResponse, RequestParams, parse }; -//! use cli::req::SimpleSearchRequest; -//! use cli::res::SearchResponse; -//! -//! # fn main() { -//! let (client, _) = cli::default().unwrap(); -//! -//! let params = RequestParams::default() -//! .url_param("pretty", true) -//! .url_param("q", "*"); -//! -//! let search = SimpleSearchRequest::for_index_ty( -//! "myindex", "mytype" -//! ); -//! -//! let http_res = client.elastic_req(¶ms, search).unwrap(); -//! let search_res = parse::().from_response(http_res).unwrap(); -//! # } -//! ``` -//! -//! ## Search Request with Json -//! -//! Using the [`json_str`][json_str] crate, you can execute -//! queries using pure json: -//! -//! ```no_run -//! //HTTP POST /myindex/mytype/_search -//! -//! #[macro_use] -//! extern crate json_str; -//! extern crate elastic_reqwest as cli; -//! -//! use cli::{SyncElasticClient, ParseResponse, parse}; -//! use cli::req::SearchRequest; -//! use cli::res::SearchResponse; -//! -//! # fn main() { -//! let (client, params) = cli::default().unwrap(); -//! -//! let search = SearchRequest::for_index_ty( -//! "myindex", "mytype", -//! json_str!({ -//! query: { -//! filtered: { -//! query: { -//! match_all: {} -//! }, -//! filter: { -//! geo_distance: { -//! distance: "20km", -//! location: { -//! lat: 37.776, -//! lon: -122.41 -//! } -//! } -//! } -//! } -//! } -//! }) -//! ); -//! -//! let http_res = client.elastic_req(¶ms, search).unwrap(); -//! let search_res = parse::().from_response(http_res).unwrap(); -//! # } -//! ``` -//! -//! # See Also -//! -//! - [`elastic`][elastic]. -//! A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. -//! - [`rs-es`][rs-es]. -//! A higher-level Elasticsearch client that provides strongly-typed Query DSL buiilders. -//! - [`json_str`][json_str] -//! A library for generating minified json strings from Rust syntax. -//! -//! # Links -//! - [Elasticsearch Docs][es-docs] -//! - [Github][repo] -//! -//! [default]: fn.default.html -//! [elastic_req]: trait.SyncElasticClient.html#tymethod.elastic_req -//! [parse]: fn.parse.html -//! [elastic]: https://github.com/elastic-rs/elastic -//! [rs-es]: https://github.com/benashford/rs-es -//! [json_str]: https://github.com/KodrAus/json_str -//! [reqwest]: https://github.com/seanmonstar/reqwest/ -//! [es-docs]: https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html -//! [repo]: https://github.com/elastic-rs/elastic-reqwest -//! [crates]: https://crates.io/crates/elastic_reqwest +/*! +Elasticsearch REST API Client + +A lightweight implementation of the Elasticsearch API based on the [`reqwest`][reqwest] HTTP client. + +Each API endpoint is represented as its own type, that only accept a valid combination of route parameters. +This library makes very few assumptions, leaving it up to you to decide what to invest your precious CPU cycles into. + +The API is generated from the official Elasticsearch spec, so it's always current. + +# Supported Versions + + `elastic_types` | Elasticsearch + --------------- | ------------- + `0.x` | `5.x` + +# Usage + +This crate is on [crates.io][crates]. +To get started, add `elastic_reqwest` and `reqwest` to your `Cargo.toml`: + +```ignore +[dependencies] +elastic_reqwest = "*" +reqwest = "*" +``` + +Then reference in your crate root: + +``` +extern crate elastic_reqwest; +# fn main() {} +``` + +# Making synchronous requests + +- Create a [`SyncClient`][default_sync] +- Call [`elastic_req`][elastic_req_sync] on the client +- Work with the raw http response +- Or call [`parse`][parse] to get a concrete response or API error + +## Minimal Example + +Execute a search request synchronously and parse the response: + +```no_run +//HTTP POST /myindex/mytype/_search + +#[macro_use] +extern crate serde_json; +extern crate elastic_reqwest; + +use serde_json::Value; +use elastic_reqwest::{SyncElasticClient, SyncFromResponse, parse}; +use elastic_reqwest::req::SearchRequest; +use elastic_reqwest::res::SearchResponse; + +# fn main() { +let (client, params) = elastic_reqwest::sync::default().unwrap(); + +let search = SearchRequest::for_index_ty( + "myindex", "mytype", + json!({ + "query": { + "filtered": { + "query": { + "match_all": {} + }, + "filter": { + "geo_distance": { + "distance": "20km", + "location": { + "lat": 37.776, + "lon": -122.41 + } + } + } + } + } + }) +); + +let http_res = client.elastic_req(¶ms, search).unwrap(); +let search_res = parse::>().from_response(http_res).unwrap(); +# } +``` + +# Making asynchronous requests + +- Create an [`AsyncClient`][default_async] +- Call [`elastic_req`][elastic_req_async] on the client +- Work with the raw http response +- Or call [`parse`][parse] to get a concrete response or API error + +## Minimal Example + +Execute a search request asynchronously and parse the response: + +```no_run +//HTTP POST /myindex/mytype/_search + +#[macro_use] +extern crate serde_json; +extern crate elastic_reqwest; +extern crate tokio_core; +extern crate tokio_io; +extern crate futures; + +use tokio_core::reactor::Core; +use futures::Future; +use serde_json::Value; +use elastic_reqwest::{AsyncElasticClient, AsyncFromResponse, parse}; +use elastic_reqwest::req::SearchRequest; +use elastic_reqwest::res::SearchResponse; + +# fn main() { +let mut core = Core::new().unwrap(); + +let (client, params) = elastic_reqwest::async::default(&core.handle()).unwrap(); + +let search = SearchRequest::for_index_ty( + "myindex", "mytype", + json!({ + "query": { + "filtered": { + "query": { + "match_all": {} + }, + "filter": { + "geo_distance": { + "distance": "20km", + "location": { + "lat": 37.776, + "lon": -122.41 + } + } + } + } + } + }) +); + +let search_future = client + .elastic_req(¶ms, search) + .and_then(|http_res| parse::>().from_response(http_res)) + .and_then(|search_res| { + println!("{:?}", search_res); + Ok(()) + }); + +core.run(search_future).unwrap(); +# } +``` + +## Search Request with Url Param + +Execute a search request with a url parameter: + +```no_run +//HTTP GET /myindex/mytype/_search?q=* + +extern crate serde_json; +extern crate elastic_reqwest; + +use serde_json::Value; +use elastic_reqwest::{ SyncElasticClient, SyncFromResponse, RequestParams, parse }; +use elastic_reqwest::req::SimpleSearchRequest; +use elastic_reqwest::res::SearchResponse; + +# fn main() { +let (client, _) = elastic_reqwest::sync::default().unwrap(); + +let params = RequestParams::default() + .url_param("pretty", true) + .url_param("q", "*"); + +let search = SimpleSearchRequest::for_index_ty( + "myindex", "mytype" +); + +let http_res = client.elastic_req(¶ms, search).unwrap(); +let search_res = parse::>().from_response(http_res).unwrap(); +# } +``` + +# See Also + +- [`elastic`][elastic]. +A higher-level Elasticsearch client that uses `elastic_reqwest` as its HTTP layer. +- [`rs-es`][rs-es]. +A higher-level Elasticsearch client that provides strongly-typed Query DSL buiilders. +- [`json_str`][json_str] +A library for generating minified json strings from Rust syntax. + +# Links +- [Elasticsearch Docs][es-docs] +- [Github][repo] + +[default_sync]: sync/fn.default.html +[default_async]: async/fn.default.html +[elastic_req_sync]: sync/trait.SyncElasticClient.html#tymethod.elastic_req +[elastic_req_async]: async/trait.AsyncElasticClient.html#tymethod.elastic_req +[parse]: fn.parse.html +[elastic]: https://github.com/elastic-rs/elastic +[rs-es]: https://github.com/benashford/rs-es +[json_str]: https://github.com/KodrAus/json_str +[reqwest]: https://github.com/seanmonstar/reqwest/ +[es-docs]: https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html +[repo]: https://github.com/elastic-rs/elastic-reqwest +[crates]: https://crates.io/crates/elastic_reqwest +*/ #![deny(warnings)] #![deny(missing_docs)] @@ -194,16 +234,20 @@ pub mod async; pub use self::sync::{SyncElasticClient, SyncBody, SyncFromResponse}; pub use self::async::{AsyncElasticClient, AsyncBody, AsyncFromResponse}; -/// Request types. -/// -/// These are re-exported from `elastic_requests` for convenience. +/** +Request types. + +These are re-exported from `elastic_requests` for convenience. +*/ pub mod req { pub use elastic_requests::*; } -/// Response types. -/// -/// These are re-exported from `elastic_responses` for convenience. +/** +Response types. + +These are re-exported from `elastic_responses` for convenience. +*/ pub mod res { pub use elastic_responses::*; } @@ -214,9 +258,7 @@ use std::io::Error as IoError; use std::sync::Arc; use std::collections::BTreeMap; use std::str; -use tokio_core::reactor::Handle; -use reqwest::{Client as ClientSync, Error as ReqwestError}; -use reqwest::unstable::async::Client as ClientAsync; +use reqwest::Error as ReqwestError; use reqwest::header::{Headers, ContentType}; use url::form_urlencoded::Serializer; @@ -224,24 +266,24 @@ use self::res::error::ResponseError; use self::req::HttpMethod; quick_error! { - /// An error sending a request or parsing a response. + /** An error sending a request or parsing a response. */ #[derive(Debug)] pub enum Error { - /// A http error. + /** A http error. */ Http(err: ReqwestError) { from() description("http error") display("http error: {}", err) cause(err) } - /// An io error. + /** An io error. */ Io(err: IoError) { from() description("io error") display("io error: {}", err) cause(err) } - /// A response error. + /** A response error. */ Response(err: ResponseError) { from() description("response error") @@ -251,68 +293,71 @@ quick_error! { } } -/// Misc parameters for any request. -/// -/// The `RequestParams` struct allows you to set headers and url parameters for your requests. -/// By default, the `ContentType::json` header will always be added. -/// Url parameters are added as simple key-value pairs, and serialised by [rust-url](http://servo.github.io/rust-url/url/index.html). -/// -/// # Examples -/// -/// With default query parameters: -/// -/// ``` -/// # use elastic_reqwest::RequestParams; -/// let params = RequestParams::default(); -/// ``` -/// -/// With a custom base url: -/// -/// ``` -/// # use elastic_reqwest::RequestParams; -/// let params = RequestParams::new("http://mybaseurl:9200"); -/// ``` -/// -/// With custom headers: -/// -/// ``` -/// # extern crate reqwest; -/// # extern crate elastic_reqwest; -/// # use elastic_reqwest::RequestParams; -/// # use reqwest::header::Authorization; -/// # fn main() { -/// let params = RequestParams::default() -/// .header(Authorization("let me in".to_owned())); -/// # } -/// ``` -/// -/// With url query parameters: -/// -/// ``` -/// # extern crate elastic_reqwest; -/// # use elastic_reqwest::RequestParams; -/// # fn main() { -/// let params = RequestParams::default() -/// .url_param("pretty", true) -/// .url_param("q", "*"); -/// # } -/// ``` +/** +Misc parameters for any request. + +The `RequestParams` struct allows you to set headers and url parameters for your requests. +By default, the `ContentType::json` header will always be added. +Url parameters are added as simple key-value pairs, and serialised by [rust-url](http://servo.github.io/rust-url/url/index.html). + +# Examples + +With default query parameters: + +``` +# use elastic_reqwest::RequestParams; +let params = RequestParams::default(); +``` + +With a custom base url: + +``` +# use elastic_reqwest::RequestParams; +let params = RequestParams::new("http://mybaseurl:9200"); +``` + +With custom headers: + +``` +# extern crate reqwest; +# extern crate elastic_reqwest; +# use elastic_reqwest::RequestParams; +# use reqwest::header::Authorization; +# fn main() { +let params = RequestParams::default() + .headers(|h| h.set(Authorization("let me in".to_owned()))); +# } +``` + +With url query parameters: + +``` +# extern crate elastic_reqwest; +# use elastic_reqwest::RequestParams; +# fn main() { +let params = RequestParams::default() + .url_param("pretty", true) + .url_param("q", "*"); +# } +``` +*/ #[derive(Clone)] pub struct RequestParams { - /// Base url for Elasticsearch. + /** Base url for Elasticsearch. */ base_url: String, - /// Simple key-value store for url query params. + /** Simple key-value store for url query params. */ url_params: BTreeMap<&'static str, String>, - /// The complete set of headers that will be sent with the request. + /** The complete set of headers that will be sent with the request. */ headers_factory: Option>, } impl RequestParams { - /// Create a new container for request parameters. - /// - /// This method takes a fully-qualified url for the Elasticsearch - /// node. - /// It will also set the `Content-Type` header to `application/json`. + /** + Create a new container for request parameters. + + This method takes a fully-qualified url for the Elasticsearch node. + It will also set the `Content-Type` header to `application/json`. + */ pub fn new>(base: T) -> Self { RequestParams { base_url: base.into(), @@ -321,16 +366,18 @@ impl RequestParams { } } - /// Set the base url for the Elasticsearch node. + /** Set the base url for the Elasticsearch node. */ pub fn base_url>(mut self, base: T) -> Self { self.base_url = base.into(); self } - /// Set a url param value. - /// - /// These parameters are added as query parameters to request urls. + /** + Set a url param value. + + These parameters are added as query parameters to request urls. + */ pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { // This is safe because we know here that the key exists @@ -343,11 +390,12 @@ impl RequestParams { self } - /// Set a header value on the params. - /// - /// Each call to `headers` will chain to the end of the last call. - /// This function allocates a new `Box` for each call, so it's recommended to just call it once - /// and configure multiple headers, rather than calling it once per header. + /** + Set a header value on the params. + + Each call to `headers` will chain to the end of the last call. + This function allocates a new `Box` for each call, so it's recommended to just call it once and configure multiple headers, rather than calling it once per header. + */ pub fn headers(mut self, headers_factory: F) -> Self where F: Fn(&mut Headers) + Send + Sync + 'static { @@ -365,7 +413,7 @@ impl RequestParams { self } - /// Create a new `Headers` structure, and thread it through the configuration functions. + /** Create a new `Headers` structure, and thread it through the configuration functions. */ pub fn get_headers(&self) -> Headers { let mut headers = Headers::new(); headers.set(ContentType::json()); @@ -377,12 +425,13 @@ impl RequestParams { headers } - /// Get the url query params as a formatted string. - /// - /// Follows the `application/x-www-form-urlencoded` format. - /// This method returns the length of the query string and an optional - /// value. - /// If the value is `None`, then the length will be `0`. + /** + Get the url query params as a formatted string. + + Follows the `application/x-www-form-urlencoded` format. + This method returns the length of the query string and an optional value. + If the value is `None`, then the length will be `0`. + */ pub fn get_url_qry(&self) -> (usize, Option) { if self.url_params.len() > 0 { let qry: String = Serializer::for_suffix(String::from("?"), 1) @@ -402,20 +451,6 @@ impl Default for RequestParams { } } -/// Get a default `Client` and `RequestParams`. -pub fn default_sync() -> Result<(ClientSync, RequestParams), Error> { - ClientSync::new() - .map(|cli| (cli, RequestParams::default())) - .map_err(Into::into) -} - -/// Get a default `Client` and `RequestParams`. -pub fn default_async(handle: &Handle) -> Result<(ClientAsync, RequestParams), Error> { - ClientAsync::new(handle) - .map(|cli| (cli, RequestParams::default())) - .map_err(Into::into) -} - fn build_url<'a>(req_url: &str, params: &RequestParams) -> String { let (qry_len, qry) = params.get_url_qry(); diff --git a/src/sync.rs b/src/sync.rs index f56c61ce5..f218f43a1 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -11,11 +11,18 @@ use super::req::HttpRequest; use super::res::parsing::{Parse, IsOk}; use super::{Error, RequestParams, build_url, build_method}; -/// A type that can be converted into a request body. +/** Get a default `Client` and `RequestParams`. */ +pub fn default() -> Result<(Client, RequestParams), Error> { + Client::new() + .map(|cli| (cli, RequestParams::default())) + .map_err(Into::into) +} + +/** A type that can be converted into a request body. */ pub struct SyncBody(Body); impl SyncBody { - /// Convert the body into its inner value. + /** Convert the body into its inner value. */ pub fn into_inner(self) -> Body { self.0 } @@ -71,31 +78,36 @@ impl From<&'static str> for SyncBody { } } -/// Represents a client that can send Elasticsearch requests. +/** Represents a client that can send Elasticsearch requests synchronously. */ pub trait SyncElasticClient { - /// Send a request and get a response. - /// - /// # Examples - /// - /// Bring the `SyncElasticClient` trait into scope and call `elastic_req` with any type that - /// can be converted into a `req::HttpRequest`. - /// This method returns a raw `reqwest::Response`. - /// - /// ```no_run - /// # use elastic_reqwest::req::SimpleSearchRequest; - /// # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); - /// use elastic_reqwest::SyncElasticClient; - /// - /// let (client, params) = elastic_reqwest::default().unwrap(); - /// - /// let http_res = client.elastic_req(¶ms, request).unwrap(); - /// ``` + /** + Send a request and get a response. + + # Examples + + Bring the `SyncElasticClient` trait into scope and call `elastic_req` with any type that + can be converted into a `req::HttpRequest`. + This method returns a raw `reqwest::Response`. + + ```no_run + # extern crate elastic_reqwest; + # use elastic_reqwest::req::SimpleSearchRequest; + # fn main () { + # let request = SimpleSearchRequest::for_index_ty("myindex", "mytype"); + use elastic_reqwest::SyncElasticClient; + + let (client, params) = elastic_reqwest::sync::default().unwrap(); + + let http_res = client.elastic_req(¶ms, request).unwrap(); + # } + ``` + */ fn elastic_req(&self, params: &RequestParams, req: I) -> Result where I: Into>, B: Into; } -/// Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. +/** Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. */ pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: Into @@ -127,9 +139,9 @@ impl SyncElasticClient for Client { } } -/// Represents a response that can be parsed into a concrete Elasticsearch response. +/** Represents a response that can be parsed into a concrete Elasticsearch response. */ pub trait SyncFromResponse { - /// Parse a response into a concrete response type. + /** Parse a response into a concrete response type. */ fn from_response(self, response: Response) -> Result; } From 3ee9c08ee167cd37b3cea3be9f302b4600657e75 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 28 Jul 2017 18:09:23 +1000 Subject: [PATCH 112/127] fix benches --- benches/mod.rs | 4 +++- src/async.rs | 14 +++++++------- src/sync.rs | 14 +++++++------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/benches/mod.rs b/benches/mod.rs index 4404319cd..06512b656 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -9,7 +9,9 @@ use reqwest::Client as ClientSync; use reqwest::unstable::async::Client as ClientAsync; use reqwest::header::Referer; use tokio_core::reactor::Core; -use elastic_reqwest::{build_req_sync, build_req_async, RequestParams}; +use elastic_reqwest::RequestParams; +use elastic_reqwest::sync::build_req as build_req_sync; +use elastic_reqwest::async::build_req as build_req_async; use elastic_reqwest::req::PingRequest; #[inline(always)] diff --git a/src/async.rs b/src/async.rs index b0344cf67..65297cd9e 100644 --- a/src/async.rs +++ b/src/async.rs @@ -107,7 +107,7 @@ pub trait AsyncElasticClient { } /** Build an asynchronous `reqwest::RequestBuilder` from an Elasticsearch request. */ -pub fn build_req_async(client: &Client, params: &RequestParams, req: I) -> Result +pub fn build_req(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: Into { @@ -134,7 +134,7 @@ impl AsyncElasticClient for Client { where I: Into>, B: Into { - let fut = build_req_async(&self, params, req) + let fut = build_req(&self, params, req) .into_future() .and_then(|mut req| req.send().map_err(Into::into)); @@ -204,7 +204,7 @@ mod tests { #[test] fn head_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req_async(&cli, ¶ms(), PingHeadRequest::new()); + let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); let url = "eshost:9200/path/?pretty=true&q=*"; @@ -216,7 +216,7 @@ mod tests { #[test] fn get_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req_async(&cli, ¶ms(), SimpleSearchRequest::new()); + let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); let url = "eshost:9200/path/_search?pretty=true&q=*"; @@ -228,7 +228,7 @@ mod tests { #[test] fn post_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req_async(&cli, + let req = build_req(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); @@ -242,7 +242,7 @@ mod tests { #[test] fn put_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req_async(&cli, + let req = build_req(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); @@ -256,7 +256,7 @@ mod tests { #[test] fn delete_req() { let cli = Client::new(&core().handle()).unwrap(); - let req = build_req_async(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); let url = "eshost:9200/path/idx?pretty=true&q=*"; diff --git a/src/sync.rs b/src/sync.rs index f218f43a1..8f64c8153 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -108,7 +108,7 @@ pub trait SyncElasticClient { } /** Build a synchronous `reqwest::RequestBuilder` from an Elasticsearch request. */ -pub fn build_req_sync(client: &Client, params: &RequestParams, req: I) -> Result +pub fn build_req(client: &Client, params: &RequestParams, req: I) -> Result where I: Into>, B: Into { @@ -135,7 +135,7 @@ impl SyncElasticClient for Client { where I: Into>, B: Into { - build_req_sync(&self, params, req)?.send().map_err(Into::into) + build_req(&self, params, req)?.send().map_err(Into::into) } } @@ -186,7 +186,7 @@ mod tests { #[test] fn head_req() { let cli = Client::new().unwrap(); - let req = build_req_sync(&cli, ¶ms(), PingHeadRequest::new()); + let req = build_req(&cli, ¶ms(), PingHeadRequest::new()); let url = "eshost:9200/path/?pretty=true&q=*"; @@ -198,7 +198,7 @@ mod tests { #[test] fn get_req() { let cli = Client::new().unwrap(); - let req = build_req_sync(&cli, ¶ms(), SimpleSearchRequest::new()); + let req = build_req(&cli, ¶ms(), SimpleSearchRequest::new()); let url = "eshost:9200/path/_search?pretty=true&q=*"; @@ -210,7 +210,7 @@ mod tests { #[test] fn post_req() { let cli = Client::new().unwrap(); - let req = build_req_sync(&cli, + let req = build_req(&cli, ¶ms(), PercolateRequest::for_index_ty("idx", "ty", vec![])); @@ -224,7 +224,7 @@ mod tests { #[test] fn put_req() { let cli = Client::new().unwrap(); - let req = build_req_sync(&cli, + let req = build_req(&cli, ¶ms(), IndicesCreateRequest::for_index("idx", vec![])); @@ -238,7 +238,7 @@ mod tests { #[test] fn delete_req() { let cli = Client::new().unwrap(); - let req = build_req_sync(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); + let req = build_req(&cli, ¶ms(), IndicesDeleteRequest::for_index("idx")); let url = "eshost:9200/path/idx?pretty=true&q=*"; From 647cece4eb44840f80248976e141f48270a935c6 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 29 Jul 2017 18:59:49 +1000 Subject: [PATCH 113/127] Delete Cargo.toml --- examples/Cargo.toml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 examples/Cargo.toml diff --git a/examples/Cargo.toml b/examples/Cargo.toml deleted file mode 100644 index 08deee55e..000000000 --- a/examples/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[workspace] -members = [ - "basic", - "typed", - "bulk", -] \ No newline at end of file From 5d97d269da17c3526132f12a1936aa53403eacf1 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 29 Jul 2017 19:39:11 +1000 Subject: [PATCH 114/127] fix typed sample --- examples/Cargo.toml | 4 ++++ examples/typed/Cargo.toml | 1 - examples/typed/src/main.rs | 20 ++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 examples/Cargo.toml diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 000000000..59894e542 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +members = [ + "typed" +] \ No newline at end of file diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml index 0b7544215..00742dd6e 100644 --- a/examples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -6,7 +6,6 @@ authors = ["Ashley Mannix "] [dependencies] elastic_reqwest = { version = "*", path = "../../" } -reqwest = "~0.6" serde = "~1" serde_derive = "~1" serde_json = "~1" diff --git a/examples/typed/src/main.rs b/examples/typed/src/main.rs index 59b75be44..afa9cef18 100644 --- a/examples/typed/src/main.rs +++ b/examples/typed/src/main.rs @@ -10,7 +10,6 @@ extern crate serde; extern crate serde_json; -extern crate reqwest; #[macro_use] extern crate serde_derive; @@ -20,10 +19,9 @@ extern crate elastic_types_derive; extern crate elastic_reqwest; use std::net::Ipv4Addr; -use reqwest::Client; -use elastic_reqwest::{ElasticClient, ParseResponse, RequestParams}; +use elastic_reqwest::{SyncElasticClient, SyncFromResponse, RequestParams}; use elastic_reqwest::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; -use elastic_reqwest::res::{parse, CommandResponse, IndexResponse, SearchResponse, Hit}; +use elastic_reqwest::res::{parse, CommandResponse, IndexResponse, SearchResponse}; use elastic_types::prelude::*; mod data; @@ -51,14 +49,16 @@ fn main() { // Perform a search request and deserialise to `SearchResponse`. let res = query(&client, ¶ms); - println!("results: {}", res.hits.total); + println!("results: {}", res.hits().count()); for hit in res.hits() { println!("hit: {:?}", hit); } } -fn create_index(client: &Client, params: &RequestParams) { +fn create_index(client: &TClient, params: &RequestParams) + where TClient: SyncElasticClient +{ let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&Index::default()).unwrap()); // Create index @@ -88,7 +88,9 @@ fn get_data() -> Vec { }] } -fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { +fn index_datum(client: &TClient, params: &RequestParams, datum: &MyStruct) + where TClient: SyncElasticClient +{ let req = IndexRequest::for_index_ty_id(INDEX, MyStruct::name(), datum.id.to_string(), @@ -99,7 +101,9 @@ fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) { parse::().from_response(res).unwrap(); } -fn query(client: &Client, params: &RequestParams) -> SearchResponse { +fn query(client: &TClient, params: &RequestParams) -> SearchResponse + where TClient: SyncElasticClient +{ let req = SearchRequest::for_index_ty(INDEX, MyStruct::name(), json_lit!({ From a9d370dbc79cf13f1e1fee2ed13d995767273c3f Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 5 Aug 2017 20:16:18 +1000 Subject: [PATCH 115/127] update to latest reqwest --- src/async.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/async.rs b/src/async.rs index 65297cd9e..c335726df 100644 --- a/src/async.rs +++ b/src/async.rs @@ -149,10 +149,11 @@ pub trait AsyncFromResponse { } impl AsyncFromResponse for Parse { - fn from_response(self, response: Response) -> Box> { + fn from_response(self, mut response: Response) -> Box> { let status: u16 = response.status().into(); + let body = response.body(); - let body_future = io::read_to_end(response, Vec::new()) + let body_future = io::read_to_end(body, Vec::new()) .map_err(Into::into); let de_future = body_future From 14cc9917d44a60cc5ff0d63e6d2f81acc49dbcdf Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 9 Aug 2017 18:38:45 +1000 Subject: [PATCH 116/127] update to latest reqwest --- src/async.rs | 11 ++++------- src/lib.rs | 8 -------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/async.rs b/src/async.rs index c335726df..dbd3ea04b 100644 --- a/src/async.rs +++ b/src/async.rs @@ -5,9 +5,8 @@ use bytes::Bytes; use serde::de::DeserializeOwned; use serde_json::Value; use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; -use futures::{Future, IntoFuture}; +use futures::{Future, Stream, IntoFuture}; use tokio_core::reactor::Handle; -use tokio_io::io; use super::req::HttpRequest; use super::res::parsing::{Parse, IsOk}; @@ -151,14 +150,12 @@ pub trait AsyncFromResponse { impl AsyncFromResponse for Parse { fn from_response(self, mut response: Response) -> Box> { let status: u16 = response.status().into(); - let body = response.body(); - - let body_future = io::read_to_end(body, Vec::new()) + let body_future = response.body().concat2() .map_err(Into::into); let de_future = body_future - .and_then(move |(_, body)| { - self.from_slice(status, &body).map_err(Into::into) + .and_then(move |body| { + self.from_slice(status, body.as_ref()).map_err(Into::into) }); Box::new(de_future) diff --git a/src/lib.rs b/src/lib.rs index 1dc325a8a..7a9650532 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -254,7 +254,6 @@ pub mod res { pub use self::res::parse; -use std::io::Error as IoError; use std::sync::Arc; use std::collections::BTreeMap; use std::str; @@ -276,13 +275,6 @@ quick_error! { display("http error: {}", err) cause(err) } - /** An io error. */ - Io(err: IoError) { - from() - description("io error") - display("io error: {}", err) - cause(err) - } /** A response error. */ Response(err: ResponseError) { from() From 29fc4d05a3c38c756c8dfa8461eabf08e9a3f645 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 13 Aug 2017 19:20:14 +1000 Subject: [PATCH 117/127] fix warning --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e92a6ce5a..3c76899f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -295,7 +295,7 @@ impl RequestParams { /// These parameters are added as query parameters to request urls. pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { - let mut entry = self.url_params.get_mut(key).unwrap(); + let entry = self.url_params.get_mut(key).unwrap(); *entry = value.to_string(); } else { self.url_params.insert(key, value.to_string()); From 6aac9c5a97cac125caf48d4d45b080fe5e15f505 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 13 Aug 2017 19:32:56 +1000 Subject: [PATCH 118/127] cargo/0.8.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ba0b4f8d4..2047e417d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "elastic_reqwest" -version = "0.8.0" +version = "0.8.1" authors = ["Ashley Mannix ", "Stephan Buys "] license = "Apache-2.0" description = "A lightweight implementation of the Elasticsearch API based on reqwest." From a869ab9ddeb1d31dd3446b7342698674749ecad8 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 16 Aug 2017 09:49:16 +1000 Subject: [PATCH 119/127] hide headers details --- benches/mod.rs | 12 ++++++------ src/lib.rs | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/benches/mod.rs b/benches/mod.rs index 06512b656..5a44093a9 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -16,16 +16,16 @@ use elastic_reqwest::req::PingRequest; #[inline(always)] fn with_headers_1(params: RequestParams) -> RequestParams { - params.headers(|h| h.set(Referer::new("/People.html#tim"))) + params.header(Referer::new("/People.html#tim")) } #[inline(always)] fn with_headers_5(params: RequestParams) -> RequestParams { - params.headers(|h| h.set(Referer::new("/People.html#tim"))) - .headers(|h| h.set(Referer::new("/People.html#tim"))) - .headers(|h| h.set(Referer::new("/People.html#tim"))) - .headers(|h| h.set(Referer::new("/People.html#tim"))) - .headers(|h| h.set(Referer::new("/People.html#tim"))) + params.header(Referer::new("/People.html#tim")) + .header(Referer::new("/People.html#tim")) + .header(Referer::new("/People.html#tim")) + .header(Referer::new("/People.html#tim")) + .header(Referer::new("/People.html#tim")) } #[inline(always)] diff --git a/src/lib.rs b/src/lib.rs index 7a9650532..9d1764578 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -258,7 +258,7 @@ use std::sync::Arc; use std::collections::BTreeMap; use std::str; use reqwest::Error as ReqwestError; -use reqwest::header::{Headers, ContentType}; +use reqwest::header::{Header, Headers, ContentType}; use url::form_urlencoded::Serializer; use self::res::error::ResponseError; @@ -317,7 +317,7 @@ With custom headers: # use reqwest::header::Authorization; # fn main() { let params = RequestParams::default() - .headers(|h| h.set(Authorization("let me in".to_owned()))); + .header(Authorization("let me in".to_owned())); # } ``` @@ -382,13 +382,24 @@ impl RequestParams { self } + /** + Set a request header. + */ + pub fn header(self, header: H) -> Self + where H: Header + Clone + { + self.headers(move |h| h.set(header.clone())) + } + /** Set a header value on the params. Each call to `headers` will chain to the end of the last call. - This function allocates a new `Box` for each call, so it's recommended to just call it once and configure multiple headers, rather than calling it once per header. + This function allocates a new `Box` for each call. + + Once we can depend on `http` this might go away. */ - pub fn headers(mut self, headers_factory: F) -> Self + fn headers(mut self, headers_factory: F) -> Self where F: Fn(&mut Headers) + Send + Sync + 'static { if let Some(old_headers_factory) = self.headers_factory { From ad7c1bdebe1a46c37a2bce403ddb0671257eed21 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 21 Aug 2017 14:17:13 +1000 Subject: [PATCH 120/127] fix build for latest reqwest --- .gitignore | 1 + src/async.rs | 6 ++++-- src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 381a7d4f9..54b21b46a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ Cargo.lock # Visual Studio *.user *.suo +.vscode /target/ /obj/ diff --git a/src/async.rs b/src/async.rs index dbd3ea04b..db71b8d6e 100644 --- a/src/async.rs +++ b/src/async.rs @@ -1,10 +1,11 @@ /*! Asynchronous http client. */ +use std::mem; use std::ops::Deref; use bytes::Bytes; use serde::de::DeserializeOwned; use serde_json::Value; -use reqwest::unstable::async::{Client, RequestBuilder, Response, Body}; +use reqwest::unstable::async::{Client, Decoder, RequestBuilder, Response, Body}; use futures::{Future, Stream, IntoFuture}; use tokio_core::reactor::Handle; @@ -150,7 +151,8 @@ pub trait AsyncFromResponse { impl AsyncFromResponse for Parse { fn from_response(self, mut response: Response) -> Box> { let status: u16 = response.status().into(); - let body_future = response.body().concat2() + let body_future = mem::replace(response.body_mut(), Decoder::empty()) + .concat2() .map_err(Into::into); let de_future = body_future diff --git a/src/lib.rs b/src/lib.rs index 9d1764578..62f846b4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,7 +373,7 @@ impl RequestParams { pub fn url_param(mut self, key: &'static str, value: T) -> Self { if self.url_params.contains_key(key) { // This is safe because we know here that the key exists - let mut entry = self.url_params.get_mut(key).unwrap(); + let entry = self.url_params.get_mut(key).unwrap(); *entry = value.to_string(); } else { self.url_params.insert(key, value.to_string()); From 590f31f95cdceacca413c40daca2d048eebb45fa Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Mon, 21 Aug 2017 17:22:48 +1000 Subject: [PATCH 121/127] add method to get base url --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7c0d9ad43..b77ecec9b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -375,9 +375,7 @@ impl RequestParams { self } - /** - Set a request header. - */ + /** Set a request header. */ pub fn header(self, header: H) -> Self where H: Header + Clone { @@ -409,6 +407,11 @@ impl RequestParams { self } + /** Get the base url. */ + pub fn get_base_url(&self) -> &str { + &self.base_url + } + /** Create a new `Headers` structure, and thread it through the configuration functions. */ pub fn get_headers(&self) -> Headers { let mut headers = Headers::new(); From 7e9fe8bcb4c38fcb624c52a5aa671ecfd9466471 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 22 Aug 2017 12:17:20 +1000 Subject: [PATCH 122/127] add non exhaustive variant to error --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b77ecec9b..7039d3a75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -282,6 +282,8 @@ quick_error! { display("response error: {}", err) cause(err) } + #[doc(hidden)] + __NonExhaustive } } From a01112e9ad378a3281e4dcaf95b4e46a06726dc3 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 22 Aug 2017 12:24:15 +1000 Subject: [PATCH 123/127] track master reqwest --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index efaaf4694..6c3bae00c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ nightly = [] serde = "~1" elastic_requests = "~0.4.1" elastic_responses = "~0.9.0" -reqwest = { version = "*", git = "https://github.com/KodrAus/reqwest.git", branch = "feat/async-decoder", features = ["unstable"] } +reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git", features = ["unstable"] } url = "~1" bytes = "*" tokio-core = "*" From 609e18be084fc65bc54796b0b79beda2573b70e9 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 29 Aug 2017 17:44:41 +1000 Subject: [PATCH 124/127] fix build warning and travis error --- .travis.yml | 27 +++------------------------ Cargo.toml | 1 - README.md | 1 - examples/typed/Cargo.toml | 2 -- examples/typed/src/main.rs | 12 +++++------- src/lib.rs | 1 - 6 files changed, 8 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index b0534a03f..4cf648aa3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,34 +1,13 @@ sudo: false language: rust -addons: - apt: - packages: - - libcurl4-openssl-dev - - libelf-dev - - libdw-dev - - binutils-dev # optional: only required for the --verify flag of coveralls rust: - nightly - stable -env: - global: - - TRAVIS_CARGO_NIGHTLY_FEATURE="" - -before_script: - - | - pip install 'travis-cargo<0.2' --user && - export PATH=$HOME/.local/bin:$PATH - script: - | - travis-cargo --only nightly test -- --features nightly && - travis-cargo test && - travis-cargo bench && + cargo test && + cargo bench && cd examples/typed && - travis-cargo --only nightly build && - cd ../../ && - travis-cargo --only stable doc -after_success: - - travis-cargo --only stable doc-upload \ No newline at end of file + cargo build diff --git a/Cargo.toml b/Cargo.toml index 6c3bae00c..4e56ff1f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ reqwest = { version = "*", git = "https://github.com/seanmonstar/reqwest.git", f url = "~1" bytes = "*" tokio-core = "*" -tokio-io = "*" futures = "*" serde_json = "~1" quick-error = "~1" diff --git a/README.md b/README.md index 260217836..20f2bc385 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Windows | Nightly | [![Build status](https://ci.appveyor.com/api/projects/statu Version | Docs ------------- | ------------- -`master` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://elastic-rs.github.io/elastic-reqwest/elastic_reqwest/) `current` | [![Documentation](https://img.shields.io/badge/docs-rustdoc-orange.svg)](https://docs.rs/elastic_reqwest/*/elastic_reqwest/) ## Alternatives diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml index 00742dd6e..ad06a8d74 100644 --- a/examples/typed/Cargo.toml +++ b/examples/typed/Cargo.toml @@ -11,5 +11,3 @@ serde_derive = "~1" serde_json = "~1" elastic_types = "~0.19" elastic_types_derive = "~0.19" - -json_str = { version = "*", features = ["nightly"]} diff --git a/examples/typed/src/main.rs b/examples/typed/src/main.rs index afa9cef18..43e8d699e 100644 --- a/examples/typed/src/main.rs +++ b/examples/typed/src/main.rs @@ -5,10 +5,8 @@ //! This sample executes a simple search request against some indexed data. //! The data is provided by a struct with mapping generated by `elastic_types`. -#![feature(plugin)] -#![plugin(json_str)] - extern crate serde; +#[macro_use] extern crate serde_json; #[macro_use] extern crate serde_derive; @@ -106,10 +104,10 @@ fn query(client: &TClient, params: &RequestParams) -> SearchResponse Date: Tue, 29 Aug 2017 17:49:41 +1000 Subject: [PATCH 125/127] remove typed sample --- .travis.yml | 4 +- examples/.gitignore | 2 - examples/Cargo.toml | 4 -- examples/typed/.gitignore | 2 - examples/typed/Cargo.toml | 13 ---- examples/typed/src/data.rs | 28 --------- examples/typed/src/main.rs | 118 ------------------------------------- src/lib.rs | 1 - 8 files changed, 1 insertion(+), 171 deletions(-) delete mode 100644 examples/.gitignore delete mode 100644 examples/Cargo.toml delete mode 100644 examples/typed/.gitignore delete mode 100644 examples/typed/Cargo.toml delete mode 100644 examples/typed/src/data.rs delete mode 100644 examples/typed/src/main.rs diff --git a/.travis.yml b/.travis.yml index 4cf648aa3..fad8f738f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,4 @@ rust: script: - | cargo test && - cargo bench && - cd examples/typed && - cargo build + cargo bench diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index ab22063e1..000000000 --- a/examples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/obj/ \ No newline at end of file diff --git a/examples/Cargo.toml b/examples/Cargo.toml deleted file mode 100644 index 59894e542..000000000 --- a/examples/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[workspace] -members = [ - "typed" -] \ No newline at end of file diff --git a/examples/typed/.gitignore b/examples/typed/.gitignore deleted file mode 100644 index ab22063e1..000000000 --- a/examples/typed/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target/ -/obj/ \ No newline at end of file diff --git a/examples/typed/Cargo.toml b/examples/typed/Cargo.toml deleted file mode 100644 index ad06a8d74..000000000 --- a/examples/typed/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "typed" -version = "0.1.0" -authors = ["Ashley Mannix "] - -[dependencies] -elastic_reqwest = { version = "*", path = "../../" } - -serde = "~1" -serde_derive = "~1" -serde_json = "~1" -elastic_types = "~0.19" -elastic_types_derive = "~0.19" diff --git a/examples/typed/src/data.rs b/examples/typed/src/data.rs deleted file mode 100644 index 246723cd5..000000000 --- a/examples/typed/src/data.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::net::Ipv4Addr; -use elastic_types::prelude::*; - -// The type we want to index in Elasticsearch -#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] -pub struct MyStruct { - pub id: i32, - pub title: String, - pub timestamp: Date, - pub geo: GeoLocation, -} - -#[derive(Clone, Debug, Serialize, Deserialize, ElasticType)] -pub struct GeoLocation { - pub ip: Ipv4Addr, - pub loc: GeoPoint, -} - -// An index request type with mappings bundled in -#[derive(Default, Serialize)] -pub struct Index { - mappings: Mappings, -} - -#[derive(Default, Serialize)] -struct Mappings { - mystruct: IndexDocumentMapping, -} diff --git a/examples/typed/src/main.rs b/examples/typed/src/main.rs deleted file mode 100644 index 43e8d699e..000000000 --- a/examples/typed/src/main.rs +++ /dev/null @@ -1,118 +0,0 @@ -//! Elasticsearch Hyper Client Samples -//! -//! This sample assumes you have a node running on `localhost`. -//! -//! This sample executes a simple search request against some indexed data. -//! The data is provided by a struct with mapping generated by `elastic_types`. - -extern crate serde; -#[macro_use] -extern crate serde_json; -#[macro_use] -extern crate serde_derive; - -extern crate elastic_types; -#[macro_use] -extern crate elastic_types_derive; -extern crate elastic_reqwest; - -use std::net::Ipv4Addr; -use elastic_reqwest::{SyncElasticClient, SyncFromResponse, RequestParams}; -use elastic_reqwest::req::{IndicesCreateRequest, IndexRequest, SearchRequest}; -use elastic_reqwest::res::{parse, CommandResponse, IndexResponse, SearchResponse}; -use elastic_types::prelude::*; - -mod data; -use data::*; - -const INDEX: &'static str = "testidx"; - -fn main() { - // Create a new client - let (client, params) = elastic_reqwest::sync::default().unwrap(); - - // Wait for refresh when indexing data. - // Normally this isn't a good idea, but is ok for this example. - let index_params = RequestParams::default().url_param("refresh", true); - - // Create an index and map our type - create_index(&client, ¶ms); - - // Index some objects. - // For lots of data, prefer the `BulkRequest` - for t in get_data() { - index_datum(&client, &index_params, &t); - } - - // Perform a search request and deserialise to `SearchResponse`. - let res = query(&client, ¶ms); - - println!("results: {}", res.hits().count()); - - for hit in res.hits() { - println!("hit: {:?}", hit); - } -} - -fn create_index(client: &TClient, params: &RequestParams) - where TClient: SyncElasticClient -{ - let req = IndicesCreateRequest::for_index(INDEX, serde_json::to_string(&Index::default()).unwrap()); - - // Create index - let res = client.elastic_req(¶ms, req).unwrap(); - - parse::().from_response(res).unwrap(); -} - -fn get_data() -> Vec { - vec![MyStruct { - id: 1, - title: String::from("Some Title"), - timestamp: Date::now(), - geo: GeoLocation { - ip: Ipv4Addr::new(10, 0, 0, 1), - loc: GeoPoint::build(-71.34, 41.12), - }, - }, - MyStruct { - id: 2, - title: String::from("Some Other Title"), - timestamp: Date::now(), - geo: GeoLocation { - ip: Ipv4Addr::new(10, 0, 0, 2), - loc: GeoPoint::build(-71.34, 41.12), - }, - }] -} - -fn index_datum(client: &TClient, params: &RequestParams, datum: &MyStruct) - where TClient: SyncElasticClient -{ - let req = IndexRequest::for_index_ty_id(INDEX, - MyStruct::name(), - datum.id.to_string(), - serde_json::to_string(&datum).unwrap()); - - let res = client.elastic_req(¶ms, req).unwrap(); - - parse::().from_response(res).unwrap(); -} - -fn query(client: &TClient, params: &RequestParams) -> SearchResponse - where TClient: SyncElasticClient -{ - let req = SearchRequest::for_index_ty(INDEX, - MyStruct::name(), - json!({ - "query": { - "query_string": { - "query": "*" - } - } - })); - - let res = client.elastic_req(¶ms, req).unwrap(); - - parse().from_response(res).unwrap() -} diff --git a/src/lib.rs b/src/lib.rs index 396da6626..8ee121ea8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,7 +103,6 @@ Execute a search request asynchronously and parse the response: extern crate serde_json; extern crate elastic_reqwest; extern crate tokio_core; -extern crate tokio_io; extern crate futures; use tokio_core::reactor::Core; From d9a6de24a087c02c35389604326bb129f19b8b50 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Tue, 29 Aug 2017 18:05:32 +1000 Subject: [PATCH 126/127] only run benches on nightly --- .travis.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index fad8f738f..115d292c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,16 @@ sudo: false language: rust -rust: - - nightly - - stable +matrix: + include: + - rust: stable + env: + - CHANNEL="stable" + - rust: nightly + env: + - CHANNEL="nightly" script: - | cargo test && - cargo bench + if [ "$CHANNEL" == "nightly" ]; then cargo bench; fi From 935802b85ed8e59ff952d5a3fa81ba4ce02b6be9 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 6 Oct 2017 17:24:35 +1000 Subject: [PATCH 127/127] Update .travis.yml --- .travis.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 115d292c2..02020c124 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,8 @@ sudo: false -language: rust - -matrix: - include: - - rust: stable - env: - - CHANNEL="stable" - - rust: nightly - env: - - CHANNEL="nightly" script: - | - cargo test && - if [ "$CHANNEL" == "nightly" ]; then cargo bench; fi + echo 'nothing to see here' + +notifications: + email: false