1、http://boss.to8to.com/index.php/gii/controller/index
在gii 创建一个Controller 名字showlog
2、导入ES核心包
Yii-Elastica-master\lib\Elastica\* 到..\protected\vendor\Elastica\*
3、导入ES核心组件
Yii-Elastica-master\components\* 到 ..\protected\components\*
4、在protected\components\ 创建 ElasticaAutoLoader.php 见04
5、在入口文件index.php 导入
define('YII_ENABLE_EXCEPTION_HANDLER', false);
define('YII_ENABLE_ERROR_HANDLER', false);
//Yii::createWebApplication($config);->run();
$app = Yii::createWebApplication($config);
// adding custom Zend Framework autoloader
Yii::import("application.vendor.*");
Yii::import("application.components.ElasticaAutoLoader", true);
Yii::registerAutoloader(array('ElasticaAutoLoader','loadClass'), true);
$app->run();
6、在 controllers\showlogController.php
$_config = array(
'host' =>'192.168.1.60', // host
'port' => 39200,
);
$client = new Elastica\Client($_config);
//$client = new Elastica\Client();
$elastica_query = new Elastica\Query();
$elastica_search = new Elastica\Search($client);
$elastica_search->setQuery($elastica_query);
try {
$b = $elastica_search->search();
} catch (Exception $e) {
var_dump($e->getMessage());
}
$res = ($b->getResults());
var_dump($res);
/*
foreach ($res as $key => $rs) {
var_dump($rs->getParam('_source'));
//var_dump($rs) ;
}
*/
echo 'all the end';
//exit;