Skip to content
Elastic Search library for PhalconPHP Api's
Branch: master
Clone or download
Latest commit ef23eb8 Apr 25, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests Rewrite test using classes and individual data Mar 8, 2019
.env.example Add .env.example file Mar 6, 2019
.gitignore start elastic phalcon May 7, 2018
LICENSE Initial commit May 7, 2018
composer.json Add codeception codeception to the project Mar 6, 2019
scrutinizer.yml Fix typo in tests node Mar 8, 2019

Baka Phalcon Elastic Search

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

Table of Contents

  1. Indexing
    1. Create
    2. Insert
  2. Search
  3. Testing



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

Add elastic configuration to config.php


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

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

add queue to DI


$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;


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

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


class Users extends \Baka\Elasticsearch\Model



php cli/app.php IndexBuilder queue ModelName

Example: php cli/app.php IndexBuilder queue Users


In order to simply searching en elastic search with elastic you most install this extension

Now your search controller must use our trait


 * Search controller
class SearchController extends BaseController
    use \Baka\Elasticsearch\SearchTrait

And Follow the same query structure has Baka Http|asc&q=(is_deleted:0,relationship.type_id:1)&fields=id,first_name,last_name,,



codecept run
You can’t perform that action at this time.