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


PHP Mapping::toArray方法代码示例

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


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

示例1: testEnableTtl

 public function testEnableTtl()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     $mapping = new Mapping($type, array());
     $mapping->enableTtl();
     $data = $mapping->toArray();
     $this->assertTrue($data[$type->getName()]['_ttl']['enabled']);
 }
开发者ID:kskod,项目名称:Elastica,代码行数:11,代码来源:MappingTest.php

示例2: main

 /**
  * Creates the elastic search mapping for the provided table, or just prints it out
  * to the screen if the `dry-run` option is provided.
  *
  * @param string $table The table name to inspect and create a mapping for
  * @return bool
  */
 public function main($table)
 {
     $table = TableRegistry::get($table);
     $schema = $table->schema();
     $mapping = ['@timestamp' => ['type' => 'date', 'format' => 'basic_t_time_no_millis||dateOptionalTime||basic_date_time||ordinal_date_time_no_millis||yyyy-MM-dd HH:mm:ss'], 'transaction' => ['type' => 'string', 'index' => 'not_analyzed'], 'type' => ['type' => 'string', 'index' => 'not_analyzed'], 'primary_key' => ['type' => 'string', 'index' => 'not_analyzed'], 'source' => ['type' => 'string', 'index' => 'not_analyzed'], 'parent_source' => ['type' => 'string', 'index' => 'not_analyzed'], 'original' => ['properties' => []], 'changed' => ['properties' => []], 'meta' => ['properties' => ['ip' => ['type' => 'string', 'index' => 'not_analyzed'], 'url' => ['type' => 'string', 'index' => 'not_analyzed'], 'user' => ['type' => 'string', 'index' => 'not_analyzed'], 'app_name' => ['type' => 'string', 'index' => 'not_analyzed']]]];
     $properties = [];
     foreach ($schema->columns() as $column) {
         $properties[$column] = $this->mapType($schema, $column);
     }
     if ($table->hasBehavior('AuditLog')) {
         $whitelist = (array) $table->behaviors()->AuditLog->config('whitelist');
         $blacklist = (array) $table->behaviors()->AuditLog->config('blacklist');
         $properties = empty($whitelist) ? $properties : array_intersect_key($properties, array_flip($whitelist));
         $properties = array_diff_key($properties, array_flip($blacklist));
     }
     $mapping['original']['properties'] = $mapping['changed']['properties'] = $properties;
     $client = ConnectionManager::get('auditlog_elastic');
     $index = $client->getIndex(sprintf($client->getConfig('index'), '-' . gmdate('Y.m.d')));
     $type = $index->getType($table->table());
     $elasticMapping = new ElasticaMapping();
     $elasticMapping->setType($type);
     $elasticMapping->setProperties($mapping);
     if ($this->params['dry-run']) {
         $this->out(json_encode($elasticMapping->toArray(), JSON_PRETTY_PRINT));
         return true;
     }
     if ($this->params['use-templates']) {
         $template = ['template' => sprintf($client->getConfig('index'), '*'), 'mappings' => $elasticMapping->toArray()];
         $response = $client->request('_template/template_' . $type->getName(), Request::PUT, $template);
         $this->out('<success>Successfully created the mapping template</success>');
         return $response->isOk();
     }
     if (!$index->exists()) {
         $index->create();
     }
     $elasticMapping->send();
     $this->out('<success>Successfully created the mapping</success>');
     return true;
 }
开发者ID:lorenzo,项目名称:audit-stash,代码行数:46,代码来源:ElasticMappingShell.php

示例3: validate

 /**
  * @return Status
  */
 public function validate()
 {
     $this->outputIndented("Validating mappings...");
     if ($this->optimizeIndexForExperimentalHighlighter && !in_array('experimental highlighter', $this->availablePlugins)) {
         $this->output("impossible!\n");
         return Status::newFatal(new RawMessage("wgCirrusSearchOptimizeIndexForExperimentalHighlighter is set to true but the " . "'experimental highlighter' plugin is not installed on all hosts."));
     }
     $requiredMappings = $this->mappingConfig;
     if (!$this->checkMapping($requiredMappings)) {
         /** @var Mapping[] $actions */
         $actions = array();
         // TODO Conflict resolution here might leave old portions of mappings
         foreach ($this->types as $typeName => $type) {
             $action = new Mapping($type);
             foreach ($requiredMappings[$typeName] as $key => $value) {
                 $action->setParam($key, $value);
             }
             $actions[] = $action;
         }
         try {
             // @todo Use $action->send(array('master_timeout' => ...))
             // after updating to version of Elastica library that supports it.
             // See https://github.com/ruflin/Elastica/pull/1004
             foreach ($actions as $action) {
                 $action->getType()->request('_mapping', Request::PUT, $action->toArray(), array('master_timeout' => $this->masterTimeout));
             }
             $this->output("corrected\n");
         } catch (ExceptionInterface $e) {
             $this->output("failed!\n");
             $message = ElasticsearchIntermediary::extractMessage($e);
             return Status::newFatal(new RawMessage("Couldn't update mappings.  Here is elasticsearch's error message: {$message}\n"));
         }
     }
     return Status::newGood();
 }
开发者ID:zoglun,项目名称:mediawiki-extensions-CirrusSearch,代码行数:38,代码来源:MappingValidator.php


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