# Class yii\elasticsearch\ActiveDataProvider

Inheritance | yii\elasticsearch\ActiveDataProvider » yii\data\ActiveDataProvider » yii\data\BaseDataProvider » yii\base\Component » yii\base\BaseObject
Implements | yii\base\Configurable, yii\data\DataProviderInterface
Available since version | 2.0.5
Source Code | https://github.com/yiisoft/yii2-elasticsearch/blob/master/ActiveDataProvider.php

ActiveDataProvider is an enhanced version of yii\data\ActiveDataProvider specific to the Elasticsearch.

It allows to fetch not only rows and total rows count, but full query results including aggregations and so on.

Note: this data provider fetches result models and total count using single Elasticsearch query, so results total count will be fetched after pagination limit applying, which eliminates ability to verify if requested page number actually exist. Data provider disables yii\data\Pagination::$validatePage automatically because of this.

## Public Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
$aggregations | array | All aggregations results. This property is read-only. | yii\elasticsearch\ActiveDataProvider
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component. This property is read-only. | yii\base\Component
$count | integer | The number of data models in the current page. This property is read-only. | yii\data\BaseDataProvider
$db | yii\db\Connection|array|string|null | The DB connection object or the application component ID of the DB connection. | yii\data\ActiveDataProvider
$id | string | An ID that uniquely identifies the data provider among all data providers. | yii\data\BaseDataProvider
$key | string|callable|null | The column that is used as the key of the data models. | yii\data\ActiveDataProvider
$keys | array | The list of key values corresponding to $models. Each data model in $models is uniquely identified by the corresponding key value in this array. | yii\data\BaseDataProvider
$models | array | The list of data models in the current page. | yii\data\BaseDataProvider
$pagination | yii\data\Pagination|false | The pagination object. If this is false, it means the pagination is disabled. Note that the type of this property differs in getter and setter. See getPagination() and setPagination() for details. | yii\data\BaseDataProvider
$query | yii\db\QueryInterface|null | The query that is used to fetch data models and $totalCount if it is not explicitly set. | yii\data\ActiveDataProvider
$queryResults | array | Full query results. | yii\elasticsearch\ActiveDataProvider
$sort | yii\data\Sort|boolean | The sorting object. If this is false, it means the sorting is disabled. Note that the type of this property differs in getter and setter. See getSort() and setSort() for details. | yii\data\BaseDataProvider
$suggestions | array | All suggestions results. This property is read-only. | yii\elasticsearch\ActiveDataProvider
$totalCount | integer | Total number of possible data models. | yii\data\BaseDataProvider

## Public Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
__call() | Calls the named method which is not a class method. | yii\base\Component
__clone() |  | yii\data\ActiveDataProvider
__construct() | Constructor. | yii\base\BaseObject
__get() | Returns the value of a component property. | yii\base\Component
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component
__set() | Sets the value of a component property. | yii\base\Component
__unset() | Sets a component property to be null. | yii\base\Component
attachBehavior() | Attaches a behavior to this component. | yii\base\Component
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component
className() | Returns the fully qualified name of this class. | yii\base\BaseObject
detachBehavior() | Detaches a behavior from the component. | yii\base\Component
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component
getAggregation() | Returns results of the specified aggregation. | yii\elasticsearch\ActiveDataProvider
getAggregations() |  | yii\elasticsearch\ActiveDataProvider
getBehavior() | Returns the named behavior object. | yii\base\Component
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component
getCount() | Returns the number of data models in the current page. | yii\data\BaseDataProvider
getKeys() | Returns the key values associated with the data models. | yii\data\BaseDataProvider
getModels() | Returns the data models in the current page. | yii\data\BaseDataProvider
getPagination() | Returns the pagination object used by this data provider. | yii\data\BaseDataProvider
getQueryResults() |  | yii\elasticsearch\ActiveDataProvider
getSort() | Returns the sorting object used by this data provider. | yii\data\BaseDataProvider
getSuggestion() | Returns results of the specified suggestion. | yii\elasticsearch\ActiveDataProvider
getSuggestions() |  | yii\elasticsearch\ActiveDataProvider
getTotalCount() | Returns the total number of data models. | yii\data\BaseDataProvider
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component
init() | Initializes the DB connection component. | yii\data\ActiveDataProvider
off() | Detaches an existing event handler from this component. | yii\base\Component
on() | Attaches an event handler to an event. | yii\base\Component
prepare() | Prepares the data models and keys. | yii\data\BaseDataProvider
refresh() | Refreshes the data provider. | yii\elasticsearch\ActiveDataProvider
setKeys() | Sets the key values associated with the data models. | yii\data\BaseDataProvider
setModels() | Sets the data models in the current page. | yii\data\BaseDataProvider
setPagination() | Sets the pagination for this data provider. | yii\data\BaseDataProvider
setQueryResults() |  | yii\elasticsearch\ActiveDataProvider
setSort() | Sets the sort definition for this data provider. | yii\data\ActiveDataProvider
setTotalCount() | Sets the total number of data models. | yii\data\BaseDataProvider
trigger() | Triggers an event. | yii\base\Component

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
prepareKeys() | Prepares the keys associated with the currently available data models. | yii\elasticsearch\ActiveDataProvider
prepareModels() | Prepares the data models that will be made available in the current page. | yii\elasticsearch\ActiveDataProvider
prepareTotalCount() | Returns a value indicating the total number of data models in this data provider. | yii\elasticsearch\ActiveDataProvider

## Property Details

$aggregations public property

All aggregations results. This property is read-only.

public array $aggregations = null
$queryResults public property

Full query results.

public array $queryResults = null
$suggestions public property

All suggestions results. This property is read-only.

public array $suggestions = null

## Method Details

getAggregation() public method

Returns results of the specified aggregation.

public array getAggregation ( $name )
$name | string | Aggregation name.
return | array | Aggregation results.
throws | yii\base\InvalidCallException | if query results do not contain the requested aggregation.

getAggregations() public method

public array getAggregations ( )
return | array | All aggregations results

getQueryResults() public method

public array getQueryResults ( )
return | array | Full query results

getSuggestion() public method

Returns results of the specified suggestion.

public array getSuggestion ( $name )
$name | string | Suggestion name.
return | array | Suggestion results.
throws | yii\base\InvalidCallException | if query results do not contain the requested suggestion.

getSuggestions() public method

public array getSuggestions ( )
return | array | All suggestions results

prepareKeys() protected method

Prepares the keys associated with the currently available data models.

protected array prepareKeys ( $models )
$models | array | The available data models
return | array | The keys

prepareModels() protected method

Prepares the data models that will be made available in the current page.

protected array prepareModels ( )
return | array | The available data models

prepareTotalCount() protected method

Returns a value indicating the total number of data models in this data provider.

protected integer prepareTotalCount ( )
return | integer | Total number of data models in this data provider.

refresh() public method

Refreshes the data provider.

After calling this method, if getModels(), getKeys() or getTotalCount() is called again, they will re-execute the query and return the latest data available.

public void refresh ( )

setQueryResults() public method

public void setQueryResults ( $results )
$results | array | Full query results