Skip to main content

ElasticsearchBackend

Elasticsearch Backend.

Attributes

AttributeTypeDescription
indexstring = celeryThe name of the Elasticsearch index where task results are stored.
doc_typestring = nullThe document type used for indexing and retrieving results within the Elasticsearch index.
schemestring = httpThe protocol used to connect to the Elasticsearch server, such as http or https.
hoststring = localhostThe hostname or IP address of the Elasticsearch server.
portinteger = 9200The network port on which the Elasticsearch server is listening.
usernamestring = nullThe username for authenticating with the Elasticsearch server via HTTP Basic Auth.
passwordstring = nullThe password for authenticating with the Elasticsearch server via HTTP Basic Auth.
es_retry_on_timeoutboolean = falseFlag indicating whether the client should retry requests that fail due to a timeout.
es_timeoutinteger = 10The maximum number of seconds to wait for a response from the Elasticsearch server before timing out.
es_max_retriesinteger = 3The maximum number of times the client will attempt to retry a failed request.

Constructor

Signature

def ElasticsearchBackend(
url: string = null,
*args: any = null,
**kwargs: any = null
) - > null

Parameters

NameTypeDescription
urlstring = nullThe URL used to connect to the Elasticsearch server, containing scheme, host, port, and credentials.
*argsany = nullVariable length argument list passed to the parent class constructor.
**kwargsany = nullArbitrary keyword arguments passed to the parent class constructor.

Methods


exception_safe_to_retry()

@classmethod
def exception_safe_to_retry(
exc: Exception
) - > boolean

Determines if a given exception is safe to retry based on Elasticsearch error codes and transport errors.

Parameters

NameTypeDescription
excExceptionThe exception instance caught during an Elasticsearch operation.

Returns

TypeDescription
booleanTrue if the exception is a transient or retryable error like a timeout or specific HTTP status codes (401, 409, 500, 502, 504), otherwise False.

get()

@classmethod
def get(
key: string
) - > any

Fetches the result associated with a specific key from the Elasticsearch index.

Parameters

NameTypeDescription
keystringThe unique identifier for the task result document.

Returns

TypeDescription
anyThe task result stored in the document's source, or None if the key is not found.

set()

@classmethod
def set(
key: string,
value: any
) - > null

Stores a value in the backend for the given key without specifying a specific task state.

Parameters

NameTypeDescription
keystringThe unique identifier for the data being stored.
valueanyThe data to be persisted in the Elasticsearch index.

Returns

TypeDescription
nullnull

encode()

@classmethod
def encode(
data: any
) - > any

Serializes task metadata, optionally encoding specific fields like 'result' and 'traceback' if full text saving is disabled.

Parameters

NameTypeDescription
dataanyThe task metadata or result object to be encoded for storage.

Returns

TypeDescription
anyThe encoded data, either as a serialized string or a dictionary with encoded sub-fields.

decode()

@classmethod
def decode(
payload: any
) - > any

Deserializes task metadata retrieved from the backend into Python objects.

Parameters

NameTypeDescription
payloadanyThe raw data or dictionary retrieved from Elasticsearch.

Returns

TypeDescription
anyThe decoded task metadata, including deserialized results and tracebacks.

mget()

@classmethod
def mget(
keys: array
) - > array

Retrieves multiple task results simultaneously for a list of keys.

Parameters

NameTypeDescription
keysarrayA list of document IDs to fetch from the index.

Returns

TypeDescription
arrayA list of task results corresponding to the provided keys.

delete()

@classmethod
def delete(
key: string
) - > null

Removes a specific task result document from the Elasticsearch index.

Parameters

NameTypeDescription
keystringThe document ID to be deleted.

Returns

TypeDescription
nullnull

server()

@classmethod
def server() - > elasticsearch.Elasticsearch

Provides a cached Elasticsearch client instance, initializing the connection on the first access.

Returns

TypeDescription
elasticsearch.ElasticsearchThe active Elasticsearch client used for all backend operations.