標籤:表示 strong array nbsp last images uil ash ber
前提:在伺服器上安裝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"
:
"[email protected]"
}
}
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
Elasticsearch的PHP的API使用(一)