Crate elastic_responses [−] [src]
Elasticsearch Response Iterators
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
.
This crate provides parsers that can be used to convert a http response into a concrete type or an API error.
Usage
This crate is on crates.io.
Add elastic_responses
to your Cargo.toml
:
[dependencies]
elastic_responses = "*"
Use the parse
function to deserialise a http response to a Result<T, ApiError>
for some
concrete response type T
.
Examples
Run a Query DSL query, then iterate through the results:
// Send a document get request and read as a response let (response_status, response_body) = do_request(); // Parse body to JSON as an elastic_responses::SearchResponse object // If the response is an API error then it'll be parsed into a friendly Rust error let body_as_json = parse::<SearchResponse>().from_slice(response_status, response_body).unwrap(); // Use hits() or aggs() iterators // Hits for i in body_as_json.hits() { println!("{:?}",i); } // Agregations for i in body_as_json.aggs() { println!("{:?}",i); }
Run a Get Document request, and handle cases where the document wasn't found or the index doesn't exist:
// Send a document get request and read as a response let (response_status, response_body) = do_request(); let get_response = parse::<GetResponseOf<Value>>().from_slice(response_status, response_body); match get_response { Ok(ref res) if res.found => { // The document was found } Ok(res) => { // The document was not found } Err(ResponseError::Api(ApiError::IndexNotFound { index })) => { // The index doesn't exist } _ => { // Some other error } }
Reexports
pub use self::parsing::parse; |
Modules
error |
Error types from Elasticsearch |
parsing |
Response type parsing. |
Structs
AggregationIterator |
Aggregator that traverses the results from Elasticsearch's Aggregations and returns a result row by row in a table-styled fashion. |
Aggregations |
Type Struct to hold a generic |
BulkErrorsResponse |
Response for a bulk request. |
BulkItem |
A successful bulk response item. |
BulkItemError |
A failed bulk response item. |
BulkItems |
Bulk items split by success or failure. |
BulkResponse |
Response for a bulk request. |
CommandResponse |
A standard command acknowledgement response. |
GetResponseOf |
Response for a get document request. |
Hit |
Full metadata and source for a single hit. |
Hits |
Struct to hold the search's Hits, serializable to type |
IndexResponse |
Response for an index document request. |
PingResponse |
Response for a cluster ping request. |
SearchResponseOf |
Response for a search request. |
Shards |
Returned hits metadata. |
Enums
BulkAction |
The bulk action being performed. |
Type Definitions
GetResponse | |
SearchResponse |