\ElasticaIndex

Elastica index object.

Handles reads, deletes and configurations of an index

Summary

Methods
Properties
Constants
__construct()
getType()
getStats()
getMapping()
getSettings()
updateDocuments()
addDocuments()
deleteByQuery()
delete()
deleteDocuments()
optimize()
forcemerge()
refresh()
create()
exists()
createSearch()
search()
count()
open()
close()
getName()
getClient()
addAlias()
removeAlias()
getAliases()
hasAlias()
clearCache()
flush()
setSettings()
request()
analyze()
No public properties found
No constants found
No protected methods found
$_name
$_client
N/A
No private methods found
No private properties found
N/A

Properties

$_name

$_name : string

Index name.

Type

string — Index name

$_client

$_client : \Elastica\Client

Client object.

Type

\Elastica\Client — Client object

Methods

__construct()

__construct(\Elastica\Client  $client, string  $name) 

Creates a new index object.

All the communication to and from an index goes of this object

Parameters

\Elastica\Client $client

Client object

string $name

Index name

getType()

getType(string  $type) : \Elastica\Type

Returns a type object for the current index with the given name.

Parameters

string $type

Type name

Returns

\Elastica\Type

Type object

getMapping()

getMapping() : array

Gets all the type mappings for an index.

Returns

array

getSettings()

getSettings() : \Elastica\Index\Settings

Returns the index settings object.

Returns

\Elastica\Index\Settings

Settings object

updateDocuments()

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

Uses _bulk to send documents to the server.

Parameters

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

Array of Elastica\Document

Returns

\Elastica\Bulk\ResponseSet

addDocuments()

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

Uses _bulk to send documents to the server.

Parameters

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

Array of Elastica\Document

Returns

\Elastica\Bulk\ResponseSet

deleteByQuery()

deleteByQuery(\Elastica\Query|string|array  $query, array  $options = array()) : \Elastica\Response

Deletes entries in the db based on a query.

Parameters

\Elastica\Query|string|array $query

Query object or array

array $options

Optional params

Returns

\Elastica\Response

delete()

delete() : \Elastica\Response

Deletes the index.

Returns

\Elastica\Response

Response object

deleteDocuments()

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

Uses _bulk to delete documents from the server.

Parameters

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

Array of Elastica\Document

Returns

\Elastica\Bulk\ResponseSet

optimize()

optimize(array  $args = array()) : array

Optimizes search index.

Detailed arguments can be found here in the link

Parameters

array $args

OPTIONAL Additional arguments

Returns

array —

Server response

forcemerge()

forcemerge(array  $args = array()) : array

Force merges index.

Detailed arguments can be found here in the link

Parameters

array $args

OPTIONAL Additional arguments

Returns

array —

Server response

refresh()

refresh() : \Elastica\Response

Refreshes the index.

Returns

\Elastica\Response

Response object

create()

create(array  $args = array(), boolean|array  $options = null) : \Elastica\Response

Creates a new index with the given arguments.

Parameters

array $args

OPTIONAL Arguments to use

boolean|array $options

OPTIONAL bool=> Deletes index first if already exists (default = false). array => Associative array of options (option=>value)

Throws

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

Returns

\Elastica\Response

Server response

exists()

exists() : boolean

Checks if the given index is already created.

Returns

boolean —

True if index exists

search()

search(string|array|\Elastica\Query  $query = '', integer|array  $options = null) : \Elastica\ResultSet

Searches in this index.

{ "from" : 0, "size" : 10, "sort" : { "postDate" : {"order" : "desc"}, "user" : { }, "_score" : { } }, "query" : { "term" : { "user" : "kimchy" } } }

Parameters

string|array|\Elastica\Query $query

Array with all query data inside or a Elastica\Query object

integer|array $options

OPTIONAL Limit or associative array of options (option=>value)

Returns

\Elastica\ResultSet

with all results inside

count()

count(string|array|\Elastica\Query  $query = '') : integer

Counts results of query.

If no query is set, matchall query is created

Parameters

string|array|\Elastica\Query $query

Array with all query data inside or a Elastica\Query object

Returns

integer —

number of documents matching the query

open()

open() : \Elastica\Response

Opens an index.

Returns

\Elastica\Response

Response object

close()

close() : \Elastica\Response

Closes the index.

Returns

\Elastica\Response

Response object

getName()

getName() : string

Returns the index name.

Returns

string —

Index name

getClient()

getClient() : \Elastica\Client

Returns index client.

Returns

\Elastica\Client

Index client object

addAlias()

addAlias(string  $name, boolean  $replace = false) : \Elastica\Response

Adds an alias to the current index.

Parameters

string $name

Alias name

boolean $replace

OPTIONAL If set, an existing alias will be replaced

Returns

\Elastica\Response

Response

removeAlias()

removeAlias(string  $name) : \Elastica\Response

Removes an alias pointing to the current index.

Parameters

string $name

Alias name

Returns

\Elastica\Response

Response

getAliases()

getAliases() : array

Returns all index aliases.

Returns

array —

Aliases

hasAlias()

hasAlias(string  $name) : boolean

Checks if the index has the given alias.

Parameters

string $name

Alias name

Returns

boolean

clearCache()

clearCache() : \Elastica\Response

Clears the cache of an index.

Returns

\Elastica\Response

Response object

flush()

flush(array  $options = array()) : \Elastica\Response

Flushes the index to storage.

Parameters

array $options

Returns

\Elastica\Response

Response object

setSettings()

setSettings(array  $data) : \Elastica\Response

Can be used to change settings during runtime. One example is to use it for bulk updating.

Parameters

array $data

Data array

Returns

\Elastica\Response

Response object

request()

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

Makes calls to the elasticsearch server based on this index.

Parameters

string $path

Path to call

string $method

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

array|string $data

OPTIONAL Arguments as array or encoded string

array $query

OPTIONAL Query params

Returns

\Elastica\Response

Response object

analyze()

analyze(string  $text, array  $args = array()) : array

Analyzes a string.

Detailed arguments can be found here in the link

Parameters

string $text

String to be analyzed

array $args

OPTIONAL Additional arguments

Returns

array —

Server response