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


PHP Client::create方法代码示例

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


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

示例1: addMapping

 /**
  * Adds a new type to an index with the mappings. Index and type will be created if they do not exist.
  *
  * @param string $index   The name of the index the mapping will be added to.
  * @param string $name    The name of the mapping/type you are creating.
  * @param array  $mapping An array of mapping properties that define the mapping/type.
  *
  * @return array like ['acknowledged' => (Boolean)];
  *
  * @throws ProtectedIndexException When $index starts with 'hercules-'.
  * @throws UsageException When $index, $name, or $mapping are empty/null.
  */
 public function addMapping($index, $name, array $mapping)
 {
     $errorMessages = [];
     if (empty($index)) {
         throw new UsageException('$index cannot be null.');
     }
     //Block mappings from being added to any hercules-* index new or existing.
     if (preg_match('/^(hercules-)/', $index, $matches)) {
         throw new ProtectedIndexException("Mappings cannot be added to protected {$matches}* Indices.");
     }
     //Attempt to create the index. If the index already exists an indexAlreadyExists Exception is thrown
     try {
         $response = $this->client->create($index);
         if ($response['acknowledged'] != true) {
             $errorMessages[] = "The request to create {$index} was not acknowledged.";
         }
     } catch (\Exception $e) {
         //Report error message only if it was not an error stating the index already existed.
         //IndexAlreadyExistsException is one of ES's custom exceptions.
         if (get_class($e) === 'IndexAlreadyExistsException') {
             $errorMessages[] = "Failed to create {$index} with error {$e->getMessage()}.";
         }
     }
     if (empty($name)) {
         $errorMessages[] = '$name cannot = null.';
     }
     if (empty($mapping)) {
         $errorMessages[] = "An empty mapping cannot be created. That doesn't make any sense.";
     }
     if (!empty($errorMessages)) {
         throw new UsageException(implode("\n", $errorMessages));
     }
     $req = ['index' => $index, 'type' => $name, 'body' => $mapping];
     return $this->client->putMapping($req);
 }
开发者ID:Code4HR,项目名称:hercules,代码行数:47,代码来源:ElasticSearchServiceProvider.php

示例2: create

 /**
  * @inheritdoc
  */
 public function create(array $params = [])
 {
     return $this->client->create($params);
 }
开发者ID:nordsoftware,项目名称:lumen-elasticsearch,代码行数:7,代码来源:ElasticsearchService.php


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