PHP code example of cvreferral / phalcon-elasticsearch

1. Go to this page and download the library: Download cvreferral/phalcon-elasticsearch library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cvreferral / phalcon-elasticsearch example snippets


namespace Models;

use Ovr\Phalcon\Elastic\ModelTrait;

class Project extends Injectable
{
    use ModelTrait;
    
    protected static $index = 'phalconist';
    protected static $type = 'project';
    
    /**
     * @param int $limit
     * @return mixed
     */
    public static function myQuery($limit = 25)
    {
        $query = [
            'aggs' => [
                'types' => [
                    'terms' => [
                        'field' => 'composer.type',
                        'size' => $limit,
                    ],
                ]
            ]
        ];
        
        $resultSet = static::getStorage()->search($query);
        return static::toTags($resultSet->getAggregation('types')['buckets'], 'key', 'doc_count');
    }
}

$result = Project::myQuery(25);