Package org.elasticsearch
Class ElasticsearchException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- org.elasticsearch.ElasticsearchException
-
- All Implemented Interfaces:
java.io.Serializable,Writeable,ToXContent,ToXContentFragment
- Direct Known Subclasses:
AggregationExecutionException,AggregationInitializationException,AliasFilterParsingException,BlobStoreException,BroadcastShardOperationFailedException,CancellableThreads.ExecutionCancelledException,CircuitBreakingException,ClusterBlockException,DelayRecoveryException,Discovery.FailedToCommitClusterStateException,ElasticsearchGenerationException,ElasticsearchParseException,ElasticsearchStatusException,ElasticsearchTimeoutException,EngineException,FailedNodeException,GatewayException,GeneralScriptException,HttpException,IllegalIndexShardStateException,IncompatibleClusterStateVersionException,IndexClosedException,IndexCreationException,IndexPrimaryShardNotAllocatedException,IndexShardRecoveryException,IndexShardRestoreException,IndexShardSnapshotException,IndexTemplateMissingException,InvalidAggregationPathException,InvalidAliasNameException,InvalidIndexNameException,InvalidIndexTemplateException,MapperException,MasterNotDiscoveredException,NodeClosedException,NoNodeAvailableException,NoShardAvailableActionException,NotMasterException,NotSerializableExceptionWrapper,ParsingException,PrimaryMissingActionException,ProcessClusterEventTimeoutException,QueryShardException,RecoverFilesRecoveryException,RecoveryFailedException,ReplicationOperation.RetryOnPrimaryException,RepositoryException,ResourceAlreadyExistsException,ResourceNotFoundException,RoutingException,RoutingMissingException,ScriptException,SearchContextMissingException,SearchException,SearchPhaseExecutionException,SearchSourceBuilderException,SettingsException,ShardLockObtainFailedException,ShardStateAction.NoLongerPrimaryShardException,SnapshotException,SnapshotInProgressException,TaskCancelledException,TcpTransport.HttpOnTransportException,TimestampParsingException,TranslogCorruptedException,TranslogException,TransportException,TransportReplicationAction.RetryOnReplicaException,TypeMissingException,UnavailableShardsException,UncategorizedExecutionException
public class ElasticsearchException extends java.lang.RuntimeException implements 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
ToXContent.DelegatingMapParams, ToXContent.MapParams, 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.StringREST_EXCEPTION_SKIP_STACK_TRACEPassed in theToXContent.ParamsofgenerateThrowableXContent(XContentBuilder, Params, Throwable)to control if thestack_traceelement should render.static booleanREST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT-
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 aElasticsearchExceptionwith the specified detail message.ElasticsearchException(java.lang.String msg, java.lang.Throwable cause, java.lang.Object... args)Construct aElasticsearchExceptionwith the specified detail message and nested exception.ElasticsearchException(java.lang.Throwable cause)Construct aElasticsearchExceptionwith the specified cause exception.ElasticsearchException(StreamInput in)
-
Method Summary
Modifier and Type Method Description voidaddHeader(java.lang.String key, java.lang.String... value)Adds a new header with the given key.voidaddHeader(java.lang.String key, java.util.List<java.lang.String> value)Adds a new header with the given key.voidaddMetadata(java.lang.String key, java.lang.String... values)Adds a new piece of metadata with the given key.voidaddMetadata(java.lang.String key, java.util.List<java.lang.String> values)Adds a new piece of metadata with the given key.static ElasticsearchExceptionfailureFromXContent(XContentParser parser)Parses the output ofgenerateFailureXContent(XContentBuilder, Params, Exception, boolean)static ElasticsearchExceptionfromXContent(XContentParser parser)Generate aElasticsearchExceptionfrom aXContentParser.static voidgenerateFailureXContent(XContentBuilder builder, ToXContent.Params params, java.lang.Exception e, boolean detailed)Render any exception as a xcontent, encapsulated within a field or object named "error".static voidgenerateThrowableXContent(XContentBuilder builder, ToXContent.Params params, java.lang.Throwable t)Static toXContent helper method that rendersElasticsearchExceptionorThrowableinstances as XContent, delegating the rendering totoXContent(XContentBuilder, Params)orinnerToXContent(XContentBuilder, Params, Throwable, String, String, Map, Map, Throwable).java.lang.StringgetDetailedMessage()Return the detail message, including the message from the nested exception if there is one.protected java.lang.StringgetExceptionName()static java.lang.StringgetExceptionName(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 ornullif no header for the given key exists.java.util.Set<java.lang.String>getHeaderKeys()Returns a set of all header keys on this exceptionprotected java.util.Map<java.lang.String,java.util.List<java.lang.String>>getHeaders()static intgetId(java.lang.Class<? extends ElasticsearchException> exception)Returns the serialization id the given exception.IndexgetIndex()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 ornullif no metadata for the given key exists.java.util.Set<java.lang.String>getMetadataKeys()Returns a set of all metadata keys on this exceptionjava.util.List<java.lang.String>getResourceId()java.lang.StringgetResourceType()java.lang.ThrowablegetRootCause()Retrieve the innermost cause of this exception, if none, returns the current exception.ShardIdgetShardId()ElasticsearchException[]guessRootCauses()Returns the root cause of this exception or multiple if different shards caused different exceptionsstatic ElasticsearchException[]guessRootCauses(java.lang.Throwable t)Returns the root cause of this exception or multiple if different shards caused different exceptions.static ElasticsearchExceptioninnerFromXContent(XContentParser parser, boolean parseRootCauses)protected static voidinnerToXContent(XContentBuilder builder, 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 booleanisRegistered(java.lang.Class<? extends java.lang.Throwable> exception, Version version)Returnstrueiff the given class is a registered for an exception to be read.protected voidmetadataToXContent(XContentBuilder builder, ToXContent.Params params)Renders additional per exception information into the XContentstatic ElasticsearchExceptionreadException(StreamInput input, int id)static <T extends java.lang.Throwable>
TreadStackTrace(T throwable, StreamInput in)Deserializes stacktrace elements as well as suppressed exceptions from the given output stream and adds it to the given exception.voidsetIndex(java.lang.String index)voidsetIndex(Index index)voidsetResources(java.lang.String type, java.lang.String... id)voidsetShard(ShardId shardId)RestStatusstatus()Returns the rest status code associated with this exception.java.lang.StringtoString()XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)java.lang.ThrowableunwrapCause()Unwraps the actual cause from the exception for cases when the exception is aElasticsearchWrapperException.static <T extends java.lang.Throwable>
TwriteStackTraces(T throwable, StreamOutput out)Serializes the given exceptions stacktrace elements as well as it's suppressed exceptions to the given output stream.voidwriteTo(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 Detail
-
REST_EXCEPTION_SKIP_STACK_TRACE
public static final java.lang.String REST_EXCEPTION_SKIP_STACK_TRACE
Passed in theToXContent.ParamsofgenerateThrowableXContent(XContentBuilder, Params, Throwable)to control if thestack_traceelement should render. Unlike most parameters totoXContentmethods this parameter is internal only and not available as a URL parameter. Use theerror_traceparameter 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
-
-
Constructor Detail
-
ElasticsearchException
public ElasticsearchException(java.lang.Throwable cause)
Construct aElasticsearchExceptionwith the specified cause exception.
-
ElasticsearchException
public ElasticsearchException(java.lang.String msg, java.lang.Object... args)Construct aElasticsearchExceptionwith the specified detail message. The message can be parameterized using{}as placeholders for the given arguments- Parameters:
msg- the detail messageargs- the arguments for the message
-
ElasticsearchException
public ElasticsearchException(java.lang.String msg, java.lang.Throwable cause, java.lang.Object... args)Construct aElasticsearchExceptionwith the specified detail message and nested exception. The message can be parameterized using{}as placeholders for the given arguments- Parameters:
msg- the detail messagecause- the nested exceptionargs- the arguments for the message
-
ElasticsearchException
public ElasticsearchException(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
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 ornullif 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 ornullif 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 aElasticsearchWrapperException.- 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:WriteableWrite this into the StreamOutput.
-
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)Returnstrueiff 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 XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
java.io.IOException
-
innerToXContent
protected static void innerToXContent(XContentBuilder builder, 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(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
Renders additional per exception information into the XContent- Throws:
java.io.IOException
-
fromXContent
public static ElasticsearchException fromXContent(XContentParser parser) throws java.io.IOException
Generate aElasticsearchExceptionfrom aXContentParser. 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 ofElasticsearchExceptioninstances.- Throws:
java.io.IOException
-
innerFromXContent
public static ElasticsearchException innerFromXContent(XContentParser parser, boolean parseRootCauses) throws java.io.IOException
- Throws:
java.io.IOException
-
generateThrowableXContent
public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, java.lang.Throwable t) throws java.io.IOException
Static toXContent helper method that rendersElasticsearchExceptionorThrowableinstances as XContent, delegating the rendering totoXContent(XContentBuilder, Params)orinnerToXContent(XContentBuilder, Params, Throwable, String, String, Map, Map, Throwable). This method is usually used when theThrowableis rendered as a part of another XContent object, and its result can be parsed back using thefromXContent(XContentParser)method.- Throws:
java.io.IOException
-
generateFailureXContent
public static void generateFailureXContent(XContentBuilder builder, 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 theExceptionis rendered as a full XContent object, and its output can be parsed by thefailureFromXContent(XContentParser)method.- Throws:
java.io.IOException
-
failureFromXContent
public static ElasticsearchException failureFromXContent(XContentParser parser) throws java.io.IOException
Parses the output ofgenerateFailureXContent(XContentBuilder, Params, Exception, boolean)- 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 ofElasticsearchExceptionan 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 stripsElasticsearchprefixes from exception names.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Throwable
-
readStackTrace
public static <T extends java.lang.Throwable> T readStackTrace(T throwable, StreamInput in) throws java.io.IOExceptionDeserializes 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) throws java.io.IOExceptionSerializes 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()
-
-