本文整理汇总了PHP中Elastica\Client::getIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::getIndex方法的具体用法?PHP Client::getIndex怎么用?PHP Client::getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Client
的用法示例。
在下文中一共展示了Client::getIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: __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']);
}
示例4: getIndex
/**
* @return Index
*/
private function getIndex()
{
if (null === $this->index) {
$this->index = $this->client->getIndex($this->indexName);
if (!$this->index->exists()) {
$this->index->create();
}
}
return $this->index;
}
示例5: createIndex
/**
* @param \Generated\Shared\Transfer\ElasticsearchIndexDefinitionTransfer $indexDefinitionTransfer
*
* @return void
*/
protected function createIndex(ElasticsearchIndexDefinitionTransfer $indexDefinitionTransfer)
{
$index = $this->elasticaClient->getIndex($indexDefinitionTransfer->getIndexName());
if (!$index->exists()) {
$this->messenger->info(sprintf('Creating elasticsearch index: "%s"', $indexDefinitionTransfer->getIndexName()));
$settings = $indexDefinitionTransfer->getSettings();
$index->create($settings);
}
foreach ($indexDefinitionTransfer->getMappings() as $mappingName => $mappingData) {
$this->sendMapping($index, $mappingName, $mappingData);
}
}
示例6: indexExtension
/**
* @var Extension
* @var bool
*/
public function indexExtension(Extension $extension, $update = false)
{
$id = $extension->getName();
$packageDocument = new \Elastica\Document($id, ['id' => $id, 'name' => $id, 'description' => $extension->getDescription(), 'tags' => $extension->getVersions(), 'keywords' => $extension->getKeywords(), 'stars' => $extension->getStars()]);
$elasticaIndex = $this->client->getIndex('packages');
$elasticaType = $elasticaIndex->getType('packages');
if ($update) {
$elasticaType->updateDocument($packageDocument);
} else {
$elasticaType->addDocument($packageDocument);
}
$elasticaType->getIndex()->refresh();
}
示例7: __construct
public function __construct($options, $indexName, $typeName)
{
if ($this->client) {
return $this->client;
}
if ($options['debug']) {
define('DEBUG', true);
}
$this->host = $options['host'];
$this->port = $options['port'];
$this->client = new \Elastica\Client(['host' => $this->host, 'port' => $this->port]);
$this->index = $this->client->getIndex($indexName);
$this->indexName = $indexName;
$this->typeName = $typeName;
}
示例8: newIndex
/**
* Get the elasticsearch index being used.
*
* @return Index
*/
protected function newIndex()
{
if (!isset($this->client)) {
$this->client = $this->newClient();
}
return $this->client->getIndex($this->config['index']);
}
示例9: 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();
}
示例10: 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);
}
示例11: 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);
}
示例12: 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
示例13: 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();
}
示例14: 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);
}
示例15: getIndexByAlias
/**
* @return Index
* @throws ElasticaManagerIndexNotFoundException
*/
public function getIndexByAlias()
{
$defaultAlias = $this->getDefaultAlias();
if (!$this->hasAlias($defaultAlias)) {
throw new ElasticaManagerIndexNotFoundException($defaultAlias, true);
}
$elasticaIndex = $this->client->getIndex($defaultAlias);
return $elasticaIndex;
}