本文整理汇总了PHP中Elastica\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: publish
public function publish(Client $client, $actionType, TableInterface $table, RecordInterface $record)
{
$con = new Condition(array('id', '=', $record->id));
$row = $table->getRow(array('id', 'pageId', 'userId', 'urlTitle', 'title', 'text'), $con);
$index = $client->getIndex('amun');
$type = $index->getType('page');
$id = $row['pageId'] . '-' . $record->id;
try {
$document = $type->getDocument($id);
if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) {
// get referring page
$handler = $this->hm->getHandler('AmunService\\Content\\Page');
$page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title'));
$data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time());
$type->updateDocument(new Document($id, $data));
} else {
if ($actionType == RecordAbstract::DELETE) {
$type->deleteDocument($document);
}
}
} catch (NotFoundException $e) {
if ($actionType == RecordAbstract::INSERT || $actionType == RecordAbstract::UPDATE) {
// get referring page
$handler = $this->hm->getHandler('AmunService\\Content\\Page');
$page = $handler->get($row['pageId'], array('id', 'path', 'urlTitle', 'title'));
$data = array('id' => $id, 'userId' => $row['userId'], 'path' => $page['path'] . '/view/' . $row['id'] . '/' . $row['urlTitle'], 'title' => $row['title'], 'content' => $row['text'], 'date' => time());
$type->addDocument(new Document($id, $data));
} else {
if ($actionType == RecordAbstract::DELETE) {
// is already deleted
}
}
}
$type->getIndex()->refresh();
}
示例2: testShutdown
/**
* Shuts one of two nodes down (if two available)
*/
public function testShutdown()
{
$client = $this->_getClient();
$nodes = $client->getCluster()->getNodes();
$count = count($nodes);
if ($count < 2) {
$this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
}
// Store node info of node with port 9200 for later
foreach ($nodes as $key => $node) {
if ($node->getInfo()->getPort() == 9200) {
$info = $node->getInfo();
unset($nodes[$key]);
}
}
// Select one of the not port 9200 nodes and shut it down
$node = array_shift($nodes);
$node->shutdown('2s');
// Wait until node is shutdown
sleep(5);
// Use still existing node
$client = new Client(array('host' => $info->getIp(), 'port' => $info->getPort()));
$names = $client->getCluster()->getNodeNames();
// One node less ...
$this->assertEquals($count - 1, count($names));
}
示例3: requestByType
/**
* Making a request by giving in raw json as the query
* @param jsonstring $query Raw json query
* @return array An array containing the mapped entities.
*/
public function requestByType($query, $type = 'organisation,vacancy,person', $requestType = Request::GET)
{
$client = new Client(array('host' => $this->es_host, 'port' => $this->es_port));
$path = $this->getIndex() . '/' . $type . '/_search';
$response = $client->request($path, $requestType, $query)->getData();
return $this->esMapper->getEntities($response['hits']['hits']);
}
示例4: initialize
/**
* До любых других действий
*/
public function initialize()
{
$currentActionName = $this->dispatcher->getActiveMethod();
$annotations = $this->annotations->getMethod(self::class, $currentActionName);
if ($annotations->has('actionInfo')) {
$annotation = $annotations->get('actionInfo');
$actionTitle = $annotation->getNamedArgument('name');
$this->log->info('Запустили: {actionTitle}', ['actionTitle' => $actionTitle]);
} else {
$currentTaskName = $this->dispatcher->getTaskName();
$this->log->info('Запустили: {currentTaskName}::{currentActionName}', ['currentTaskName' => $currentTaskName, 'currentActionName' => $currentActionName]);
}
$this->indexName = $this->dispatcher->getParam('index', 'string', false);
$this->typeName = $this->dispatcher->getParam('type', 'string', false);
if (!$this->indexName) {
$this->log->error('Указание индекса является обязательным параметром');
die;
}
$this->sizePerShard = $this->dispatcher->getParam('sizePerShard', 'int', false) ?: $this->sizePerShard;
$this->elasticsearchHost = $this->dispatcher->getParam('host', 'string', false) ?: $this->elasticsearchHost;
$this->elasticsearchPort = $this->dispatcher->getParam('port', 'int', false) ?: $this->elasticsearchPort;
$connectParams = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
$this->client = new Client($connectParams);
try {
$this->client->getStatus();
} catch (\Elastica\Exception\Connection\HttpException $e) {
$context = ['host' => $this->elasticsearchHost, 'port' => $this->elasticsearchPort];
$this->log->error('Подключение к серверу elasticsearch отсутствует: http://{host}:{port}', $context);
die;
}
$this->elasticaIndex = $this->client->getIndex($this->indexName);
$this->elasticaType = $this->elasticaIndex->getType($this->typeName);
}
示例5: testDeleteIndex
public function testDeleteIndex()
{
$index = $this->getMockBuilder('Elastica\\Index')->disableOriginalConstructor()->setMethods(array('delete'))->getMock();
$index->expects($this->once())->method('delete');
$this->elasticaClient->expects($this->once())->method('getIndex')->with('comments')->will($this->returnValue($index));
$this->client->deleteIndex('comments');
}
示例6: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $alias
*/
public function handle(Client $client, $index, $alias)
{
$config = $this->configurations->get($alias);
if (null === $config) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->create($config);
}
示例7: addDocumentsToPlayListIndex
/**
* @param $documents
*/
protected function addDocumentsToPlayListIndex($documents)
{
$elasticaClient = new Client();
$playListIndex = $elasticaClient->getIndex('track_index');
$trackType = $playListIndex->getType('track');
$trackType->addDocuments($documents);
$trackType->getIndex()->refresh();
}
开发者ID:slaparra,项目名称:Training-Elastic-Search-Symfony,代码行数:11,代码来源:ImportTracksFromDbToTrackIndexCommand.php
示例8: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $type
* @param string $alias
*/
public function handle(Client $client, $index, $type, $alias)
{
$mapping = $this->configurations->getMapping($alias, $type);
if (!$mapping) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->getType($type)->setMapping($mapping);
}
示例9: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
* @param string $alias
*/
public function handle(Client $client, $index, $alias)
{
$settings = $this->configurations->getSettings($alias);
if (null === $settings) {
throw new \InvalidArgumentException();
}
$client->getIndex($index)->setSettings($settings);
}
示例10: handle
/**
* Handle index deletion command
*
* @param Client $client
* @param string $index
*
* @throws IndexNotFoundException
*/
public function handle(Client $client, $index)
{
$index = $client->getIndex($index);
if (!$index->exists()) {
throw new IndexNotFoundException($index);
}
$index->delete();
}
示例11: __construct
/**
* @param array $options
*/
public function __construct($options = [])
{
parent::__construct($options);
$this->client = new Client($options);
if (!isset($options['index'])) {
$options['index'] = 'log';
}
$this->index = $this->client->getIndex($options['index']);
}
示例12: persist
/**
* @param array $payload
*
* @return bool
*/
public function persist(array $payload)
{
$documents = array_map(function (array $user) {
return $this->makeDocument($user);
}, $payload);
$responseSet = $this->elasticaClient->getIndex($this->target->index)->addDocuments($documents);
$this->responses = $responseSet;
return true;
}
示例13: __construct
/**
* Constructor
*
* @param Client $client The elastic search client.
* @param string $indexName The elastic search index name.
* @param boolean $delete Delete the index if already exist (default = false).
*/
public function __construct(Client $client, $indexName, $delete = false)
{
$this->client = $client;
$this->index = $client->getIndex($indexName);
// Checks if the given index is already created
if (!$this->index->exists($indexName)) {
// Create the index.
$this->index->create(array(), $delete);
}
}
示例14: testBasicGettingStarted
public function testBasicGettingStarted()
{
$client = new \Elastica\Client();
$index = $client->getIndex('ruflin');
$type = $index->getType('users');
$id = 2;
$data = array('firstname' => 'Nicolas', 'lastname' => 'Ruflin');
$doc = new \Elastica\Document($id, $data);
$type->addDocument($doc);
}
示例15: testInvalidElasticRequest
/**
* @expectedException \Elastica\Exception\ResponseException
*/
public function testInvalidElasticRequest()
{
$connection = new Connection();
$connection->setHost('localhost');
$connection->setPort(9500);
$connection->setTransport('Thrift');
$client = new Client();
$client->addConnection($connection);
$index = new Index($client, 'missing_index');
$index->getStatus();
}