PHP Class Elastica\Type

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
Author: Nicolas Ruflin ([email protected])
Inheritance: implements elastica\SearchableInterface
Mostra file Open project: ruflin/elastica Class Usage Examples

Protected Properties

Property Type Description
$_index Index.
$_name Type name.
$_serializer A callable that serializes an object passed to it

Public Methods

Method Description
__construct ( Index $index, string $name ) Creates a new type object inside the given index.
addDocument ( Document $doc ) : Response Adds the given document to the search index.
addDocuments ( array $docs ) : ResponseSet Uses _bulk to send documents to the server.
addObject ( $object, Document $doc = null ) : Response
addObjects ( array $objects ) : ResponseSet Uses _bulk to send documents to the server.
count ( string | array | Query $query = '' ) : integer Count docs by query.
createDocument ( string $id = '', array | string $data = [] ) : Document
createSearch ( string | array | Query $query = '', integer | array $options = null, Elastica\ResultSet\BuilderInterface $builder = null ) : Search Create search object.
deleteById ( integer | string $id, array $options = [] ) : Response Deletes an entry by its unique identifier.
deleteByQuery ( Query | string $query, array $options = [] ) : Response Deletes entries in the db based on a query.
deleteDocument ( Document $document ) : Response
deleteDocuments ( array $docs ) : ResponseSet Uses _bulk to delete documents from the server.
deleteIds ( array $ids, string | boolean $routing = false ) : Response Deletes the given list of ids from this type.
exists ( ) : boolean Checks if the given type exists in Index.
getDocument ( string $id, array $options = [] ) : Document Get the document from search index.
getIndex ( ) : Index Returns index client.
getMapping ( ) : array Returns current mapping for the given type.
getName ( ) : string Returns the type name.
request ( string $path, string $method, array $data = [], array $query = [] ) : Response Makes calls to the elasticsearch server based on this type.
search ( string | array | Query $query = '', integer | array $options = null ) : ResultSet Do a search on this type.
setMapping ( Mapping | array $mapping ) : Response Sets value type mapping for this type.
setSerializer ( array | string $serializer ) Sets the serializer callable used in addObject.
updateDocument ( Document | Elastica\Script\AbstractScript $data, 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.

Method Details

__construct() public method

Creates a new type object inside the given index.
public __construct ( Index $index, string $name )
$index Index Index Object
$name string Type name

addDocument() public method

Adds the given document to the search index.
public addDocument ( Document $doc ) : Response
$doc Document Document with data
return 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

addObject() public method

public addObject ( $object, Document $doc = null ) : Response
$object
$doc Document
return Response

addObjects() public method

Uses _bulk to send documents to the server.
public addObjects ( array $objects ) : ResponseSet
$objects array
return Elastica\Bulk\ResponseSet

count() public method

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

createDocument() public method

public createDocument ( string $id = '', array | string $data = [] ) : Document
$id string
$data array | string
return Document

createSearch() public method

Create search object.
public createSearch ( string | array | Query $query = '', integer | array $options = null, Elastica\ResultSet\BuilderInterface $builder = null ) : Search
$query string | array | Query Array with all query data inside or a Elastica\Query object
$options integer | array OPTIONAL Limit or associative array of options (option=>value)
$builder Elastica\ResultSet\BuilderInterface
return Search

deleteById() public method

Deletes an entry by its unique identifier.
public deleteById ( integer | string $id, array $options = [] ) : Response
$id integer | string Document id
$options array
return Response Response object

deleteByQuery() public method

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

deleteDocument() public method

public deleteDocument ( Document $document ) : Response
$document Document
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

deleteIds() public method

Deletes the given list of ids from this type.
public deleteIds ( array $ids, string | boolean $routing = false ) : Response
$ids array
$routing string | boolean Optional routing key for all ids
return Response Response object

exists() public method

Checks if the given type exists in Index.
public exists ( ) : boolean
return boolean True if type exists

getDocument() public method

Get the document from search index.
public getDocument ( string $id, array $options = [] ) : Document
$id string Document id
$options array Options for the get request.
return Document

getIndex() public method

Returns index client.
public getIndex ( ) : Index
return Index Index object

getMapping() public method

Returns current mapping for the given type.
public getMapping ( ) : array
return array Current mapping

getName() public method

Returns the type name.
public getName ( ) : string
return string Type name

request() public method

Makes calls to the elasticsearch server based on this type.
public request ( string $path, string $method, array $data = [], array $query = [] ) : Response
$path string Path to call
$method string Rest method to use (GET, POST, DELETE, PUT)
$data array OPTIONAL Arguments as array
$query array OPTIONAL Query params
return Response Response object

setMapping() public method

Sets value type mapping for this type.
public setMapping ( Mapping | array $mapping ) : Response
$mapping Elastica\Type\Mapping | array Elastica\Type\MappingType object or property array with all mappings
return Response

setSerializer() public method

Sets the serializer callable used in addObject.
See also: Elastica\Type::addObject
public setSerializer ( array | string $serializer )
$serializer array | string @see \Elastica\Type::_serializer

updateDocument() public method

Update document, using update script. Requires elasticsearch >= 0.19.0.
public updateDocument ( Document | Elastica\Script\AbstractScript $data, array $options = [] ) : Response
$data Document | Elastica\Script\AbstractScript Document with update data
$options array array of query params to use for query. For possible options check es api
return Response

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

$_index protected_oe property

Index.
protected $_index

$_name protected_oe property

Type name.
protected $_name

$_serializer protected_oe property

A callable that serializes an object passed to it
protected $_serializer