zoukankan      html  css  js  c++  java
  • ElasticSearch-PHP的API使用(二)

    1:索引内的一个文档的创建(相当表记录的添加)

    比如:要添加一条记录 INSERT INTO blog(title,content,add_time) VALUES('ElasticSearch-PHP之使用二','有关于ElasticSearch在PHP下的扩展使用方法之谈','2016-11-18')

    require_once( __DIR__ . '/../vendor/elasticsearch/autoload.php');
    $hosts = Yii::app()->params['extra']['elasticsearch']['hosts'];  //array('192.168.1.10')     
    $client =  ElasticsearchClientBuilder::create()->setHosts($hosts)->build();
    $params = array(
                'index' => 'website',
                'type' => 'blog',
                'id' => 7,
                'body' => array(
                    'title' => 'ElasticSearch-PHP之使用二',
                    'content' => '有关于ElasticSearch在PHP下的扩展使用方法之谈',
                    'create_time' => '2016-11-18 08:00:00',
                ),
            );
    $resp = $client->index($params);
    echo '<pre>';
    print_r($resp);
    echo '</pre>';
    die('FILE:' . __FILE__ . '; LINE:' . __LINE__);

    2:数据查询一(get)

            $client = $this->getElasticClient();
            $params = array(
                'index' => $this->_index,
                'type' => $this->_type,
                'id' => Yii::app()->request->getParam('id', 1),
            );
            try {
                $resp = $client->get($params);
            } catch (Exception $ex) {
                $resp = $ex->getMessage();
            }
    

    3:数据查询二(search) 

            $client = $this->getElasticClient();
            $params = array(
                'index' => $this->_index,
                'type' => $this->_type,
                'body' => array(
                    'query' => array(
                        'match' => array(
                            'title' => 'elasticsearch php extends'
                        ),
                    ),
                ),
            );
            try {
                $resp = $client->search($params);
            } catch (Exception $ex) {
                $resp = $ex->getMessage();
            }
    
            echo '<pre>';
            print_r($resp);
            echo '</pre>';
            die('FILE:' . __FILE__ . '; LINE:' . __LINE__);

     

  • 相关阅读:
    Android 动画-alpha(渐变透明度动画效果)
    Memento(备忘录)
    Mediator(中介者)
    Iterator(迭代器)
    Command(命令)
    Chain of Responsibility(责任链)
    Template Method(模板方法)
    Interpreter(解释器)
    Proxy(代理)
    Flyweight(享元)
  • 原文地址:https://www.cnblogs.com/amuge/p/6076232.html
Copyright © 2011-2022 走看看