How to use elastic search in yii2

Elastic Search can be implemented in yii2 easily. You need to setup server and elastic search before to use.

After elastic search setup, you need to install the yii2 extension

https://github.com/yiisoft/yii2-elasticsearch/blob/master/docs/guide/README.md

Configure in common/main.php file

elasticsearch_logo-600x123

Creating index and mapping

Since it is not always possible to update ElasticSearch mappings incrementally, it is a good idea to create several static methods in your model that deal with index creation and updates. Here is one example of how this can be done.

By using above class, you can create index and mapping. Also you can add records in Book index.

Querying the data by yii\elasticsearch\Query

Adding aggregation in query

Adding filters in query

Adding sorting in results

Paging and render results

 

Comments