Class ElasticsearchException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.elasticsearch.ElasticsearchException
All Implemented Interfaces:
java.io.Serializable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentFragment
Direct Known Subclasses:
AggregationExecutionException, AggregationInitializationException, AliasFilterParsingException, BlobStoreException, BroadcastShardOperationFailedException, CancellableThreads.ExecutionCancelledException, CircuitBreakingException, ClusterBlockException, CoordinationStateRejectedException, DelayRecoveryException, ElasticsearchGenerationException, ElasticsearchParseException, ElasticsearchStatusException, ElasticsearchTimeoutException, EngineException, FailedNodeException, FailedToCommitClusterStateException, GatewayException, GeneralScriptException, HttpException, IllegalIndexShardStateException, IncompatibleClusterStateVersionException, IndexClosedException, IndexCreationException, IndexPrimaryShardNotAllocatedException, IndexShardRecoveryException, IndexShardRestoreException, IndexShardSnapshotException, IndexTemplateMissingException, IngestProcessorException, InvalidAggregationPathException, InvalidAliasNameException, InvalidIndexNameException, InvalidIndexTemplateException, MapperException, MasterNotDiscoveredException, NodeClosedException, NodeHealthCheckFailureException, NoNodeAvailableException, NoSeedNodeLeftException, NoShardAvailableActionException, NotMasterException, NotSerializableExceptionWrapper, ParsingException, PrimaryMissingActionException, ProcessClusterEventTimeoutException, QueryShardException, RecoverFilesRecoveryException, RecoveryFailedException, ReplicationOperation.RetryOnPrimaryException, RepositoryException, ResourceAlreadyExistsException, ResourceNotFoundException, RetentionLeaseInvalidRetainingSeqNoException, RoutingException, RoutingMissingException, ScriptException, SearchContextMissingException, SearchException, SearchPhaseExecutionException, SearchSourceBuilderException, SettingsException, ShardLockObtainFailedException, ShardStateAction.NoLongerPrimaryShardException, SnapshotException, SnapshotInProgressException, TaskCancelledException, TcpTransport.HttpRequestOnTransportException, TimestampParsingException, TranslogCorruptedException, TranslogException, TransportException, TransportReplicationAction.RetryOnReplicaException, TypeMissingException, UnavailableShardsException, UncategorizedExecutionException, VersionMismatchException

public class ElasticsearchException
extends java.lang.RuntimeException
implements org.elasticsearch.common.xcontent.ToXContentFragment, Writeable
A base class for all elasticsearch exceptions.
See Also:
Serialized Form
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent

    org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params

    Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable

    Writeable.Reader<V>, Writeable.Writer<V>
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String REST_EXCEPTION_SKIP_STACK_TRACE
    Passed in the ToXContent.Params of generateThrowableXContent(XContentBuilder, Params, Throwable) to control if the stack_trace element should render.
    static boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT  
    static java.lang.String STACK_TRACE  

    Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent

    EMPTY_PARAMS
  • Constructor Summary

    Constructors
    Constructor Description
    ElasticsearchException​(java.lang.String msg, java.lang.Object... args)
    Construct a ElasticsearchException with the specified detail message.
    ElasticsearchException​(java.lang.String msg, java.lang.Throwable cause, java.lang.Object... args)
    Construct a ElasticsearchException with the specified detail message and nested exception.
    ElasticsearchException​(java.lang.Throwable cause)
    Construct a ElasticsearchException with the specified cause exception.
    ElasticsearchException​(StreamInput in)  
  • Method Summary

    Modifier and Type Method Description
    void addHeader​(java.lang.String key, java.lang.String... value)
    Adds a new header with the given key.
    void addHeader​(java.lang.String key, java.util.List<java.lang.String> value)
    Adds a new header with the given key.
    void addMetadata​(java.lang.String key, java.lang.String... values)
    Adds a new piece of metadata with the given key.
    void addMetadata​(java.lang.String key, java.util.List<java.lang.String> values)
    Adds a new piece of metadata with the given key.
    static ElasticsearchException failureFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser)
    static ElasticsearchException fromXContent​(org.elasticsearch.common.xcontent.XContentParser parser)
    Generate a ElasticsearchException from a XContentParser.
    static void generateFailureXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, java.lang.Exception e, boolean detailed)
    Render any exception as a xcontent, encapsulated within a field or object named "error".
    static void generateThrowableXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, java.lang.Throwable t)
    Static toXContent helper method that renders ElasticsearchException or Throwable instances as XContent, delegating the rendering to toXContent(XContentBuilder, Params) or innerToXContent(XContentBuilder, Params, Throwable, String, String, Map, Map, Throwable).
    java.lang.String getDetailedMessage()
    Return the detail message, including the message from the nested exception if there is one.
    protected java.lang.String getExceptionName()  
    static java.lang.String getExceptionName​(java.lang.Throwable ex)
    Returns a underscore case name for the given exception.
    java.util.List<java.lang.String> getHeader​(java.lang.String key)
    Returns the list of header values for the given key or null if no header for the given key exists.
    java.util.Set<java.lang.String> getHeaderKeys()
    Returns a set of all header keys on this exception
    protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaders()  
    static int getId​(java.lang.Class<? extends ElasticsearchException> exception)
    Returns the serialization id the given exception.
    Index getIndex()  
    protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMetadata()  
    java.util.List<java.lang.String> getMetadata​(java.lang.String key)
    Returns the list of metadata values for the given key or null if no metadata for the given key exists.
    java.util.Set<java.lang.String> getMetadataKeys()
    Returns a set of all metadata keys on this exception
    java.util.List<java.lang.String> getResourceId()  
    java.lang.String getResourceType()  
    java.lang.Throwable getRootCause()
    Retrieve the innermost cause of this exception, if none, returns the current exception.
    ShardId getShardId()  
    ElasticsearchException[] guessRootCauses()
    Returns the root cause of this exception or multiple if different shards caused different exceptions
    static ElasticsearchException[] guessRootCauses​(java.lang.Throwable t)
    Returns the root cause of this exception or multiple if different shards caused different exceptions.
    static ElasticsearchException innerFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser, boolean parseRootCauses)  
    protected static void innerToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, java.lang.Throwable throwable, java.lang.String type, java.lang.String message, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> metadata, java.lang.Throwable cause)  
    static boolean isRegistered​(java.lang.Class<? extends java.lang.Throwable> exception, Version version)
    Returns true iff the given class is a registered for an exception to be read.
    protected void metadataToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
    Renders additional per exception information into the XContent
    static ElasticsearchException readException​(StreamInput input, int id)  
    static <T extends java.lang.Throwable>
    T
    readStackTrace​(T throwable, StreamInput in)
    Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and adds it to the given exception.
    void setIndex​(java.lang.String index)  
    void setIndex​(Index index)  
    void setResources​(java.lang.String type, java.lang.String... id)  
    void setShard​(ShardId shardId)  
    RestStatus status()
    Returns the rest status code associated with this exception.
    java.lang.String toString()  
    org.elasticsearch.common.xcontent.XContentBuilder toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)  
    java.lang.Throwable unwrapCause()
    Unwraps the actual cause from the exception for cases when the exception is a ElasticsearchWrapperException.
    static <T extends java.lang.Throwable>
    T
    writeStackTraces​(T throwable, StreamOutput out, Writeable.Writer<java.lang.Throwable> exceptionWriter)
    Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.
    void writeTo​(StreamOutput out)
    Write this into the StreamOutput.

    Methods inherited from class java.lang.Throwable

    addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment

    isFragment
  • Field Details

    • REST_EXCEPTION_SKIP_STACK_TRACE

      public static final java.lang.String REST_EXCEPTION_SKIP_STACK_TRACE
      Passed in the ToXContent.Params of generateThrowableXContent(XContentBuilder, Params, Throwable) to control if the stack_trace element should render. Unlike most parameters to toXContent methods this parameter is internal only and not available as a URL parameter. Use the error_trace parameter instead.
      See Also:
      Constant Field Values
    • REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT

      public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT
      See Also:
      Constant Field Values
    • STACK_TRACE

      public static final java.lang.String STACK_TRACE
      See Also:
      Constant Field Values
  • Constructor Details

    • ElasticsearchException

      public ElasticsearchException​(java.lang.Throwable cause)
      Construct a ElasticsearchException with the specified cause exception.
    • ElasticsearchException

      public ElasticsearchException​(java.lang.String msg, java.lang.Object... args)
      Construct a ElasticsearchException with the specified detail message. The message can be parameterized using {} as placeholders for the given arguments
      Parameters:
      msg - the detail message
      args - the arguments for the message
    • ElasticsearchException

      public ElasticsearchException​(java.lang.String msg, java.lang.Throwable cause, java.lang.Object... args)
      Construct a ElasticsearchException with the specified detail message and nested exception. The message can be parameterized using {} as placeholders for the given arguments
      Parameters:
      msg - the detail message
      cause - the nested exception
      args - the arguments for the message
    • ElasticsearchException

      public ElasticsearchException​(StreamInput in) throws java.io.IOException
      Throws:
      java.io.IOException
  • Method Details

    • addMetadata

      public void addMetadata​(java.lang.String key, java.lang.String... values)
      Adds a new piece of metadata with the given key. If the provided key is already present, the corresponding metadata will be replaced
    • addMetadata

      public void addMetadata​(java.lang.String key, java.util.List<java.lang.String> values)
      Adds a new piece of metadata with the given key. If the provided key is already present, the corresponding metadata will be replaced
    • getMetadataKeys

      public java.util.Set<java.lang.String> getMetadataKeys()
      Returns a set of all metadata keys on this exception
    • getMetadata

      public java.util.List<java.lang.String> getMetadata​(java.lang.String key)
      Returns the list of metadata values for the given key or null if no metadata for the given key exists.
    • getMetadata

      protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getMetadata()
    • addHeader

      public void addHeader​(java.lang.String key, java.util.List<java.lang.String> value)
      Adds a new header with the given key. This method will replace existing header if a header with the same key already exists
    • addHeader

      public void addHeader​(java.lang.String key, java.lang.String... value)
      Adds a new header with the given key. This method will replace existing header if a header with the same key already exists
    • getHeaderKeys

      public java.util.Set<java.lang.String> getHeaderKeys()
      Returns a set of all header keys on this exception
    • getHeader

      public java.util.List<java.lang.String> getHeader​(java.lang.String key)
      Returns the list of header values for the given key or null if no header for the given key exists.
    • getHeaders

      protected java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaders()
    • status

      public RestStatus status()
      Returns the rest status code associated with this exception.
    • unwrapCause

      public java.lang.Throwable unwrapCause()
      Unwraps the actual cause from the exception for cases when the exception is a ElasticsearchWrapperException.
      See Also:
      ExceptionsHelper.unwrapCause(Throwable)
    • getDetailedMessage

      public java.lang.String getDetailedMessage()
      Return the detail message, including the message from the nested exception if there is one.
    • getRootCause

      public java.lang.Throwable getRootCause()
      Retrieve the innermost cause of this exception, if none, returns the current exception.
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      java.io.IOException
    • readException

      public static ElasticsearchException readException​(StreamInput input, int id) throws java.io.IOException
      Throws:
      java.io.IOException
    • isRegistered

      public static boolean isRegistered​(java.lang.Class<? extends java.lang.Throwable> exception, Version version)
      Returns true iff the given class is a registered for an exception to be read.
    • getId

      public static int getId​(java.lang.Class<? extends ElasticsearchException> exception)
      Returns the serialization id the given exception.
    • toXContent

      public org.elasticsearch.common.xcontent.XContentBuilder toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException
      Specified by:
      toXContent in interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
      java.io.IOException
    • innerToXContent

      protected static void innerToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, java.lang.Throwable throwable, java.lang.String type, java.lang.String message, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headers, java.util.Map<java.lang.String,​java.util.List<java.lang.String>> metadata, java.lang.Throwable cause) throws java.io.IOException
      Throws:
      java.io.IOException
    • metadataToXContent

      protected void metadataToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException
      Renders additional per exception information into the XContent
      Throws:
      java.io.IOException
    • fromXContent

      public static ElasticsearchException fromXContent​(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException
      Generate a ElasticsearchException from a XContentParser. This does not return the original exception type (ie NodeClosedException for example) but just wraps the type, the reason and the cause of the exception. It also recursively parses the tree structure of the cause, returning it as a tree structure of ElasticsearchException instances.
      Throws:
      java.io.IOException
    • innerFromXContent

      public static ElasticsearchException innerFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser, boolean parseRootCauses) throws java.io.IOException
      Throws:
      java.io.IOException
    • generateThrowableXContent

      public static void generateThrowableXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, java.lang.Throwable t) throws java.io.IOException
      Static toXContent helper method that renders ElasticsearchException or Throwable instances as XContent, delegating the rendering to toXContent(XContentBuilder, Params) or innerToXContent(XContentBuilder, Params, Throwable, String, String, Map, Map, Throwable). This method is usually used when the Throwable is rendered as a part of another XContent object, and its result can be parsed back using the fromXContent(XContentParser) method.
      Throws:
      java.io.IOException
    • generateFailureXContent

      public static void generateFailureXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params, @Nullable java.lang.Exception e, boolean detailed) throws java.io.IOException
      Render any exception as a xcontent, encapsulated within a field or object named "error". The level of details that are rendered depends on the value of the "detailed" parameter: when it's false only a simple message based on the type and message of the exception is rendered. When it's true all detail are provided including guesses root causes, cause and potentially stack trace. This method is usually used when the Exception is rendered as a full XContent object, and its output can be parsed by the failureFromXContent(XContentParser) method.
      Throws:
      java.io.IOException
    • failureFromXContent

      public static ElasticsearchException failureFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser) throws java.io.IOException
      Throws:
      java.io.IOException
    • guessRootCauses

      public ElasticsearchException[] guessRootCauses()
      Returns the root cause of this exception or multiple if different shards caused different exceptions
    • guessRootCauses

      public static ElasticsearchException[] guessRootCauses​(java.lang.Throwable t)
      Returns the root cause of this exception or multiple if different shards caused different exceptions. If the given exception is not an instance of ElasticsearchException an empty array is returned.
    • getExceptionName

      protected java.lang.String getExceptionName()
    • getExceptionName

      public static java.lang.String getExceptionName​(java.lang.Throwable ex)
      Returns a underscore case name for the given exception. This method strips Elasticsearch prefixes from exception names.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Throwable
    • readStackTrace

      public static <T extends java.lang.Throwable> T readStackTrace​(T throwable, StreamInput in) throws java.io.IOException
      Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and adds it to the given exception.
      Throws:
      java.io.IOException
    • writeStackTraces

      public static <T extends java.lang.Throwable> T writeStackTraces​(T throwable, StreamOutput out, Writeable.Writer<java.lang.Throwable> exceptionWriter) throws java.io.IOException
      Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.
      Throws:
      java.io.IOException
    • getIndex

      public Index getIndex()
    • getShardId

      public ShardId getShardId()
    • setIndex

      public void setIndex​(Index index)
    • setIndex

      public void setIndex​(java.lang.String index)
    • setShard

      public void setShard​(ShardId shardId)
    • setResources

      public void setResources​(java.lang.String type, java.lang.String... id)
    • getResourceId

      public java.util.List<java.lang.String> getResourceId()
    • getResourceType

      public java.lang.String getResourceType()