Elasticsearch Query and ActiveRecord for Yii 2
This extension provides the Elasticsearch integration for the Yii framework 2.0.
It includes basic querying/search support and also implements the ActiveRecord pattern that allows you to store active
records in Elasticsearch.
For license information check the LICENSE-file.
Documentation is at docs/guide/README.md.
Requirements ¶
Depending on the version of Elasticsearch you are using you need a different version of this extension.
- For Elasticsearch 1.6.0 to 1.7.6 use extension version 2.0.x
- For Elasticsearch 5.x or above use extension version 2.1.x
Installation ¶
[!IMPORTANT]
- The minimum required PHP version is PHP
7.4.- It works best with PHP
8.
The preferred way to install this extension is through composer:
composer require --prefer-dist yiisoft/yii2-elasticsearch:"~2.1.0"
Configuration ¶
To use this extension, you have to configure the Connection class in your application configuration:
return [
//....
'components' => [
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'nodes' => [
['http_address' => '127.0.0.1:9200'],
// configure more hosts if you have a cluster
],
'dslVersion' => 7, // default is 5
],
]
];
Class Reference
| Class | Description |
|---|---|
| yii\ |
ActiveDataProvider is an enhanced version of yii\ |
| yii\ |
ActiveFixture represents a fixture for testing backed up by an ActiveRecord class or an elastic search index. |
| yii\ |
ActiveQuery represents a yii\ |
| yii\ |
ActiveRecord is the base class for classes representing relational data in terms of objects. |
| yii\ |
BatchQueryResult represents a batch query from which you can retrieve data in batches. |
| yii\ |
The yii\ |
| yii\ |
The Command class implements the API for accessing the Elasticsearch REST API. |
| yii\ |
Elasticsearch Connection is used to connect to an Elasticsearch cluster version 0.20 or higher |
| yii\ |
Debug Action is used by yii\ |
| yii\ |
Debugger panel that collects and displays Elasticsearch queries performed. |
| yii\ |
ElasticsearchTarget stores log messages in a Elasticsearch index. |
| yii\ |
Exception represents an exception that is caused by Elasticsearch-related operations. |
| yii\ |
Query represents a query to the search API of Elasticsearch. |
| yii\ |
QueryBuilder builds an Elasticsearch query based on the specification given as a yii\ |

