PHP Class Elastica\Index

Handles reads, deletes and configurations of an index
Author: Nicolas Ruflin ([email protected])
Inheritance: implements elastica\SearchableInterface
Show file Open project: ruflin/elastica Class Usage Examples

Protected Properties

Property Type Description
$_client Client object.
$_name Index name.

Public Methods

Method Description
__construct ( Client $client, string $name ) Creates a new index object.
addAlias ( string $name, boolean $replace = false ) : Response Adds an alias to the current index.
addDocuments ( array $docs ) : ResponseSet Uses _bulk to send documents to the server.
analyze ( string $text, array $args = [] ) : array Analyzes a string.
clearCache ( ) : Response Clears the cache of an index.
close ( ) : Response Closes the index.
count ( string | array | Query $query = '' ) : integer Counts results of query.
create ( array $args = [], boolean | array $options = null ) : Response Creates a new index with the given arguments.
createSearch ( string | array | Query $query = '', integer | array $options = null, Elastica\ResultSet\BuilderInterface $builder = null ) : Search
delete ( ) : Response Deletes the index.
deleteByQuery ( Query | string | array $query, array $options = [] ) : Response Deletes entries in the db based on a query.
deleteDocuments ( array $docs ) : ResponseSet Uses _bulk to delete documents from the server.
exists ( ) : boolean Checks if the given index is already created.
flush ( $options = [] ) : Response Flushes the index to storage.
forcemerge ( array $args = [] ) : array Force merges index.
getAliases ( ) : array Returns all index aliases.
getClient ( ) : Client Returns index client.
getMapping ( ) : array Gets all the type mappings for an index.
getName ( ) : string Returns the index name.
getSettings ( ) : Settings Returns the index settings object.
getStats ( ) : Stats Return Index Stats.
getType ( string $type ) : Type Returns a type object for the current index with the given name.
hasAlias ( string $name ) : boolean Checks if the index has the given alias.
open ( ) : Response Opens an index.
optimize ( array $args = [] ) : array Optimizes search index.
refresh ( ) : Response Refreshes the index.
removeAlias ( string $name ) : Response Removes an alias pointing to the current index.
request ( string $path, string $method, array | string $data = [], array $query = [] ) : Response Makes calls to the elasticsearch server based on this index.
search ( string | array | Query $query = '', integer | array $options = null ) : ResultSet Searches in this index.
setSettings ( array $data ) : Response Can be used to change settings during runtime. One example is to use it for bulk updating.
updateDocuments ( array $docs ) : ResponseSet Uses _bulk to send documents to the server.

Method Details

__construct() public method

All the communication to and from an index goes of this object
public __construct ( Client $client, string $name )
$client Client Client object
$name string Index name

addAlias() public method

Adds an alias to the current index.
public addAlias ( string $name, boolean $replace = false ) : Response
$name string Alias name
$replace boolean OPTIONAL If set, an existing alias will be replaced
return Response Response

addDocuments() public method

Uses _bulk to send documents to the server.
public addDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet

analyze() public method

Detailed arguments can be found here in the link
public analyze ( string $text, array $args = [] ) : array
$text string String to be analyzed
$args array OPTIONAL Additional arguments
return array Server response

clearCache() public method

Clears the cache of an index.
public clearCache ( ) : Response
return Response Response object

close() public method

Closes the index.
public close ( ) : Response
return Response Response object

count() public method

Counts results of query.
See also: Elastica\SearchableInterface::count
public count ( string | array | Query $query = '' ) : integer
$query string | array | Query Array with all query data inside or a Elastica\Query object
return integer number of documents matching the query

create() public method

Creates a new index with the given arguments.
public create ( array $args = [], boolean | array $options = null ) : Response
$args array OPTIONAL Arguments to use
$options boolean | array OPTIONAL bool=> Deletes index first if already exists (default = false). array => Associative array of options (option=>value)
return Response Server response

createSearch() public method

public createSearch ( string | array | Query $query = '', integer | array $options = null, Elastica\ResultSet\BuilderInterface $builder = null ) : Search
$query string | array | Query
$options integer | array
$builder Elastica\ResultSet\BuilderInterface
return Search

delete() public method

Deletes the index.
public delete ( ) : Response
return Response Response object

deleteByQuery() public method

Deletes entries in the db based on a query.
public deleteByQuery ( Query | string | array $query, array $options = [] ) : Response
$query Query | string | array Query object or array
$options array Optional params
return Response

deleteDocuments() public method

Uses _bulk to delete documents from the server.
public deleteDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet

exists() public method

Checks if the given index is already created.
public exists ( ) : boolean
return boolean True if index exists

flush() public method

Flushes the index to storage.
public flush ( $options = [] ) : Response
return Response Response object

forcemerge() public method

Detailed arguments can be found here in the link
public forcemerge ( array $args = [] ) : array
$args array OPTIONAL Additional arguments
return array Server response

getAliases() public method

Returns all index aliases.
public getAliases ( ) : array
return array Aliases

getClient() public method

Returns index client.
public getClient ( ) : Client
return Client Index client object

getMapping() public method

Gets all the type mappings for an index.
public getMapping ( ) : array
return array

getName() public method

Returns the index name.
public getName ( ) : string
return string Index name

getSettings() public method

Returns the index settings object.
public getSettings ( ) : Settings
return Elastica\Index\Settings Settings object

getStats() public method

Return Index Stats.
public getStats ( ) : Stats
return Elastica\Index\Stats

getType() public method

Returns a type object for the current index with the given name.
public getType ( string $type ) : Type
$type string Type name
return Type Type object

hasAlias() public method

Checks if the index has the given alias.
public hasAlias ( string $name ) : boolean
$name string Alias name
return boolean

open() public method

Opens an index.
public open ( ) : Response
return Response Response object

optimize() public method

Detailed arguments can be found here in the link
public optimize ( array $args = [] ) : array
$args array OPTIONAL Additional arguments
return array Server response

refresh() public method

Refreshes the index.
public refresh ( ) : Response
return Response Response object

removeAlias() public method

Removes an alias pointing to the current index.
public removeAlias ( string $name ) : Response
$name string Alias name
return Response Response

request() public method

Makes calls to the elasticsearch server based on this index.
public request ( string $path, string $method, 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 encoded string
$query array OPTIONAL Query params
return Response Response object

setSettings() public method

Can be used to change settings during runtime. One example is to use it for bulk updating.
public setSettings ( array $data ) : Response
$data array Data array
return Response Response object

updateDocuments() public method

Uses _bulk to send documents to the server.
public updateDocuments ( array $docs ) : ResponseSet
$docs array Array of Elastica\Document
return Elastica\Bulk\ResponseSet

Property Details

$_client protected property

Client object.
protected $_client

$_name protected property

Index name.
protected $_name