imsamurai/elasticsearch-source

Elasticsearch source for CakePHP (HttpSource)

1.3.1 2014-12-23 11:48 UTC

README

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

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