Struct elastic::client::responses::BulkResponse []

pub struct BulkResponse<TIndex = String, TType = String, TId = String> {
    pub took: u64,
    pub items: BulkItems<TIndex, TType, TId>,
    // some fields omitted
}

Response for a bulk request.

This type splits successful and failed bulk operations so it's easier to handle errors in bulk requests.

Examples

Send a bulk request and iterate through the results:

// Send a request (omitted, see `samples/bulk`), and read the response.
// Parse body to JSON as an elastic_responses::BulkResponse object
let body_as_json: BulkResponse = do_request();

// Do something with successful operations
for op in body_as_json.items.ok {
    match op.action {
        BulkAction::Create => {
            println!("created index: {}, type: {}, id: {}", 
                op.index, 
                op.ty, 
                op.id
            );
        },
        _ => ()
    }
}

// Do something with failed operations
for op in body_as_json.items.err {
    match op.action {
        BulkAction::Delete => (), // Ignore failed deletes
        _ => println!("bulk op failed: {:?}", op) 
    }
}

Optimising bulk responses

If you're only interested in bulk operations that failed, see BulkErrorsResponse. It can avoid allocating bulk operation responses that will never be processed.

Both the BulkResponse and BulkErrorsResponse types have generic parameters for the index, type and id fields. If your bulk operations have a small set of possible values for these fields you can avoid allocating Strings on the heap by using an alternative type, like an enum.

In the example below, we expect all bulk operations to use either a type called mytypea or mytypeb and an index called myindex:

#[derive(Deserialize)]
#[serde(rename_all = "lowercase")]
enum Index {
    MyIndex,
}
 
#[derive(Deserialize)]
#[serde(rename_all = "lowercase")]
enum Type {
    MyTypeA,
    MyTypeB,
}
 
let bulk: BulkResponse<Index, Type> = do_request();

Also see the string-cache crate as an alternative to using Strings and enums.

Fields

Methods

impl<TIndex, TType, TId> BulkResponse<TIndex, TType, TId>

Trait Implementations

impl<'de, TIndex, TType, TId> Deserialize<'de> for BulkResponse<TIndex, TType, TId> where
    TId: Deserialize<'de>,
    TIndex: Deserialize<'de>,
    TType: Deserialize<'de>, 

impl<TIndex, TType, TId> IsOk for BulkResponse<TIndex, TType, TId>

Inspect the http response to determine whether or not it succeeded.

impl<TIndex, TType, TId> Debug for BulkResponse<TIndex, TType, TId> where
    TId: Debug,
    TIndex: Debug,
    TType: Debug

Formats the value using the given formatter.

impl<TIndex, TType, TId> Clone for BulkResponse<TIndex, TType, TId> where
    TId: Clone,
    TIndex: Clone,
    TType: Clone