前提:在服務器上安裝Elasticsearch (host:192.168.1.10)
http://192.168.1.10:9200?_search?pretty
1:安裝PHP的Elasticsearch的的擴展(使用composer方法)
1.1 下載composer.phar包(見composer安裝軟件 http://www.cnblogs.com/amuge/p/5998985.html)
1.2 composer.json
{
"require"
: {
"elasticsearch/elasticsearch"
:
"~2.0@beta"
}
}
1.3 php composer.phar install 會自動尋找composer.json這個配置文件,下載此的擴展。當下載完成后會在當前運行的目錄下新添一個vendor目錄(就表示成功下載elasticsearch-php擴展)
2:將vendor目錄拷到項目的第三方的擴展目錄下(比如:我是用YII框架。我將vendor拷到 application/protected/vendor/elasticsearch目錄下)
3:測試
require_once( __DIR__ . '/../vendor/elasticsearch/autoload.php');
$hosts = array('192.168.1.10');
$client = Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$client = $this->getElasticClient();
$params = array(
'index' => 'website',
'type' => 'blog',
'body' => array(
'query' => array(
'match' => array(
'_id' => 1,
)
)
)
);
$rtn = $client->search($params);
echo '<pre>';
print_r($rtn);
echo '</pre>';
die('FILE:' . __FILE__ . '; LINE:' . __LINE__);
4:結果

官方文檔:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html
瀏覽ES庫的插件:head 訪問:http://192.168.1.100/_plugin/head

