PHP Class Elastica\Client

Author: Nicolas Ruflin ([email protected])
Afficher le fichier Open project: ruflin/elastica Class Usage Examples

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

Inits the client connections.
protected _initConnections ( )

_log() protected méthode

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

_populateDocumentFieldsFromResponse() protected méthode

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 méthode

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

addConnection() public méthode

public addConnection ( Connection $connection )
$connection Connection

addDocuments() public méthode

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
Résultat Elastica\Bulk\ResponseSet Response object

addHeader() public méthode

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

bulk() public méthode

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
Résultat Elastica\Bulk\ResponseSet Response object

connect() public méthode

Establishes the client connections.
public connect ( )

deleteDocuments() public méthode

Bulk deletes documents.
public deleteDocuments ( array $docs ) : ResponseSet
$docs array
Résultat Elastica\Bulk\ResponseSet

deleteIds() public méthode

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
Résultat Elastica\Bulk\ResponseSet Response object

getCluster() public méthode

Returns the current cluster.
public getCluster ( ) : Cluster
Résultat Cluster Cluster object

getConfig() public méthode

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

getConfigValue() public méthode

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
Résultat mixed

getConnection() public méthode

public getConnection ( ) : Connection
Résultat Connection

getConnectionStrategy() public méthode

public getConnectionStrategy ( ) : Elastica\Connection\Strategy\StrategyInterface
Résultat Elastica\Connection\Strategy\StrategyInterface

getConnections() public méthode

public getConnections ( ) : Connection[]
Résultat Connection[]

getIndex() public méthode

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

getLastRequest() public méthode

public getLastRequest ( ) : Request | null
Résultat Request | null

getLastResponse() public méthode

public getLastResponse ( ) : Response | null
Résultat Response | null

getStatus() public méthode

Returns the status object for all indices.
public getStatus ( ) : Status
Résultat Status Status object

getVersion() public méthode

Get current version.
public getVersion ( ) : string
Résultat string

hasConnection() public méthode

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

optimizeAll() public méthode

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

refreshAll() public méthode

Refreshes all search indices.
public refreshAll ( ) : Response
Résultat Response Response object

removeHeader() public méthode

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

request() public méthode

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
Résultat Response Response object

setConfig() public méthode

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

setConfigValue() public méthode

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

setConnections() public méthode

public setConnections ( array $connections )
$connections array

setLogger() public méthode

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

updateDocument() public méthode

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
Résultat Response

updateDocuments() public méthode

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
Résultat Elastica\Bulk\ResponseSet Response object

Property Details

$_callback protected_oe property

protected callback $_callback
Résultat 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
Résultat array

$_connectionPool protected_oe property

protected ConnectionPool,Elastica\Connection $_connectionPool
Résultat Elastica\Connection\ConnectionPool

$_lastRequest protected_oe property

protected Request,Elastica|null $_lastRequest
Résultat Request | null

$_lastResponse protected_oe property

protected Response,Elastica|null $_lastResponse
Résultat Response | null

$_logger protected_oe property

protected LoggerInterface,Psr\Log $_logger
Résultat Psr\Log\LoggerInterface

$_version protected_oe property

protected string $_version
Résultat string