zoukankan      html  css  js  c++  java
  • 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:测试

    require_once( __DIR__ . '/../vendor/elasticsearch/autoload.php');
    $hosts = array('192.168.1.10');
    $client = ElasticsearchClientBuilder::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

  • 相关阅读:
    HttpServlet
    Servlet练习和自定义GenericServlet实现类
    Servlet-ServletRequest
    HTTP协议-GET/POST请求
    Servlet-ServletConfig对象
    Servlet
    1089. Duplicate Zeros
    1002. Find Common Characters
    17. Letter Combinations of a Phone Number
    254. Factor Combinations
  • 原文地址:https://www.cnblogs.com/amuge/p/6072162.html
Copyright © 2011-2022 走看看