PHPackages                             mirocow/yii2-elasticsearch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. mirocow/yii2-elasticsearch

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

mirocow/yii2-elasticsearch
==========================

Yii2 Elasticsearch client based on official Elasticsearch PHP library

1.0.22(6y ago)1322.9k↓40%72BSD-3-ClausePHPPHP &gt;=5.4.0

Since Sep 16Pushed 5y ago7 watchersCompare

[ Source](https://github.com/Mirocow/yii2-elasticsearch)[ Packagist](https://packagist.org/packages/mirocow/yii2-elasticsearch)[ RSS](/packages/mirocow-yii2-elasticsearch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (27)Used By (2)

Elasticsearch client for Yii2 framework based on official Elasticsearch PHP library
===================================================================================

[](#elasticsearch-client-for-yii2-framework-based-on-official-elasticsearch-php-library)

[![www.elasticsearch.com](https://github.com/Mirocow/yii2-elasticsearch/raw/master/documents/elasticsearch.png)](https://github.com/Mirocow/yii2-elasticsearch/blob/master/documents/elasticsearch.png)

[![Latest Stable Version](https://camo.githubusercontent.com/67dbac9c62a01b809cc5365519c7b3e018b092459c61c28b35323cede2fd5af9/68747470733a2f2f706f7365722e707567782e6f72672f6d69726f636f772f796969322d656c61737469637365617263682f762f737461626c65)](https://packagist.org/packages/mirocow/yii2-elasticsearch)[![Latest Unstable Version](https://camo.githubusercontent.com/37d8847914cb6d518cbf19830d0f3bd4672a28d23301bd1a864dac4d5cdfe988/68747470733a2f2f706f7365722e707567782e6f72672f6d69726f636f772f796969322d656c61737469637365617263682f762f756e737461626c65)](https://packagist.org/packages/mirocow/yii2-elasticsearch)[![Total Downloads](https://camo.githubusercontent.com/d44baba447daf18d33ca8c1565ef5bacb07bc15e2aa146547373e01e3817d1fb/68747470733a2f2f706f7365722e707567782e6f72672f6d69726f636f772f796969322d656c61737469637365617263682f646f776e6c6f616473)](https://packagist.org/packages/mirocow/yii2-elasticsearch) [![License](https://camo.githubusercontent.com/4f37793146ada9a247e158c5f7cdc4177d0da441ef44fd66e2cb341439cc3569/68747470733a2f2f706f7365722e707567782e6f72672f6d69726f636f772f796969322d656c61737469637365617263682f6c6963656e7365)](https://packagist.org/packages/mirocow/yii2-elasticsearch)[![Join the chat at https://gitter.im/Mirocow/yii2-elasticsearch](https://camo.githubusercontent.com/d6f61995525cf1720021995c8e88f009f790616df0f1926b9015ea9396a90e58/68747470733a2f2f6261646765732e6769747465722e696d2f4d69726f636f772f796969322d656c61737469637365617263682e737667)](https://gitter.im/Mirocow/yii2-elasticsearch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)[![FOSSA Status](https://camo.githubusercontent.com/b13a54cc389fac5c64b45ffe5e9614b6b8fdd2d5f888e9f8b67463e9eadbf238/68747470733a2f2f6170702e666f7373612e696f2f6170692f70726f6a656374732f6769742532426769746875622e636f6d2532464d69726f636f77253246796969322d656c61737469637365617263682e7376673f747970653d736869656c64)](https://app.fossa.io/projects/git%2Bgithub.com%2FMirocow%2Fyii2-elasticsearch?ref=badge_shield)[![Maintainability](https://camo.githubusercontent.com/0e0fc8f9d43d9e36e212521bc1bf75348e1987765ca651c43a3b71d981134375/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61373733303239616361333266343137623333332f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Mirocow/yii2-elasticsearch/maintainability)

Docs are available in english and [russian](README.ru.md). Based on

Honey modules
-------------

[](#honey-modules)

- [mirocow/yii2-elasticsearch-log](https://github.com/Mirocow/yii2-elasticsearch-log)
- [mirocow/yii2-elasticsearch-debug](https://github.com/Mirocow/yii2-elasticsearch-debug)

Install
-------

[](#install)

```
$ composer require --prefer-dist mirocow/yii2-elasticsearch
```

### Elasticsearch 5.6.x

[](#elasticsearch-56x)

```
$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
$ sudo apt-get install apt-transport-https
$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-5.x.list
$ sudo apt-get update && sudo apt-get install elasticsearch
$ composer require --prefer-dist mirocow/yii2-elasticsearch
```

Configure
---------

[](#configure)

- Create a class that implements the `common\modules\elasticsearch\contracts\Index` interface.
- Add it to the module configuration in `common/config/main.php`
- Start indexing

```
return [
    'modules' => [

        // elasticsearch
        common\modules\elasticsearch\Module::MODULE_NAME => [
          'class' => common\modules\elasticsearch\Module::class,
          'indexes' => [
            common\repositories\indexes\ProductsSearchIndex::class
          ]
        ],

    ],
    'bootstrap' => [
        mirocow\elasticsearch\Bootstrap::class,
    ]
];
```

Create index
------------

[](#create-index)

Create empty index

```
$ php yii elasticsearch/index/create index_name
```

Fill index with all documents

```
$ php yii elasticsearch/index/populate index_name
```

Destroy an index and all its data

```
$ php yii elasticsearch/index/destroy index_name
```

Remove all existing indexes, re-create all indexes and re-index all documents for all indexes

```
$ php yii elasticsearch/index/rebuild
```

Debug
-----

[](#debug)

```
$ export PHP_IDE_CONFIG="serverName=www.site.loc" && export XDEBUG_CONFIG="remote_host=192.168.1.6 idekey=xdebug" && php7.0 ./yii elasticsearch/index/create products_search
```

Query
-----

[](#query)

```
