imsamurai / elasticsearch-source
Elasticsearch source for CakePHP (HttpSource)
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 1
Type:cakephp-plugin
Requires
- composer/installers: *
- imsamurai/http-source: >=1.2.1
README
CakePHP ElasticsearchSource is DataSource Plugin for Elasticsearch
Installation
Step 1: Clone or download HttpSource
Step 2: Clone or download to Plugin/ElasticsearchSource
cd my_cake_app/app git://github.com/imsamurai/CakePHP-ElasticsearchSource-Datasource.git Plugin/ElasticsearchSource
or if you use git add as submodule:
cd my_cake_app
git submodule add "git://github.com/imsamurai/CakePHP-ElasticsearchSource-Datasource.git" "app/Plugin/ElasticsearchSource"
then update submodules:
git submodule init
git submodule update
Step 3: Add your configuration to database.php
and set it to the model
:: database.php ::
public $elasticsearch = array( 'datasource' => 'ElasticsearchSource.Http/ElasticsearchSource', 'host' => 'example.com', 'port' => 'some port' ); public $elasticsearchTest = array( 'datasource' => 'ElasticsearchSource.Http/ElasticsearchSource', 'host' => 'localhost', 'prefix' => '', 'port' => 9200, 'timeout' => 5 );
Then make model
:: Elasticsearch.php ::
public $useDbConfig = 'elasticsearch'; public $useTable = '<desired endpoint, for ex: "_search">';
Step 4: Load plugin
:: bootstrap.php ::
CakePlugin::load('HttpSource', array('bootstrap' => true, 'routes' => true)); CakePlugin::load('ElasticsearchSource', array('bootstrap' => false, 'routes' => true));
#Tests
To run tests add and fill $elasticsearchTest in database.php
#Usage
You can use elasticsearch almost as db tables:
$this->Elasticsearch->setSource('search'); $params = array( 'conditions' => array( 'query' => array( "term" => array("title" => "apple") ) ), 'fields' => array('title', 'rank'), 'order' => array('rank' => 'desc'), 'offset' => 2 ); $result = $this->Elasticsearch->find('first', $params);
#Documentation
Please read HttpSource Plugin README