Skip to main content

SearchError

Enum SearchError 

Source
pub enum SearchError {
Show 13 variants IndexNotFound { index: String, }, IndexAlreadyExists { index: String, }, MapperParsing { kind: String, reason: String, }, VersionConflict { index: String, id: String, reason: String, }, Overloaded { kind: String, reason: String, }, Unauthorized { reason: String, }, Forbidden { reason: String, }, BadRequest { kind: String, reason: String, }, Unavailable { status: u16, reason: String, }, BulkPartialFailure { failed: usize, total: usize, first: String, }, Unexpected { status: u16, kind: String, reason: String, }, Transport(String), Malformed { context: String, message: String, },
}
Expand description

A failure from Elasticsearch or OpenSearch.

Variants§

§

IndexNotFound

The index does not exist.

Usually a typo or a missing bootstrap step rather than an outage, and worth telling apart from an empty result: searching a misspelled index and searching an index with nothing in it look identical from the caller’s side otherwise.

Fields

§index: String
§

IndexAlreadyExists

The index already exists, from a create that assumed it did not.

Ordinary in a startup path that creates its indices every boot, which is why crate::SearchClient::create_index_if_missing exists.

Fields

§index: String
§

MapperParsing

The document does not fit the mapping.

A string where the mapping says long, a field the index refuses under dynamic: strict, an unparseable date. Never retryable — the same bytes will be rejected the same way for as long as the mapping stands. The reason carries the underlying cause where the cluster gives one, because failed to parse field [price] without it names the field but not the problem.

Fields

§kind: String
§reason: String
§

VersionConflict

The document changed since it was read.

Optimistic concurrency working as intended: something else wrote this document first. Retrying the identical request cannot help, but reading the document again and reapplying the change usually can — which is why this is not folded into SearchError::is_retryable.

Fields

§index: String
§reason: String
§

Overloaded

The cluster refused the work to stay alive.

A circuit breaker tripping, a full search or write queue, an index blocked by a disk watermark. The request was not performed, so backing off and repeating it is safe and is usually the correct response.

Fields

§kind: String
§reason: String
§

Unauthorized

401 — no credentials, or credentials the cluster does not accept.

Fields

§reason: String
§

Forbidden

403 — authenticated, but not allowed to do this.

Separate from SearchError::Unauthorized because the fixes have nothing in common: one is a wrong password, the other a missing role.

Fields

§reason: String
§

BadRequest

A request the cluster could parse but not accept — a malformed query, an illegal argument, an unknown parameter.

Fields

§kind: String
§reason: String
§

Unavailable

The cluster is not answering: a gateway in front of it, a node restarting, a shard with no copy available.

Fields

§status: u16
§reason: String
§

BulkPartialFailure

Some documents in a _bulk request were not written.

The one failure the HTTP status will never tell you about: _bulk answers 200 whether every item succeeded or none did, and reports the per-item outcome in the body. This exists so that crate::BulkReport::ok_or_error can turn that into an error a ? notices, for the callers that would rather not inspect every item. Which items, and why, is in the report — the reasons differ per item, so retryability cannot be decided for the request as a whole.

Fields

§failed: usize
§total: usize
§first: String
§

Unexpected

Anything else the cluster answered.

Fields

§status: u16
§kind: String
§reason: String
§

Transport(String)

The request never reached the cluster.

§

Malformed

The cluster answered successfully with a shape this crate cannot read.

Distinct from every variant above, which are the cluster saying no. This one is a yes in a form we did not expect — a proxy rewriting the body, or a version whose response layout moved — and naming what was being parsed is the only thing that makes it diagnosable.

Fields

§context: String
§message: String

Implementations§

Source§

impl SearchError

Source

pub fn from_response(status: u16, context: &str, body: &str) -> SearchError

Build from a status code and whatever body came with it.

context names what was being attempted; it is used only where the body does not identify the resource itself, which is common for a document-level failure.

Source

pub fn is_retryable(&self) -> bool

Whether repeating the identical request could plausibly succeed.

The judgement callers most need and most often get wrong. A rejected write never happened, so repeating it after a pause is both safe and likely to work. A mapping error, a bad query and a permission failure will fail the same way for as long as nothing else changes, and retrying them only turns one clear log line into a hundred.

A version conflict is deliberately not retryable even though a later attempt may well succeed: the request that lost carries a stale document, and sending it again would overwrite the winner.

Source

pub fn is_conflict(&self) -> bool

Whether re-reading the document and reapplying the change could work.

Source

pub fn is_index_not_found(&self) -> bool

Source

pub fn is_auth_failure(&self) -> bool

Whether the failure is about credentials rather than the request.

Source

pub fn kind(&self) -> &str

The cluster’s own error.type, where it gave one.

Worth surfacing: Elasticsearch has hundreds of exception types and this crate names only the handful worth branching on, so a caller chasing an unusual failure still has the string the documentation indexes by.

Trait Implementations§

Source§

impl Clone for SearchError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SearchError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SearchError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SearchError

Source§

impl Error for SearchError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<SearchError> for Error

Source§

fn from(error: SearchError) -> Error

Converts to this type from the input type.
Source§

impl PartialEq for SearchError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SearchError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.