PHP中調用 ElasticSearch的數據


PHP中 ElasticSearch的使用

准備

1.環境window  xampp 或者其他的php運行環境

2.windows下安裝Composer-Setup.exe

              http://jingyan.baidu.com/article/4f34706ed04013e386b56d72.html

3.在php.ini中開啟curl和openssl

使用

接下來介紹如何使用elasticsearch-php

4. 在E盤新建文件夾命名為elastic,下載composer.phar  拷貝composer.phar到
     E:/elastic目錄下面

5.在里面放入一個命名為composer.json的文件,文件內容為:

    {  
        "require":{  
            "elasticsearch/elasticsearch" : "~1.2"  
        }  
    }  

6..將composer.phar拷貝到elastic文件夾中,cd 到test文件夾,輸入命令:php composer.phar install --no-dev  等待安裝成功

這個時候test文件夾下面應該會出現vendor文件夾,里面有elasticsearch、composer、guzzle等文件夾,很多內容

7.這個時候,就可以使用elasticsearch了

獲取數據

<?php
require_once('vendor/autoload.php');  
$params = array();
$params['hosts'] = array (
    '127.0.0.1:9200',                 // IP + Port改成elasticsearch的ip和端口
   
);
 
    $client = new Elasticsearch\Client($params);

    $getParams = array();
    $getParams['index'] = '庫';
    $getParams['type'] = '表';
    $getParams['id'] = 'id';//上面三個都是elasticsearch里面的東西
    $retDoc = $client->get($getParams);
    var_dump($retDoc);die;

其他的插入數據等https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_quickstart.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM