This is a pre-alpha version of an alternative ORM for CakePHP 3.0 using Elastic Search as its backend. It is currently under development and is only being used to test the interfaces exposed in CakePHP 3.0.
You can find the documentation for the plugin in the Cake Book.
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": "^1.0"
}
And run php composer.phar update
After installing, you should tell your application to load the plugin:
// in config/bootstrap.php
Plugin::load('Cake/ElasticSearch');
// If you want the plugin to automatically configure the Elastic model provider
// and FormHelper do the following:
Plugin::load('Cake/ElasticSearch', ['bootstrap' => true]);
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,
'index' => 'my_apps_index',
],
]
You can enable request logging by setting the log
config option to true. By
default, Elastica\Log
will be used, which logs via error_log
. 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.
Type objects are the equivalent of ORM\Table
instances in elastic search. You can
use the TypeRegistry
factory to get instances, much like TableRegistry
:
use Cake\ElasticSearch\TypeRegistry;
$comments = TypeRegistry::get('Comments');
To be able to delete records via criteria other than _id
you need the ElasticSearch delete-by-query plugin.
NOTE: Without the plugin you will get at least 2 test failures
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:
- Copy
phpunit.xml.dist
tophpunit.xml
- Run
phpunit