elastic_responses 0.7.2

Parses search results from Elasticsearch and presents results using convenient iterators.
Documentation

elastic_responses Latest Version

A crate to handle parsing and handling Elasticsearch search results which provides convenient iterators to step through the results returned. It is designed to work with elastic-reqwest.

Build Status

Platform Channel Status
Linux / OSX Stable / Nightly Build Status

Documentation

Version Docs
master Documentation
current Documentation

Usage

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 body_as_json: SearchResponse = res.json().unwrap();

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

// Agregations
for agg in body_as_json.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 body_as_json: BulkResponse = res.json().unwrap();

// Do something with successful operations
for op in body_as_json.items.ok {
    println!("{:?}", op);
}

// Do something with failed operations
for op in body_as_json.items.err {
    println!("{:?}", op);
}

License

Licensed under either of these: