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 String
s 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 String
s and enum
s.
Fields
took: u64
items: BulkItems<TIndex, TType, TId>
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>,
TId: Deserialize<'de>,
TIndex: Deserialize<'de>,
TType: Deserialize<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<BulkResponse<TIndex, TType, TId>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
__deserializer: __D
) -> Result<BulkResponse<TIndex, TType, TId>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
impl<TIndex, TType, TId> IsOk for BulkResponse<TIndex, TType, TId>
fn is_ok<B>(
head: HttpResponseHead,
body: Unbuffered<B>
) -> Result<MaybeOkResponse<B>, ParseResponseError> where
B: ResponseBody,
head: HttpResponseHead,
body: Unbuffered<B>
) -> Result<MaybeOkResponse<B>, ParseResponseError> where
B: ResponseBody,
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,
TId: Debug,
TIndex: Debug,
TType: Debug,
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<TIndex, TType, TId> Clone for BulkResponse<TIndex, TType, TId> where
TId: Clone,
TIndex: Clone,
TType: Clone,
TId: Clone,
TIndex: Clone,
TType: Clone,