PHP Class Elastica\Client

Author: Nicolas Ruflin ([email protected])
Datei anzeigen Open project: ruflin/elastica Class Usage Examples

Protected Properties

Property Type Description
$_callback callback
$_config array 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)
$_connectionPool Elastica\Connection\ConnectionPool
$_lastRequest Request | null
$_lastResponse Response | null
$_logger Psr\Log\LoggerInterface
$_version string

Public Methods

Method Description
__construct ( array $config = [], callback $callback = null, Psr\Log\LoggerInterface $logger = null ) Creates a new Elastica client.
addConnection ( Connection $connection )
addDocuments ( array $docs ) : ResponseSet Uses _bulk to send documents to the server.
addHeader ( string $header, string $headerValue ) Adds a HTTP Header.
bulk ( array $params ) : ResponseSet Bulk operation.
connect ( ) Establishes the client connections.
deleteDocuments ( array $docs ) : ResponseSet Bulk deletes documents.
deleteIds ( array $ids, string | Index $index, string | Type $type, string | boolean $routing = false ) : ResponseSet Deletes documents with the given ids, index, type from the index.
getCluster ( ) : Cluster Returns the current cluster.
getConfig ( string $key = '' ) : array | string Returns a specific config key or the whole config array if not set.
getConfigValue ( array | string $keys, mixed $default = null ) : mixed
getConnection ( ) : Connection
getConnectionStrategy ( ) : Elastica\Connection\Strategy\StrategyInterface
getConnections ( ) : Connection[]
getIndex ( string $name ) : Index Returns the index for the given connection.
getLastRequest ( ) : Request | null
getLastResponse ( ) : Response | null
getStatus ( ) : Status Returns the status object for all indices.
getVersion ( ) : string Get current version.
hasConnection ( ) : boolean Determines whether a valid connection is available for use.
optimizeAll ( array $args = [] ) : Response Optimizes all search indices.
refreshAll ( ) : Response Refreshes all search indices.
removeHeader ( string $header ) Remove a HTTP Header.
request ( string $path, string $method = Request::GET, array | string $data = [], array $query = [] ) : Response Makes calls to the elasticsearch server based on this index.
setConfig ( array $config ) Sets specific config values (updates and keeps default values).
setConfigValue ( string $key, mixed $value ) Sets / overwrites a specific config value.
setConnections ( array $connections )
setLogger ( Psr\Log\LoggerInterface $logger ) Replace the existing logger.
updateDocument ( integer | string $id, array | Elastica\Script\AbstractScript | Document $data, string $index, string $type, array $options = [] ) : Response Update document, using update script. Requires elasticsearch >= 0.19.0.
updateDocuments ( array $docs ) : ResponseSet Uses _bulk to send documents to the server.

Protected Methods

Method Description
_initConnections ( ) Inits the client connections.
_log ( mixed $context ) logging.
_populateDocumentFieldsFromResponse ( Response $response, Document $document, string $fields )
_prepareConnectionParams ( array $config ) : array Creates a Connection params array from a Client or server config array.

Method Details

__construct() public method

Creates a new Elastica client.
public __construct ( array $config = [], callback $callback = null, Psr\Log\LoggerInterface $logger = null )
$config array OPTIONAL Additional config options
$callback callback OPTIONAL Callback function which can be used to be notified about errors (for example connection down)
$logger Psr\Log\LoggerInterface

_initConnections() protected method

Inits the client connections.
protected _initConnections ( )

_log() protected method

logging.
Deprecation: Overwriting Client->_log is deprecated. Handle logging functionality by using a custom LoggerInterface.
protected _log ( mixed $context )
$context mixed

_populateDocumentFieldsFromResponse() protected method

protected _populateDocumentFieldsFromResponse ( Response $response, Document $document, string $fields )
$response Response
$document Document
$fields string Array of field names to be populated or '_source' if whole document data should be updated

_prepareConnectionParams() protected method

Creates a Connection params array from a Client or server config array.
protected _prepareConnectionParams ( array $config ) : array
$config array
return array

addConnection() public method

public addConnection ( Connection $connection )
$connection Connection

addDocuments() public method

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
public addDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet Response object

addHeader() public method

Adds a HTTP Header.
public addHeader ( string $header, string $headerValue )
$header string The HTTP Header
$headerValue string The HTTP Header Value

bulk() public method

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')) );
public bulk ( array $params ) : ResponseSet
$params array Parameter array
return Elastica\Bulk\ResponseSet Response object

connect() public method

Establishes the client connections.
public connect ( )

deleteDocuments() public method

Bulk deletes documents.
public deleteDocuments ( array $docs ) : ResponseSet
$docs array
return Elastica\Bulk\ResponseSet

deleteIds() public method

Deletes documents with the given ids, index, type from the index.
public deleteIds ( array $ids, string | Index $index, string | Type $type, string | boolean $routing = false ) : ResponseSet
$ids array Document ids
$index string | Index Index name
$type string | Type Type of documents
$routing string | boolean Optional routing key for all ids
return Elastica\Bulk\ResponseSet Response object

getCluster() public method

Returns the current cluster.
public getCluster ( ) : Cluster
return Cluster Cluster object

getConfig() public method

Returns a specific config key or the whole config array if not set.
public getConfig ( string $key = '' ) : array | string
$key string Config key
return array | string Config value

getConfigValue() public method

public getConfigValue ( array | string $keys, mixed $default = null ) : mixed
$keys array | string config key or path of config keys
$default mixed default value will be returned if key was not found
return mixed

getConnection() public method

public getConnection ( ) : Connection
return Connection

getConnectionStrategy() public method

public getConnectionStrategy ( ) : Elastica\Connection\Strategy\StrategyInterface
return Elastica\Connection\Strategy\StrategyInterface

getConnections() public method

public getConnections ( ) : Connection[]
return Connection[]

getIndex() public method

Returns the index for the given connection.
public getIndex ( string $name ) : Index
$name string Index name to create connection to
return Index Index for the given name

getLastRequest() public method

public getLastRequest ( ) : Request | null
return Request | null

getLastResponse() public method

public getLastResponse ( ) : Response | null
return Response | null

getStatus() public method

Returns the status object for all indices.
public getStatus ( ) : Status
return Status Status object

getVersion() public method

Get current version.
public getVersion ( ) : string
return string

hasConnection() public method

Determines whether a valid connection is available for use.
public hasConnection ( ) : boolean
return boolean

optimizeAll() public method

Optimizes all search indices.
public optimizeAll ( array $args = [] ) : Response
$args array OPTIONAL Optional arguments
return Response Response object

refreshAll() public method

Refreshes all search indices.
public refreshAll ( ) : Response
return Response Response object

removeHeader() public method

Remove a HTTP Header.
public removeHeader ( string $header )
$header string The HTTP Header to remove

request() public method

It's possible to make any REST query directly over this method
public request ( string $path, string $method = Request::GET, array | string $data = [], array $query = [] ) : Response
$path string Path to call
$method string Rest method to use (GET, POST, DELETE, PUT)
$data array | string OPTIONAL Arguments as array or pre-encoded string
$query array OPTIONAL Query params
return Response Response object

setConfig() public method

Sets specific config values (updates and keeps default values).
public setConfig ( array $config )
$config array Params

setConfigValue() public method

Sets / overwrites a specific config value.
public setConfigValue ( string $key, mixed $value )
$key string Key to set
$value mixed Value

setConnections() public method

public setConnections ( array $connections )
$connections array

setLogger() public method

Replace the existing logger.
public setLogger ( Psr\Log\LoggerInterface $logger )
$logger Psr\Log\LoggerInterface

updateDocument() public method

Update document, using update script. Requires elasticsearch >= 0.19.0.
public updateDocument ( integer | string $id, array | Elastica\Script\AbstractScript | Document $data, string $index, string $type, array $options = [] ) : Response
$id integer | string document id
$data array | Elastica\Script\AbstractScript | Document raw data for request body
$index string index to update
$type string type of index to update
$options array array of query params to use for query. For possible options check es api
return Response

updateDocuments() public method

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
public updateDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet Response object

Property Details

$_callback protected_oe property

protected callback $_callback
return callback

$_config protected_oe property

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)
protected array $_config
return array

$_connectionPool protected_oe property

protected ConnectionPool,Elastica\Connection $_connectionPool
return Elastica\Connection\ConnectionPool

$_lastRequest protected_oe property

protected Request,Elastica|null $_lastRequest
return Request | null

$_lastResponse protected_oe property

protected Response,Elastica|null $_lastResponse
return Response | null

$_logger protected_oe property

protected LoggerInterface,Psr\Log $_logger
return Psr\Log\LoggerInterface

$_version protected_oe property

protected string $_version
return string