当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::connection方法代码示例

本文整理汇总了PHP中Elasticsearch\Client::connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::connection方法的具体用法?PHP Client::connection怎么用?PHP Client::connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Elasticsearch\Client的用法示例。


在下文中一共展示了Client::connection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testMapFields

 public function testMapFields()
 {
     $client = \ElasticSearch\Client::connection(array('index' => 'test-index', 'type' => 'test-type'));
     $client->index(array('tweet' => 'ElasticSearch is awesome'));
     $response = $client->map(array('tweet' => array('type' => 'string')));
     $this->assert->array($response)->isNotEmpty();
 }
开发者ID:linbaoling,项目名称:elasticsearch-1,代码行数:7,代码来源:Mapping.php

示例2: indexAction

 public function indexAction()
 {
     //        phpinfo();die();
     //        var_dump((new IndexModel)->deleteUserByUserId()); die();
     //        $client = new Yar_Client("http://192.168.10.122/admin/");
     //        $client->SetOpt(YAR_OPT_PACKAGER, "json");
     //        var_dump($client->deleteUserByUserId());
     /* call remote service */
     //        $result = $client->some_method("parameter");
     //        die();
     //        $data = new ExcelReader(APPLICATION_PATH."/source/example.xls");
     //        $data->dump(true,true);
     //        var_dump($data->sheets[0]['numRows']);
     //        die();
     //        var_dump(base64_decode("FgFikMDYVdFRaK4Wx5cNOEnnRyNWTK+OOA4zQZI4Fd+UWwWCSWlFfHp1ESAiA4jLjukqtp0NDJvkJqlLevRuwA=="));
     //        $cdoco = new Cdoco();
     //        $cdoco->query("set names utf8");
     //        var_dump($cdoco->query("select * from slm_product"));
     //        die();
     //        $data = (new DemoModel())->selectInfo();
     //        echo Payment_AliPay::ERR_ANT_VERIFY_FAILED;
     //        var_dump($data);
     $es = Client::connection(array('servers' => '192.168.10.122:9200'));
     //        $es->map(array(
     //            'title' => array(
     //                'type' => 'my-type',
     //                'index' => 'my-index'
     //            )
     //        ));
     //        $es->setType("t-type")->setIndex("my-index")
     //            ->index(array('title' => 'My cool document','id' => '7'));
     //        $es->index("my-index");
     //        $es->setIndex("my-index")
     //            ->setType("my-type");
     $results = $es->setIndex(["my-index"])->setType(["t-type", "other-type"])->search(['query' => ['term' => ['title' => 'cool']], 'from' => 1, 'size' => 10, 'sort' => ['id' => ['order' => 'asc']], 'fields' => ['title', 'id']]);
     $dsl = new \ElasticSearch\DSL\Builder();
     //        var_dump($es->search('cool'));
     //        var_dump($es->get(1));
     var_dump($results);
     //        var_dump($es->search(array(
     //            'query' => array(
     //                'term' => array('title' => 'cool')
     //            )
     //        )));
     //        var_dump(IndexModel::find(155)->toArray());
     //        (new IndexModel)->deleteUserByUserId();
     //        $this->_view->page = "+++++++++++++";
     /*layout*/
     $this->_layout->meta_title = 'A Blog';
 }
开发者ID:musicsnap,项目名称:Cdoco_Yaf_Ext,代码行数:50,代码来源:Index.php

示例3: init

 public function init()
 {
     if ($this->es != null) {
         return true;
     }
     if ($this->connectionError) {
         return false;
     }
     try {
         $this->es = Client::connection(['servers' => $this->servers, 'protocol' => $this->protocol, 'index' => $this->index, 'type' => $this->type]);
         return true;
     } catch (Exception $ex) {
         $this->connectionError = true;
         return false;
     }
 }
开发者ID:rzer,项目名称:restphp,代码行数:16,代码来源:ElasticDatabase.php

示例4: getElastic

 public function getElastic()
 {
     /** @var Client[] $es */
     static $config, $es = [];
     if ($config === null) {
         $config = $this->getPackageConfig();
         $this->elasticCurrent = $config['elastic.current'];
     }
     $this->elasticCurrent++;
     if (!isset($config['elastic'][$this->elasticCurrent])) {
         $this->elasticCurrent = 0;
     }
     if (!isset($es[$this->elasticCurrent])) {
         $esConfig = $config['elastic'][$this->elasticCurrent];
         $es[$this->elasticCurrent] = Client::connection($esConfig);
     }
     return $es[$this->elasticCurrent];
 }
开发者ID:mpcmf,项目名称:mpcmf-core,代码行数:18,代码来源:elastic.php

示例5: testBulk

 public function testBulk()
 {
     $esURL = 'http://127.0.0.1:9200/index/type';
     putenv("ELASTICSEARCH_URL={$esURL}");
     $client = \ElasticSearch\Client::connection();
     $bulk = $client->beginBulk();
     $doc = array('title' => 'First in Line');
     $client->index($doc, false, array('refresh' => true));
     $doc2 = array('title' => 'Second in Line');
     $client->setType('type2');
     $client->index($doc2, false);
     $client->setIndex('index2');
     $client->delete(55);
     $operations = $bulk->getOperations();
     $this->assert->integer($bulk->count())->isEqualTo(3)->array($operations[1])->hasSize(2)->array($operations[0])->hasSize(2)->array($operations[0][0])->hasKey('index')->array($operations[0][0]['index'])->hasKey('_refresh')->boolean($operations[0][0]['index']['_refresh'])->isEqualTo(true)->array($operations[1][1])->isEqualTo($doc2)->array($operations[2][0])->hasKey('delete')->array($operations[2][0]['delete'])->hasKey('_id')->integer($operations[2][0]['delete']['_id'])->isEqualTo(55);
     $payload = '{"index":{"_id":false,"_index":"index","_type":"type","_refresh":true}}' . "\n" . '{"title":"First in Line"}' . "\n" . '{"index":{"_id":false,"_index":"index","_type":"type2"}}' . "\n" . '{"title":"Second in Line"}' . "\n" . '{"delete":{"_id":55,"_index":"index2","_type":"type2"}}' . "\n";
     $this->assert->string($bulk->createPayload())->isEqualTo($payload);
     // Run multiple bulks and make sure all documents are stored
     $client->beginBulk();
     $client->index(array('title' => 'Bulk1'), 1);
     $client->index(array('title' => 'Bulk2'), 2);
     $client->commitBulk();
     $client->beginBulk();
     $client->index(array('title' => 'Bulk3'), 3);
     $client->index(array('title' => 'Bulk4'), 4);
     $client->commitBulk();
     sleep(1);
     $resp = $client->search('title:Bulk*');
     $this->assert->array($resp)->hasKey('hits')->array($resp['hits'])->hasKey('total')->integer($resp['hits']['total'])->isEqualTo(4);
     putenv("ELASTICSEARCH_URL");
 }
开发者ID:linbaoling,项目名称:elasticsearch-1,代码行数:31,代码来源:Client.php


注:本文中的Elasticsearch\Client::connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。