本文整理匯總了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);
}
示例2: create
/**
* @inheritdoc
*/
public function create(array $params = [])
{
return $this->client->create($params);
}