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

setMapping()

setMapping(\Elastica\Mapping  $mapping, array  $query = array()) : \Elastica\Response

Sets the mappings for the current index.

Parameters

\Elastica\Mapping $mapping

MappingType object

array $query

querystring when put mapping (for example update_all_types)

Returns

\Elastica\Response

getMapping()

getMapping() : array

Gets all mappings for the current index.

Returns

array

getSettings()

getSettings() : \Elastica\Index\Settings

Returns the index settings object.

Returns

\Elastica\Index\Settings

Settings object

createDocument()

createDocument(string  $id = '', array|string  $data = array()) : \Elastica\Document

Parameters

string $id
array|string $data

Returns

\Elastica\Document

updateDocuments()

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

Uses _bulk to send documents to the server.

Parameters

array<mixed,\Elastica\Document> $docs

Array of Elastica\Document

array $options

Array of query params to use for query. For possible options check es api

Returns

\Elastica\Bulk\ResponseSet

updateByQuery()

updateByQuery(\Elastica\Query|string|array  $query, \Elastica\Script\AbstractScript  $script, array  $options = array()) : \Elastica\Response

Update entries in the db based on a query.

Parameters

\Elastica\Query|string|array $query

Query object or array

\Elastica\Script\AbstractScript $script

Script

array $options

Optional params

Returns

\Elastica\Response

addDocument()

addDocument(\Elastica\Document  $doc) : \Elastica\Response

Adds the given document to the search index.

Parameters

\Elastica\Document $doc

Document with data

Returns

\Elastica\Response

addDocuments()

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

Uses _bulk to send documents to the server.

Parameters

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

Array of Elastica\Document

array $options

Array of query params to use for query. For possible options check es api

Returns

\Elastica\Bulk\ResponseSet

getDocument()

getDocument(integer|string  $id, array  $options = array()) : \Elastica\Document

Get the document from search index.

Parameters

integer|string $id

Document id

array $options

options for the get request

Throws

\Elastica\Exception\ResponseException
\Elastica\Exception\NotFoundException

Returns

\Elastica\Document

deleteById()

deleteById(string  $id, array  $options = array()) : \Elastica\Response

Deletes a document by its unique identifier.

Parameters

string $id

Document id

array $options

Throws

\Elastica\Exception\NotFoundException

Returns

\Elastica\Response

Response object

deleteByQuery()

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

Deletes entries in the db based on a query.

Parameters

\Elastica\Query|\Elastica\Query\AbstractQuery|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

forcemerge()

forcemerge(array  $args = array()) : \Elastica\Response

Force merges index.

Detailed arguments can be found here in the link

Parameters

array $args

OPTIONAL Additional arguments

Returns

\Elastica\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

createSearch()

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

Parameters

string|array|\Elastica\Query $query
integer|array $options
\Elastica\ResultSet\BuilderInterface $builder

Returns

\Elastica\Search

search()

search(string|array|\Elastica\Query  $query = '', integer|array  $options = null, string  $method = \Elastica\Request::POST) : \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)

string $method

OPTIONAL Request method (use const's) (default = Request::POST)

Returns

\Elastica\ResultSet

with all results inside

count()

count(string|array|\Elastica\Query  $query = '', string  $method = \Elastica\Request::POST) : 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

string $method

OPTIONAL Request method (use const's) (default = Request::POST)

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

requestEndpoint()

requestEndpoint(\Elasticsearch\Endpoints\AbstractEndpoint  $endpoint) : \Elastica\Response

Makes calls to the elasticsearch server with usage official client Endpoint based on this index.

Parameters

\Elasticsearch\Endpoints\AbstractEndpoint $endpoint

Returns

\Elastica\Response

analyze()

analyze(array  $body, array  $args = array()) : array

Run the analysis on the index.

Parameters

array $body

request body for the _analyze API, see API documentation for the requried properties

array $args

OPTIONAL Additional arguments

Returns

array —

Server response

updateDocument()

updateDocument(\Elastica\Document|\Elastica\Script\AbstractScript  $data, array  $options = array()) : \Elastica\Response

Update document, using update script.

Parameters

\Elastica\Document|\Elastica\Script\AbstractScript $data

Document or Script with update data

array $options

array of query params to use for query

Throws

\Elastica\Exception\InvalidException

Returns

\Elastica\Response