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] 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, -}