PHPackages                             baka/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. baka/elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

baka/elasticsearch
==================

Baka Elasticsearch component

v1.0(6y ago)52.2k1[3 issues](https://github.com/bakaphp/phalcon-elasticsearch/issues)[1 PRs](https://github.com/bakaphp/phalcon-elasticsearch/pulls)1MITPHPPHP &gt;=7.2

Since Nov 26Pushed 6y ago5 watchersCompare

[ Source](https://github.com/bakaphp/phalcon-elasticsearch)[ Packagist](https://packagist.org/packages/baka/elasticsearch)[ RSS](/packages/baka-elasticsearch/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)Dependencies (9)Versions (13)Used By (1)

Baka Phalcon Elastic Search
===========================

[](#baka-phalcon-elastic-search)

Phalcon Elastic Search package to index / query model with relationship easily

Table of Contents
-----------------

[](#table-of-contents)

1. [Indexing](#indexing)
    1. [Create](#indexing-create)
    2. [Insert](#indexing-insert)
2. [Search](#markdown-header-QueryParser)
3. [Testing](#markdown-header-QueryParser-Extended)

Installing
----------

[](#installing)

Packages:

- `"elasticsearch/elasticsearch": "~2.0@beta"`
- `"baka/database": "dev-master"`
- `"phalcon/incubator": "~3.0","`

Add elastic configuration to config.php

```
#config.php

'namespace' => [
    'controller' => 'Project\Controllers',
    'models' => 'Project\Models',
],

'elasticSearch' => [
    'hosts' => [getenv('ELASTIC_HOST')], //change to pass array
],
```

add queue to DI

```
#service.php

$di->set('queue', function () use ($config) {
    //Connect to the queue
    $queue = new Phalcon\Queue\Beanstalk\Extended([
        'host' => $config->beanstalk->host,
        'prefix' => $config->beanstalk->prefix,
    ]);

    return $queue;
});
```

Indexing
--------

[](#indexing)

To create a Index in Elastic search first you will need to configure a CLI project and extend it from `IndexTasksBuilder` , after doing that just run the following command

` php cli/app.php IndexBuilder createIndex ModelName 3`

Where `4` is the normal of levels you want the relationships to index for example

```
Level 1
 Class A
 - Relation BelongsTo Class B

 Level 2
 Class A
 - Relation BelongsTo Class B
 - - Class B
 - - - Relation HasMany Class C

Level 3
 Class A
 - Relation BelongsTo Class B
 - - Class B
 - - - Relation HasMany Class C
 - - - - Class C
 - - - - - Relation HasMany Class D

```

*We can ignore a relationship if we specify on the options `'elasticSearch' => false`*

I wont recommend going beyond 4 levels if it not neede, it will use a lot of space.

If you get a error related to `nestedLimit` , you can use a 4th param to specify the amount the index limit

` php cli/app.php IndexBuilder createIndex ModelName 3 100`

### Indexing Queue

[](#indexing-queue)

Now that you created a Index we need to index the data, for that your model will need to extend from `\Baka\Elasticsearch\Model` . After every update | save we will send the information to a queue where the process will insert or update the info in elastic

```
