\ElasticaType

Elastica type object.

elasticsearch has for every types as a substructure. This object represents a type inside a context The hierarchy is as following: client -> index -> type -> document

Summary

Methods
Properties
Constants
__construct()
addDocument()
addObject()
updateDocument()
updateDocuments()
addDocuments()
addObjects()
getDocument()
createDocument()
getName()
setMapping()
getMapping()
createSearch()
search()
count()
getIndex()
deleteDocument()
deleteDocuments()
deleteById()
deleteIds()
deleteByQuery()
request()
requestEndpoint()
setSerializer()
exists()
No public properties found
No constants found
No protected methods found
$_index
$_name
$_serializer
N/A
No private methods found
No private properties found
N/A

Properties

$_index

$_index : \Elastica\Index

Index.

Type

\Elastica\Index — Index object

$_name

$_name : string

Type name.

Type

string — Type name

$_serializer

$_serializer : array|string

Type

array|string — A callable that serializes an object passed to it

Methods

__construct()

__construct(\Elastica\Index  $index, string  $name) 

Creates a new type object inside the given index.

Parameters

\Elastica\Index $index

Index Object

string $name

Type name

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

addObject()

addObject(  $object, \Elastica\Document  $doc = null) : \Elastica\Response

Parameters

$object
\Elastica\Document $doc

Throws

\Elastica\Exception\RuntimeException

Returns

\Elastica\Response

updateDocument()

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

Update document, using update script. Requires elasticsearch >= 0.19.0.

Parameters

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

Document with update data

array $options

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

Throws

\Elastica\Exception\InvalidException

Returns

\Elastica\Response

updateDocuments()

updateDocuments(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

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

addObjects()

addObjects(array<mixed,object>  $objects, array  $options = array()) : \Elastica\Bulk\ResponseSet

Uses _bulk to send documents to the server.

Parameters

array<mixed,object> $objects
array $options

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

Returns

\Elastica\Bulk\ResponseSet

getDocument()

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

Get the document from search index.

Parameters

string $id

Document id

array $options

Options for the get request.

Throws

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

Returns

\Elastica\Document

createDocument()

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

Parameters

string $id
array|string $data

Returns

\Elastica\Document

getName()

getName() : string

Returns the type name.

Returns

string —

Type name

setMapping()

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

Sets value type mapping for this type.

Parameters

\Elastica\Type\Mapping|array $mapping

Elastica\Type\MappingType object or property array with all mappings

array $query

querystring when put mapping (for example update_all_types)

Returns

\Elastica\Response

getMapping()

getMapping() : array

Returns current mapping for the given type.

Returns

array —

Current mapping

createSearch()

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

Create search object.

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)

\Elastica\ResultSet\BuilderInterface $builder

Returns

\Elastica\Search

search()

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

Do a search on this type.

{ "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

Count docs by 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

getIndex()

getIndex() : \Elastica\Index

Returns index client.

Returns

\Elastica\Index

Index 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

deleteById()

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

Deletes an entry by its unique identifier.

Parameters

integer|string $id

Document id

array $options

Throws

\InvalidArgumentException
\Elastica\Exception\NotFoundException

Returns

\Elastica\Response

Response object

deleteIds()

deleteIds(array  $ids, string|boolean  $routing = false) : \Elastica\Response

Deletes the given list of ids from this type.

Parameters

array $ids
string|boolean $routing

Optional routing key for all ids

Returns

\Elastica\Response

Response object

deleteByQuery()

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

Deletes entries in the db based on a query.

Parameters

\Elastica\Query|string $query

Query object

array $options

Optional params

Returns

\Elastica\Response

request()

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

Makes calls to the elasticsearch server based on this type.

Parameters

string $path

Path to call

string $method

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

array $data

OPTIONAL Arguments as array

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 type.

Parameters

\Elasticsearch\Endpoints\AbstractEndpoint $endpoint

Returns

\Elastica\Response

setSerializer()

setSerializer(array|string  $serializer) : $this

Sets the serializer callable used in addObject.

Parameters

array|string $serializer

@see \Elastica\Type::_serializer

Returns

$this

exists()

exists() : boolean

Checks if the given type exists in Index.

Returns

boolean —

True if type exists