當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::putMapping方法代碼示例

本文整理匯總了PHP中Elasticsearch\Client::putMapping方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::putMapping方法的具體用法?PHP Client::putMapping怎麽用?PHP Client::putMapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Elasticsearch\Client的用法示例。


在下文中一共展示了Client::putMapping方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的Elasticsearch\Client::putMapping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。