PHPackages                             qlsgroup/elastic-search - 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. qlsgroup/elastic-search

ActiveCakephp-plugin[Search &amp; Filtering](/categories/search)

qlsgroup/elastic-search
=======================

An Elastic Search datasource and data mapper for CakePHP 3.0

3.4.4(3y ago)032.6k↓33.3%MIT

Since Jun 27Pushed 2y agoCompare

[ Source](https://github.com/qlsgroup/elastic-search)[ Packagist](https://packagist.org/packages/qlsgroup/elastic-search)[ Docs](https://github.com/cakephp/elastic-search)[ RSS](/packages/qlsgroup-elastic-search/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (33)Used By (0)

Elasticsearch Datasource for CakePHP
====================================

[](#elasticsearch-datasource-for-cakephp)

[![Build Status](https://camo.githubusercontent.com/f11f00044897925a6124d10a0a6645167363adb1eecdaa90a8dcb6e2a735b2ba/68747470733a2f2f7472617669732d63692e6f72672f63616b657068702f656c61737469632d7365617263682e7376673f6272616e63683d322e78)](https://travis-ci.org/cakephp/elastic-search)[![License](https://camo.githubusercontent.com/8c9c10a2eb75fb0a7bff16ab6a73ca7996846c21f21e3f5563a954f385fb64aa/68747470733a2f2f706f7365722e707567782e6f72672f63616b657068702f656c61737469632d7365617263682f6c6963656e73652e737667)](https://packagist.org/packages/cakephp/elastic-search)

Use [Elastic Search](https://www.elastic.co/) as an alternative ORM backend in CakePHP 3.6+.

You can [find the documentation for the plugin in the Cake Book](https://book.cakephp.org/elasticsearch).

Installing Elasticsearch via composer
-------------------------------------

[](#installing-elasticsearch-via-composer)

You can install Elasticsearch into your project using [composer](https://getcomposer.org). For existing applications you can add the following to your `composer.json` file:

```
"require": {
    "cakephp/elastic-search": "^2.0"
}

```

And run `php composer.phar update`

### Versions Table

[](#versions-table)

Cake\\ElasticSearchCakePHPElasticSearch[1.x](https://github.com/cakephp/elastic-search/tree/1.0)3.0 - 3.52.x - 5.x[2.x](https://github.com/cakephp/elastic-search/tree/2.x)3.6+6.x[3.x](https://github.com/cakephp/elastic-search/tree/master)4.0+6.xYou are seeing the 2.x version.

Connecting the Plugin to your Application
-----------------------------------------

[](#connecting-the-plugin-to-your-application)

After installing, you should tell your application to load the plugin:

```
use Cake\ElasticSearch\Plugin as ElasticSearchPlugin;

class Application extends BaseApplication
{
    public function bootstrap()
    {
        $this->addPlugin(ElasticSearchPlugin::class);

        // If you want to disable to automatically configure the Elastic model provider
        // and FormHelper do the following:
        // $this->addPlugin(ElasticSearchPlugin::class, [ 'bootstrap' => false ]);
    }
}
```

Defining a connection
---------------------

[](#defining-a-connection)

Before you can do any work with Elasticsearch models, you'll need to define a connection:

```
// in config/app.php
    'Datasources' => [
        // other datasources
        'elastic' => [
            'className' => 'Cake\ElasticSearch\Datasource\Connection',
            'driver' => 'Cake\ElasticSearch\Datasource\Connection',
            'host' => '127.0.0.1',
            'port' => 9200
        ],
    ]
```

As an alternative you could use a link format if you like to use enviroment variables for example.

```
// in config/app.php
    'Datasources' => [
        // other datasources
        'elastic' => [
            'url' => env('ELASTIC_URL', null)
        ]
    ]

    // and make sure the folowing env variable is available:
    // ELASTIC_URL="Cake\ElasticSearch\Datasource\Connection://127.0.0.1:9200?driver=Cake\ElasticSearch\Datasource\Connection"
```

You can enable request logging by setting the `log` config option to true. By default the `debug` Log profile will be used. You can also define an `elasticsearch` log profile in `Cake\Log\Log` to customize where Elasticsearch query logs will go. Query logging is done at a 'debug' level.

Getting a Index object
----------------------

[](#getting-a-index-object)

Index objects are the equivalent of `ORM\Table` instances in elastic search. You can use the `IndexRegistry` factory to get instances, much like `TableRegistry`:

```
use Cake\ElasticSearch\IndexRegistry;

$comments = IndexRegistry::get('Comments');
```

If you have loaded the plugin with bootstrap enabled you could load indexes using the model factory in your controllers

```
class SomeController extends AppController
{
    public function initialize()
    {
        $this->loadModel('Comments', 'Elastic');
    }

    public function index()
    {
        $comments = $this->Comments->find();
    }

    ...
```

Each `Index` object needs a correspondent Elasticsearch *index*, just like most of `ORM\Table` needs a database *table*.

In the above example, if you have defined a class as `CommentsIndex` and the `IndexRegistry` can find it, the `$comments` will receive a initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.

The Index class
---------------

[](#the-index-class)

You must create your own `Index` class so it will allow you to define the name of internal *index* for Elasticsearch, and it mapping type and define any entity properties you could need like virtual properties. As you have to [use only one mapping type for each *index*](https://www.elastic.co/guide/en/elasticsearch/reference/master/removal-of-types.html), you can use the same name for both (the default behavior when type is undefined is use singular version of index name). Index types were removed in ElasticSearch 7.

```
use Cake\ElasticSearch\Index;

class CommentsIndex extends Index
{
    /**
     * The name of index in Elasticsearch
     *
     * @return  string
     */
    public function getName()
    {
        return 'comments';
    }

    /**
     * The name of mapping type in Elasticsearch
     *
     * @return  string
     */
    public function getType()
    {
        return 'comments';
    }
}
```

Running tests
-------------

[](#running-tests)

**Warning**: Please, be very carefully when running tests as the Fixture will create and drop Elasticsearch indexes for its internal structure. Don't run tests in production or development machines where you have important data into your Elasticsearch instance.

Assuming you have PHPUnit installed system wide using one of the methods stated [here](https://phpunit.de/manual/current/en/installation.html), you can run the tests for CakePHP by doing the following:

1. Copy `phpunit.xml.dist` to `phpunit.xml`
2. Run `phpunit`

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~92 days

Recently: every ~128 days

Total

33

Last Release

1028d ago

Major Versions

1.0.0 → 2.0.0-beta2018-03-21

1.5.2 → 2.0.0-RC22018-06-29

2.0.0 → 3.0.02020-03-22

2.0.1 → 3.1.02020-05-09

2.0.2 → 3.3.02021-06-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/31ad81b0091a93d64f262ece24d83d56270b8a3a18c6735e08f8b0b0e376f197?d=identicon)[qls](/maintainers/qls)

---

Top Contributors

[![markstory](https://avatars.githubusercontent.com/u/24086?v=4)](https://github.com/markstory "markstory (156 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (149 commits)")[![josbeir](https://avatars.githubusercontent.com/u/26058?v=4)](https://github.com/josbeir "josbeir (37 commits)")[![bcrowe](https://avatars.githubusercontent.com/u/752603?v=4)](https://github.com/bcrowe "bcrowe (27 commits)")[![lilHermit](https://avatars.githubusercontent.com/u/299424?v=4)](https://github.com/lilHermit "lilHermit (15 commits)")[![gaetansnl](https://avatars.githubusercontent.com/u/8348807?v=4)](https://github.com/gaetansnl "gaetansnl (14 commits)")[![damianoporta](https://avatars.githubusercontent.com/u/7131996?v=4)](https://github.com/damianoporta "damianoporta (11 commits)")[![othercorey](https://avatars.githubusercontent.com/u/24221186?v=4)](https://github.com/othercorey "othercorey (6 commits)")[![jippi](https://avatars.githubusercontent.com/u/22841?v=4)](https://github.com/jippi "jippi (5 commits)")[![HavokInspiration](https://avatars.githubusercontent.com/u/5243386?v=4)](https://github.com/HavokInspiration "HavokInspiration (4 commits)")[![burzum](https://avatars.githubusercontent.com/u/162789?v=4)](https://github.com/burzum "burzum (4 commits)")[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (4 commits)")[![Arhell](https://avatars.githubusercontent.com/u/26163841?v=4)](https://github.com/Arhell "Arhell (3 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (3 commits)")[![Iandenh](https://avatars.githubusercontent.com/u/2911923?v=4)](https://github.com/Iandenh "Iandenh (3 commits)")[![CauanCabral](https://avatars.githubusercontent.com/u/83092?v=4)](https://github.com/CauanCabral "CauanCabral (2 commits)")[![bumburoom](https://avatars.githubusercontent.com/u/895685?v=4)](https://github.com/bumburoom "bumburoom (2 commits)")[![huipvandenende](https://avatars.githubusercontent.com/u/46244086?v=4)](https://github.com/huipvandenende "huipvandenende (2 commits)")[![ndm2](https://avatars.githubusercontent.com/u/5031606?v=4)](https://github.com/ndm2 "ndm2 (2 commits)")[![jadb](https://avatars.githubusercontent.com/u/33527?v=4)](https://github.com/jadb "jadb (2 commits)")

---

Tags

elasticsearchcakephp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/qlsgroup-elastic-search/health.svg)

```
[![Health](https://phpackages.com/badges/qlsgroup-elastic-search/health.svg)](https://phpackages.com/packages/qlsgroup-elastic-search)
```

###  Alternatives

[jolicode/elastically

Opinionated Elastica based framework to bootstrap PHP and Elasticsearch implementations.

2571.7M1](/packages/jolicode-elastically)[friendsofcake/search

CakePHP Search plugin using PRG pattern

1742.0M37](/packages/friendsofcake-search)[cakephp/elastic-search

An Elastic Search datasource and data mapper for CakePHP

86766.6k8](/packages/cakephp-elastic-search)[kvz/elasticsearch

CakePHP Plugin for ElasticSearch

4410.5k](/packages/kvz-elasticsearch)[skie/cakephp-search

CakePHP Plum Search plugin

19186.5k2](/packages/skie-cakephp-search)[kunstmaan/search-bundle

The KunstmaanSearchBundle works with ElasticSearch and supports different search providers. The bundle currently supports Elastica as a provider. Add your own objects to index using a tagged service which implements the SearchConfigurationInterface

1884.8k1](/packages/kunstmaan-search-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
