Properties

$_config

$_config : array

Config with defaults.

log: Set to true, to enable logging, set a string to log to a specific file retryOnConflict: Use in \Elastica\Client::updateDocument bigintConversion: Set to true to enable the JSON bigint to string conversion option (see issue #717)

Type

array

$_callback

$_callback : callback

Type

callback

$_logger

$_logger : \Psr\Log\LoggerInterface

Type

\Psr\Log\LoggerInterface

$_version

$_version : string

Type

string

Methods

__construct()

__construct(array  $config = array(), callback  $callback = null, \Psr\Log\LoggerInterface  $logger = null) 

Creates a new Elastica client.

Parameters

array $config

OPTIONAL Additional config options

callback $callback

OPTIONAL Callback function which can be used to be notified about errors (for example connection down)

\Psr\Log\LoggerInterface $logger

getVersion()

getVersion() : string

Get current version.

Returns

string

setConfig()

setConfig(array  $config) : $this

Sets specific config values (updates and keeps default values).

Parameters

array $config

Params

Returns

$this

getConfig()

getConfig(string  $key = '') : array|string

Returns a specific config key or the whole config array if not set.

Parameters

string $key

Config key

Throws

\Elastica\Exception\InvalidException

Returns

array|string —

Config value

setConfigValue()

setConfigValue(string  $key, mixed  $value) : $this

Sets / overwrites a specific config value.

Parameters

string $key

Key to set

mixed $value

Value

Returns

$this

getConfigValue()

getConfigValue(array|string  $keys, mixed  $default = null) : mixed

Parameters

array|string $keys

config key or path of config keys

mixed $default

default value will be returned if key was not found

Returns

mixed

getIndex()

getIndex(string  $name) : \Elastica\Index

Returns the index for the given connection.

Parameters

string $name

Index name to create connection to

Returns

\Elastica\Index

Index for the given name

addHeader()

addHeader(string  $header, string  $headerValue) : $this

Adds a HTTP Header.

Parameters

string $header

The HTTP Header

string $headerValue

The HTTP Header Value

Throws

\Elastica\Exception\InvalidException

If $header or $headerValue is not a string

Returns

$this

removeHeader()

removeHeader(string  $header) : $this

Remove a HTTP Header.

Parameters

string $header

The HTTP Header to remove

Throws

\Elastica\Exception\InvalidException

If $header is not a string

Returns

$this

updateDocuments()

updateDocuments(array|array<mixed,\Elastica\Document>  $docs) : \Elastica\Bulk\ResponseSet

Uses _bulk to send documents to the server.

Array of \Elastica\Document as input. Index and type has to be set inside the document, because for bulk settings documents, documents can belong to any type and index

Parameters

array|array<mixed,\Elastica\Document> $docs

Array of Elastica\Document

Throws

\Elastica\Exception\InvalidException

If docs is empty

Returns

\Elastica\Bulk\ResponseSet

Response object

addDocuments()

addDocuments(array|array<mixed,\Elastica\Document>  $docs) : \Elastica\Bulk\ResponseSet

Uses _bulk to send documents to the server.

Array of \Elastica\Document as input. Index and type has to be set inside the document, because for bulk settings documents, documents can belong to any type and index

Parameters

array|array<mixed,\Elastica\Document> $docs

Array of Elastica\Document

Throws

\Elastica\Exception\InvalidException

If docs is empty

Returns

\Elastica\Bulk\ResponseSet

Response object

updateDocument()

updateDocument(integer|string  $id, array|\Elastica\Script\AbstractScript|\Elastica\Document  $data, string  $index, string  $type, array  $options = array()) : \Elastica\Response

Update document, using update script. Requires elasticsearch >= 0.19.0.

Parameters

integer|string $id

document id

array|\Elastica\Script\AbstractScript|\Elastica\Document $data

raw data for request body

string $index

index to update

string $type

type of index to update

array $options

array of query params to use for query. For possible options check es api

Returns

\Elastica\Response

deleteDocuments()

deleteDocuments(array|array<mixed,\Elastica\Document>  $docs) : \Elastica\Bulk\ResponseSet

Bulk deletes documents.

Parameters

array|array<mixed,\Elastica\Document> $docs

Throws

\Elastica\Exception\InvalidException

Returns

\Elastica\Bulk\ResponseSet

getStatus()

getStatus() : \Elastica\Status

Returns the status object for all indices.

Returns

\Elastica\Status

Status object

getCluster()

getCluster() : \Elastica\Cluster

Returns the current cluster.

Returns

\Elastica\Cluster

Cluster object

connect()

connect() 

Establishes the client connections.

addConnection()

addConnection(\Elastica\Connection  $connection) : $this

Parameters

\Elastica\Connection $connection

Returns

$this

hasConnection()

hasConnection() : boolean

Determines whether a valid connection is available for use.

Returns

boolean

getConnection()

getConnection() : \Elastica\Connection

Throws

\Elastica\Exception\ClientException

Returns

\Elastica\Connection

getConnections()

getConnections() : array<mixed,\Elastica\Connection>

Returns

array<mixed,\Elastica\Connection>

setConnections()

setConnections(array|array<mixed,\Elastica\Connection>  $connections) : $this

Parameters

array|array<mixed,\Elastica\Connection> $connections

Returns

$this

deleteIds()

deleteIds(array  $ids, string|\Elastica\Index  $index, string|\Elastica\Type  $type, string|boolean  $routing = false) : \Elastica\Bulk\ResponseSet

Deletes documents with the given ids, index, type from the index.

Parameters

array $ids

Document ids

string|\Elastica\Index $index

Index name

string|\Elastica\Type $type

Type of documents

string|boolean $routing

Optional routing key for all ids

Throws

\Elastica\Exception\InvalidException

Returns

\Elastica\Bulk\ResponseSet

Response object

bulk()

bulk(array  $params) : \Elastica\Bulk\ResponseSet

Bulk operation.

Every entry in the params array has to exactly on array of the bulk operation. An example param array would be:

array( array('index' => array('_index' => 'test', '_type' => 'user', '_id' => '1')), array('user' => array('name' => 'hans')), array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2')) );

Parameters

array $params

Parameter array

Throws

\Elastica\Exception\ResponseException
\Elastica\Exception\InvalidException

Returns

\Elastica\Bulk\ResponseSet

Response object

request()

request(string  $path, string  $method = \Elastica\Request::GET, array|string  $data = array(), array  $query = array(), string  $contentType = \Elastica\Request::DEFAULT_CONTENT_TYPE) : \Elastica\Response

Makes calls to the elasticsearch server based on this index.

It's possible to make any REST query directly over this method

Parameters

string $path

Path to call

string $method

Rest method to use (GET, POST, DELETE, PUT)

array|string $data

OPTIONAL Arguments as array or pre-encoded string

array $query

OPTIONAL Query params

string $contentType

Content-Type sent with this request

Throws

\Elastica\Exception\ConnectionException|\Exception

Returns

\Elastica\Response

Response object

requestEndpoint()

requestEndpoint(\Elasticsearch\Endpoints\AbstractEndpoint  $endpoint) : \Elastica\Response

Makes calls to the elasticsearch server with usage official client Endpoint.

Parameters

\Elasticsearch\Endpoints\AbstractEndpoint $endpoint

Returns

\Elastica\Response

optimizeAll()

optimizeAll(array  $args = array()) : \Elastica\Response

Optimizes all search indices.

Parameters

array $args

OPTIONAL Optional arguments

Returns

\Elastica\Response

Response object

forcemergeAll()

forcemergeAll(array  $args = array()) : \Elastica\Response

Force merges all search indices.

Parameters

array $args

OPTIONAL Optional arguments

Returns

\Elastica\Response

Response object

refreshAll()

refreshAll() : \Elastica\Response

Refreshes all search indices.

Returns

\Elastica\Response

Response object

getLastRequest()

getLastRequest() : \Elastica\Request|null

Returns

\Elastica\Request|null

getLastResponse()

getLastResponse() : \Elastica\Response|null

Returns

\Elastica\Response|null

setLogger()

setLogger(\Psr\Log\LoggerInterface  $logger) : $this

Replace the existing logger.

Parameters

\Psr\Log\LoggerInterface $logger

Returns

$this

_initConnections()

_initConnections() 

Inits the client connections.

_prepareConnectionParams()

_prepareConnectionParams(array  $config) : array

Creates a Connection params array from a Client or server config array.

Parameters

array $config

Returns

array

_populateDocumentFieldsFromResponse()

_populateDocumentFieldsFromResponse(\Elastica\Response  $response, \Elastica\Document  $document, string  $fields) 

Parameters

\Elastica\Response $response
\Elastica\Document $document
string $fields

Array of field names to be populated or '_source' if whole document data should be updated

_log()

_log(mixed  $context) 

logging.

Parameters

mixed $context