Skip to content

Commit

Permalink
Merge pull request #36 from elastic-rs/chore/update-sample
Browse files Browse the repository at this point in the history
Update typed sample
  • Loading branch information
KodrAus authored May 7, 2017
2 parents 1edf4b8 + 368fce0 commit a9c0ff2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 87 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.7.1"
authors = ["Ashley Mannix <[email protected]>", "Stephan Buys <[email protected]>"]
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]
Expand Down
7 changes: 4 additions & 3 deletions samples/typed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ authors = ["Ashley Mannix <[email protected]>"]
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"]}
4 changes: 2 additions & 2 deletions samples/typed/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub struct Index {

#[derive(Default, Serialize)]
struct Mappings {
mystruct: Document<MyStructMapping>
}
mystruct: Document<MyStructMapping>,
}
22 changes: 11 additions & 11 deletions samples/typed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ 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;
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";

Expand All @@ -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, &params);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -99,7 +96,7 @@ fn index_datum(client: &Client, params: &RequestParams, datum: &MyStruct) {
client.elastic_req(&params, req).unwrap();
}

fn query(client: &Client, params: &RequestParams) -> SearchResponse<MyStruct> {
fn query(client: &Client, params: &RequestParams) -> SearchResponseOf<Hit<MyStruct>> {
let req = SearchRequest::for_index_ty(INDEX,
MyStruct::name(),
json_lit!({
Expand All @@ -110,7 +107,10 @@ fn query(client: &Client, params: &RequestParams) -> SearchResponse<MyStruct> {
}
}));

let res = client.elastic_req(&params, req).unwrap();
let res = {
let res = client.elastic_req(&params, req).unwrap();
HttpResponse::from_read(res.status().to_u16(), res)
};

serde_json::de::from_reader(res).unwrap()
res.into_response().unwrap()
}
69 changes: 0 additions & 69 deletions samples/typed/src/response.rs

This file was deleted.

0 comments on commit a9c0ff2

Please sign in to comment.