本文整理汇总了PHP中Elastica\Index::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Index::exists方法的具体用法?PHP Index::exists怎么用?PHP Index::exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Index
的用法示例。
在下文中一共展示了Index::exists方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: backupAction
/**
* @actionInfo(name='Бэкап данных')
*/
public function backupAction()
{
$this->folderName = __DIR__ . '/backup/';
if (!$this->elasticaIndex->exists()) {
$this->log->error('Индекс для бэкапа отсутствует: {indexName}', ['indexName' => $this->indexName]);
return;
}
$this->checkFileName();
$this->checkBackupFolder();
$this->log->info('Всё ок, бекапим {indexName} в {fileName}', ['indexName' => $this->indexName, 'fileName' => $this->fileName]);
$this->log->info('Параметры бэкапа: sizePerShard={sizePerShard}', ['sizePerShard' => $this->sizePerShard]);
$scanAndScroll = $this->getScanAndScroll();
foreach ($scanAndScroll as $resultSet) {
$buffer = [];
/* @var \Elastica\ResultSet $resultSet */
$results = $resultSet->getResults();
foreach ($results as $result) {
$item = [];
$item['_id'] = $result->getId();
$item['_source'] = $result->getSource();
$buffer[] = json_encode($item, JSON_UNESCAPED_UNICODE);
}
$fileBody = implode(PHP_EOL, $buffer);
if (file_put_contents($this->fileName, $fileBody, FILE_APPEND)) {
$countDocuments = count($results);
$this->log->info('Сохранили {countDocuments} записей', ['countDocuments' => $countDocuments]);
} else {
$this->log->error('Ошибка записи данных');
die;
}
}
}
示例3: validate
/**
* @return Status
*/
public function validate()
{
if ($this->startOver) {
$this->outputIndented("Blowing away index to start over...");
$this->createIndex(true);
$this->output("ok\n");
return Status::newGood();
}
if (!$this->index->exists()) {
$this->outputIndented("Creating index...");
$this->createIndex(false);
$this->output("ok\n");
return Status::newGood();
}
$this->outputIndented("Index exists so validating...\n");
return Status::newGood();
}
示例4: initialize
/**
* Initialize the ElasticSearch client, and setup settings for the client.
*
* @return void
*/
public function initialize()
{
spl_autoload_register(array($this, 'autoLoad'));
$this->_connectionOptions = array('url' => $this->modx->getOption('sisea.elastic.hostname', null, 'http://127.0.0.1') . ':' . $this->modx->getOption('sisea.elastic.port', null, 9200) . '/');
try {
$this->client = new \Elastica\Client($this->_connectionOptions);
$this->index = $this->client->getIndex(strtolower($this->modx->getOption('sisea.elastic.index', null, 'siplesearchindex')));
if (!$this->index->exists()) {
$indexSetup = $this->modx->getObject('modSnippet', array('name' => 'SimpleSearchElasticIndexSetup'));
if ($indexSetup) {
$indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup'));
} else {
$indexOptions = $this->modx->fromJSON($this->modx->runSnippet('SimpleSearchElasticIndexSetup_default'));
}
$this->index->create($indexOptions, true);
}
} catch (Exception $e) {
$this->modx->log(xPDO::LOG_LEVEL_ERROR, 'Error connecting to ElasticSearch server: ' . $e->getMessage());
}
}
示例5: setUp
protected function setUp()
{
$typeName = Cache::TYPE_NAME;
$this->type = $this->prophesize('\\Elastica\\Type');
$this->type->request(Argument::any(), Argument::cetera())->willReturn(true);
$this->type->getName()->willReturn($typeName);
$this->index = $this->prophesize('\\Elastica\\Index');
$this->index->getType($typeName)->willReturn($this->type->reveal());
$this->index->exists()->willReturn(true);
$nsDoc = new Document('DoctrineNamespaceCacheKey[]', [Cache::VALUE_FIELD => serialize($this->namespaceId)]);
$this->type->getIndex()->willReturn($this->index->reveal());
$this->type->getDocument("DoctrineNamespaceCacheKey[]")->willReturn($nsDoc);
$this->client = $this->prophesize('\\Elastica\\Client');
$this->client->getIndex($this->indexName)->willReturn($this->index->reveal());
$this->cache = new Cache($this->client->reveal(), ['index' => $this->indexName]);
}
示例6: deleteIndex
/**
* Удаление индекса
*/
public function deleteIndex()
{
if ($this->index->exists()) {
$this->index->delete();
}
}
示例7: setUp
protected function setUp()
{
/** @var ElasticaService elasticaService */
$elasticaService = $this->getContainer()->get("revinate_search.elasticsearch_service");
$this->elasticaClient = $elasticaService->getInstance();
$this->index = new \Elastica\Index($this->elasticaClient, View::INDEX_NAME);
if (!$this->index->exists()) {
$this->index->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
$this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
$mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/mapping.json"), true);
$mapping = new \Elastica\Type\Mapping($this->type, $mappingJson['properties']);
$this->type->setMapping($mapping);
} else {
$this->type = new \Elastica\Type($this->index, View::INDEX_TYPE);
}
$this->timeSeriesIndex = new \Elastica\Index($this->elasticaClient, StatusLog::INDEX_NAME . self::$timeSeriesTestDateSuffix);
if (!$this->timeSeriesIndex->exists()) {
$this->timeSeriesIndex->create(array("index.number_of_replicas" => "0", "index.number_of_shards" => "1"));
$this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
$mappingJson = json_decode(file_get_contents(__DIR__ . "/../data/es/statusLogMapping.json"), true);
$mapping = new \Elastica\Type\Mapping($this->timeSeriesType, $mappingJson['properties']);
$this->timeSeriesType->setMapping($mapping);
} else {
$this->timeSeriesType = new \Elastica\Type($this->timeSeriesIndex, StatusLog::INDEX_TYPE);
}
}