\Elastica\TypeAbstractType

Abstract helper class to implement search indices based on models.

This abstract model should help creating search index and a subtype with some easy config entries that are overloaded.

The following variables have to be set:

  • $_indexName
  • $_typeName

The following variables can be set for additional configuration

  • $_mapping: Value type mapping for the given type
  • $_indexParams: Parameters for the index

Summary

Methods
Properties
Constants
__construct()
create()
createSearch()
search()
count()
getIndex()
getType()
convertDate()
No public properties found
MAX_DOCS_PER_REQUEST
No protected methods found
$_indexName
$_typeName
$_client
$_index
$_type
$_mapping
$_indexParams
$_source
N/A
No private methods found
No private properties found
N/A

Constants

MAX_DOCS_PER_REQUEST

MAX_DOCS_PER_REQUEST

Properties

$_indexName

$_indexName : string

Index name.

Type

string — Index name

$_typeName

$_typeName : string

Index name.

Type

string — Index name

$_client

$_client : \Elastica\Client

Client.

Type

\Elastica\Client — Client object

$_index

$_index : \Elastica\Index

Index.

Type

\Elastica\Index — Index object

$_type

$_type : \Elastica\Type

Type.

Type

\Elastica\Type — Type object

$_mapping

$_mapping : array

Mapping.

Type

array — Mapping

$_indexParams

$_indexParams : array

Index params.

Type

array — Index params

$_source

$_source : boolean

Source.

Type

boolean — Source

Methods

__construct()

__construct(\Elastica\Client  $client = null) 

Creates index object with client connection.

Reads index and type name from protected vars _indexName and _typeName. Has to be set in child class

Parameters

\Elastica\Client $client

OPTIONAL Client object

Throws

\Elastica\Exception\InvalidException

create()

create(boolean  $recreate = false) 

Creates the index and sets the mapping for this type.

Parameters

boolean $recreate

OPTIONAL Recreates the index if true (default = false)

createSearch()

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

Parameters

string|\Elastica\Query $query
array|integer $options

Returns

\Elastica\Search

search()

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

Search on the type.

TODO: Improve sample code { "from" : 0, "size" : 10, "sort" : { "postDate" : {"reverse" : true}, "user" : { }, "_score" : { } }, "query" : { "term" : { "user" : "kimchy" } } }

Parameters

string|array|\Elastica\Query $query

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

null $options

Returns

\Elastica\ResultSet

with all results inside

count()

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

Count docs in the type based on 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 the search index.

Returns

\Elastica\Index

Index object

getType()

getType() : \Elastica\Type

Returns type object.

Returns

\Elastica\Type

Type object

convertDate()

convertDate(integer  $date) : string

Converts given time to format: 1995-12-31T23:59:59Z.

This is the lucene date format

Parameters

integer $date

Date input (could be string etc.) -> must be supported by strtotime

Returns

string —

Converted date string