• 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

  • 相关阅读:
    Nothing
    交换机基础
    BringWindowToTop(), SetForegroundWindow(), SetActiveWindow()
    NYOJ 38 布线问题_(解法2 Prim算法)
    Cocos2d-x3.0TestCpp文件夹笔记(二)
    SqlServer禁用启用触发器、外键约束
    Qt之zip压缩/解压缩(QuaZIP)
    Qt中用QuaZip来压缩和解压缩文件
    Qt 之 ZIP开源库 QuaZIP
    sqlserver 获取存储过程执行时间
  • 原文地址:https://www.cnblogs.com/amuge/p/6072162.html
Copyright © 2020-2023  润新知