本文整理汇总了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();
}
示例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';
}
示例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;
}
}
示例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];
}
示例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");
}