All Projects → cakephp → elastic-search

cakephp / elastic-search

Licence: other
Elastic search datasource for CakePHP

Programming Languages

PHP
23972 projects - #3 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to elastic-search

Search
CakePHP: Easy model searching
Stars: ✭ 153 (+80%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-feed
CakePHP Plugin with RssView to create RSS feeds.
Stars: ✭ 13 (-84.71%)
Mutual labels:  cakephp, cakephp-plugin
Migrations
CakePHP database migrations plugin
Stars: ✭ 114 (+34.12%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-i18n
A CakePHP plugin with I18n related tools.
Stars: ✭ 40 (-52.94%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-ajax
AJAX for CakePHP: A plugin to ease handling AJAX requests.
Stars: ✭ 55 (-35.29%)
Mutual labels:  cakephp, cakephp-plugin
plum search
Plum Search plugin for CakePHP
Stars: ✭ 20 (-76.47%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Ide Helper
IDE Helper plugin for CakePHP
Stars: ✭ 138 (+62.35%)
Mutual labels:  cakephp, cakephp-plugin
Footprint
CakePHP plugin to allow passing currently logged in user to model layer.
Stars: ✭ 81 (-4.71%)
Mutual labels:  cakephp, cakephp-plugin
auth
Auth objects for CakePHP
Stars: ✭ 28 (-67.06%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-error-email
ErrorEmail Plugin for CakePHP3.x
Stars: ✭ 16 (-81.18%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Tinyauth
CakePHP TinyAuth plugin for an easy and fast user authentication and authorization. Single or multi role. DB or config file based.
Stars: ✭ 114 (+34.12%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-shim
CakePHP plugin to "shim" functionality up and down for major versions of the framework.
Stars: ✭ 37 (-56.47%)
Mutual labels:  cakephp, cakephp-plugin
Acl
Plugin for managing ACL in CakePHP applications.
Stars: ✭ 113 (+32.94%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Jwt Auth
A CakePHP plugin for authenticating using JSON Web Tokens
Stars: ✭ 153 (+80%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Hybridauth
CakePHP plugin for HybridAuth
Stars: ✭ 81 (-4.71%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Imagine Plugin
CakePHP wrapper for the powerful Imagine image processing library. Makes images manipulation easy and powerful.
Stars: ✭ 140 (+64.71%)
Mutual labels:  cakephp, cakephp-plugin
Aclmanager
Plugin to manage Acl for CakePHP 2.x
Stars: ✭ 59 (-30.59%)
Mutual labels:  cakephp, cakephp-plugin
Webservice
Bringing the power of the CakePHP ORM to your favourite webservices
Stars: ✭ 79 (-7.06%)
Mutual labels:  cakephp, cakephp-plugin
Cakephp Proffer
An upload plugin for CakePHP 3
Stars: ✭ 121 (+42.35%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-swagger-bake
Automatically generate OpenAPI, Swagger, and Redoc documentation from your existing CakePHP code.
Stars: ✭ 48 (-43.53%)
Mutual labels:  cakephp, cakephp-plugin

Elasticsearch Datasource for CakePHP

Build Status Latest Stable Version Total Downloads Code Coverage Software License

Use Elastic Search as an alternative ORM backend in CakePHP 4.0+.

You can find the documentation for the plugin in the Cake Book.

Installing Elasticsearch via composer

You can install Elasticsearch into your project using composer. For existing applications you can add the following to your composer.json file:

"require": {
    "cakephp/elastic-search": "^3.0"
}

And run php composer.phar update

Versions Table

Cake\ElasticSearch CakePHP ElasticSearch
1.x 3.0 - 3.5 2.x - 5.x
2.x 3.6+ 6.x
3.x 4.0+ 6.x
4.x 4.0+ 7.x

You are seeing the 3.x version.

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

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

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

You must create your own Index class to define the name of internal index for Elasticsearch, as well as to define the mapping type and define any entity properties you need like virtual properties. As you have to use only one mapping type for each index, 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';
    }
}

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, you can run the tests for CakePHP by doing the following:

  1. Copy phpunit.xml.dist to phpunit.xml
  2. Run phpunit
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].