1. 1http://boss.to8to.com/index.php/gii/controller/index
    2. gii 创建一个Controller 名字showlog
    3. 2、导入ES核心包
    4. Yii-Elastica-master\lib\Elastica\* 到..\protected\vendor\Elastica\*
    5. 3、导入ES核心组件
    6. Yii-Elastica-master\components\* ..\protected\components\*
    7. 4、在protected\components\ 创建 ElasticaAutoLoader.php 04
    8. 5、在入口文件index.php 导入
    9. define('YII_ENABLE_EXCEPTION_HANDLER', false);
    10. define('YII_ENABLE_ERROR_HANDLER', false);
    11. //Yii::createWebApplication($config);->run();
    12. $app = Yii::createWebApplication($config);
    13. // adding custom Zend Framework autoloader
    14. Yii::import("application.vendor.*");
    15. Yii::import("application.components.ElasticaAutoLoader", true);
    16. Yii::registerAutoloader(array('ElasticaAutoLoader','loadClass'), true);
    17. $app->run();
    18. 6、在 controllers\showlogController.php
    19. $_config = array(
    20. 'host' =>'192.168.1.60', // host
    21. 'port' => 39200,
    22. );
    23. $client = new Elastica\Client($_config);
    24. //$client = new Elastica\Client();
    25. $elastica_query = new Elastica\Query();
    26. $elastica_search = new Elastica\Search($client);
    27. $elastica_search->setQuery($elastica_query);
    28. try {
    29. $b = $elastica_search->search();
    30. } catch (Exception $e) {
    31. var_dump($e->getMessage());
    32. }
    33. $res = ($b->getResults());
    34. var_dump($res);
    35. /*
    36. foreach ($res as $key => $rs) {
    37. var_dump($rs->getParam('_source'));
    38. //var_dump($rs) ;
    39. }
    40. */
    41. echo 'all the end';
    42. //exit;