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

  • 相关阅读:
    深度剖析Reges.Match
    Python入门(一)
    SQL Server部分锁说明理解
    虚拟机Linux安装redis(一)
    transform matrix阅读后的理解
    小程序SKU规格选择
    React 学习记录(二)
    React 学习记录(一)
    在MVC里面使用Response.Redirect方法后记得返回EmptyResult——转载自PowerCoder
    Nodejs的安装随笔
  • 原文地址:https://www.cnblogs.com/amuge/p/6072162.html
Copyright © 2011-2022 走看看