Elasticsearch的PHP的API使用(一)
前提:在服務器上安裝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:測試
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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
?
來源:http://www.cnblogs.com/amuge/p/6072162.html
總結
以上是生活随笔為你收集整理的Elasticsearch的PHP的API使用(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 戴玉强(说一说戴玉强的简介)
- 下一篇: 艾滋病日(说一说艾滋病日的简介)