Download the PHP package codemix/yiielasticsearch without Composer
On this page you can find all versions of the php package codemix/yiielasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yiielasticsearch
YiiElasticSearch
Elastic Search client for Yii.
Installation
Install via composer, requires php >= 5.3
Configuration
Add the following to your application config:
Also make sure, that you include the autoloader of composer. We recommend
to add this line to your index.php
and maybe also your yiic.php
:
Make sure to modify the path so that it matches the location of your vendor/
directory.
Usage
Index your ActiveRecords
Attach the YiiElasticSearch\SearchableBehavior
to any of your ActiveRecords to make it easy
to index and search your normal models with elasticsearch.
Now when MyModel instances are saved or deleted they will be automatically indexed or deleted in elasticsearch as appropriate.
Define an index for a record
By default your records will be stored in an index that uses your sanitized application name
(Yii::app()->name
). To change it you can define
or, if you need more control, create a method
Define a type for a record
By default the lower case class name will be used as type name in elasticsearch. If you want to change that you can define
or, again, if you need more control, create a method
Customize indexed data
By default all attributes are stored in the index. If you need to customize the data that should be indexed in elasticsearch, you can override these two methods.
Query records
You can specify queries using the YiiElasticSearch\Search
object. This object provides a simple
OO wrapper for the vanilla elasticsearch search API.
For example:
With a search you can either perform a 'raw' query, e.g.
This will return a result set that is a very simple wrapper around the raw elastic search response.
Alternatively, when combined with a SearchableBehavior
you can use data providers, e.g.
The data from $dataProvider->data
is a list of ActiveRecords, just like from an ordinary
CActiveDataProvider
. So you can use it in any list or grid view.
Raw requests
You can also use the connection component to send raw requests to elasticsearch.
Console Maintenance
The extension comes with two simple maintenance commands that can be helpful to find out
what's going on in your index. To configure them, add this to your console.php
configuration:
This will allow you to use yiic elastic
and yiic zerodowntimeelastic
on the console. Here are the commands help:
Console Command
This is the maintenance command for the elasticSearch component.
ZeroDowntime Command
This is a zero downtime maintenance command for the elasticSearch component. More details: https://www.elastic.co/blog/changing-mapping-with-zero-downtime