elastic_responses

Parses search results from Elasticsearch and presents results using convenient iterators

29 releases

0.21.0-pre.1 Feb 10, 2019
0.20.10 May 7, 2018
0.20.9 Feb 6, 2018
0.20.8 Dec 17, 2017
0.5.1 Mar 7, 2017

#65 in Database interfaces

Download history 323/week @ 2018-10-28 319/week @ 2018-11-04 472/week @ 2018-11-11 217/week @ 2018-11-18 347/week @ 2018-11-25 395/week @ 2018-12-02 230/week @ 2018-12-09 162/week @ 2018-12-16 119/week @ 2018-12-23 55/week @ 2018-12-30 203/week @ 2019-01-06 160/week @ 2019-01-13 37/week @ 2019-01-20 161/week @ 2019-01-27 102/week @ 2019-02-03

876 downloads per month
Used in 3 crates (1 directly)

MIT/Apache

70KB
1.5K SLoC

elastic_responses Latest Version

A crate to handle parsing and handling Elasticsearch search results which provides convenient iterators to step through the results returned.

Example

Cargo.toml

[dependencies]
elastic_reqwest = "*"
elastic_responses = "*" 

Search

Query your Elasticsearch Cluster, then iterate through the results:

// Send a request (omitted, see `samples/basic`, and read the response.
let mut res = client.elastic_req(&params, SearchRequest::for_index("_all", body)).unwrap();

// Parse body to JSON
let response = parse::<SearchResponse<Value>>().from_reader(res.status().to_u16(), res).unwrap();

// Use hits() or aggs() iterators
// Hits
for hit in response.hits() {
    println!("{:?}", hit);
}

// Agregations
for agg in response.aggs() {
    println!("{:?}", agg);
}

Bulk

Bulk response operations are split by whether they succeeded or failed:

// Send a request (omitted, see `samples/bulk`, and read the response.
let mut res = client.elastic_req(&params, BulkRequest::new(body)).unwrap();

// Parse body to JSON
let response = parse::<BulkResponse>().from_reader(res.status().to_u16(), res).unwrap();

for op in response.into_iter() {
    match op {
        Ok(ok) => {
            // Do something with successful operations
            println!("ok: {:?}", op);
        },
        Err(err) => {
            // Do something with failed operations
            println!("{:?}", op);
        }
    }
}

Dependencies

~1.5MB
~35K SLoC