PHP Класс Elastica\Client

Автор: Nicolas Ruflin ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
_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.

Описание методов

__construct() публичный Метод

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() защищенный Метод

Inits the client connections.
protected _initConnections ( )

_log() защищенный Метод

logging.
Устаревший: Overwriting Client->_log is deprecated. Handle logging functionality by using a custom LoggerInterface.
protected _log ( mixed $context )
$context mixed

_populateDocumentFieldsFromResponse() защищенный Метод

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() защищенный Метод

Creates a Connection params array from a Client or server config array.
protected _prepareConnectionParams ( array $config ) : array
$config array
Результат array

addConnection() публичный Метод

public addConnection ( Connection $connection )
$connection Connection

addDocuments() публичный Метод

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
Результат Elastica\Bulk\ResponseSet Response object

addHeader() публичный Метод

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

bulk() публичный Метод

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
Результат Elastica\Bulk\ResponseSet Response object

connect() публичный Метод

Establishes the client connections.
public connect ( )

deleteDocuments() публичный Метод

Bulk deletes documents.
public deleteDocuments ( array $docs ) : ResponseSet
$docs array
Результат Elastica\Bulk\ResponseSet

deleteIds() публичный Метод

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
Результат Elastica\Bulk\ResponseSet Response object

getCluster() публичный Метод

Returns the current cluster.
public getCluster ( ) : Cluster
Результат Cluster Cluster object

getConfig() публичный Метод

Returns a specific config key or the whole config array if not set.
public getConfig ( string $key = '' ) : array | string
$key string Config key
Результат array | string Config value

getConfigValue() публичный Метод

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
Результат mixed

getConnection() публичный Метод

public getConnection ( ) : Connection
Результат Connection

getConnectionStrategy() публичный Метод

public getConnectionStrategy ( ) : Elastica\Connection\Strategy\StrategyInterface
Результат Elastica\Connection\Strategy\StrategyInterface

getConnections() публичный Метод

public getConnections ( ) : Connection[]
Результат Connection[]

getIndex() публичный Метод

Returns the index for the given connection.
public getIndex ( string $name ) : Index
$name string Index name to create connection to
Результат Index Index for the given name

getLastRequest() публичный Метод

public getLastRequest ( ) : Request | null
Результат Request | null

getLastResponse() публичный Метод

public getLastResponse ( ) : Response | null
Результат Response | null

getStatus() публичный Метод

Returns the status object for all indices.
public getStatus ( ) : Status
Результат Status Status object

getVersion() публичный Метод

Get current version.
public getVersion ( ) : string
Результат string

hasConnection() публичный Метод

Determines whether a valid connection is available for use.
public hasConnection ( ) : boolean
Результат boolean

optimizeAll() публичный Метод

Optimizes all search indices.
public optimizeAll ( array $args = [] ) : Response
$args array OPTIONAL Optional arguments
Результат Response Response object

refreshAll() публичный Метод

Refreshes all search indices.
public refreshAll ( ) : Response
Результат Response Response object

removeHeader() публичный Метод

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

request() публичный Метод

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
Результат Response Response object

setConfig() публичный Метод

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

setConfigValue() публичный Метод

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

setConnections() публичный Метод

public setConnections ( array $connections )
$connections array

setLogger() публичный Метод

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

updateDocument() публичный Метод

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
Результат Response

updateDocuments() публичный Метод

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
Результат Elastica\Bulk\ResponseSet Response object

Описание свойств

$_callback защищенное свойство

protected callback $_callback
Результат callback

$_config защищенное свойство

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
Результат array

$_connectionPool защищенное свойство

protected ConnectionPool,Elastica\Connection $_connectionPool
Результат Elastica\Connection\ConnectionPool

$_lastRequest защищенное свойство

protected Request,Elastica|null $_lastRequest
Результат Request | null

$_lastResponse защищенное свойство

protected Response,Elastica|null $_lastResponse
Результат Response | null

$_logger защищенное свойство

protected LoggerInterface,Psr\Log $_logger
Результат Psr\Log\LoggerInterface

$_version защищенное свойство

protected string $_version
Результат string