for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace AmaTeam\ElasticSearch\Client;
use AmaTeam\ElasticSearch\API\Client\MappingClientInterface;
use AmaTeam\ElasticSearch\API\Mapping\MappingInterface;
use AmaTeam\ElasticSearch\Mapping\Mapping;
use AmaTeam\ElasticSearch\Mapping\Type\RootType;
use Elasticsearch\Client;
use Elasticsearch\Common\Exceptions\Missing404Exception;
class MappingClient implements MappingClientInterface
{
/**
* @var Client
*/
private $client;
* @param Client $client
public function __construct(Client $client)
$this->client = $client;
}
public function apply(string $index, string $type, MappingInterface $mapping): void
$serialized = Mapping::asObject($mapping);
unset($serialized->type);
$parameters = [
'index' => $index,
'type' => $type,
'body' => [$type => $serialized]
];
$this
->client
->indices()
->putMapping($parameters);
public function get(string $index, string $type): ?MappingInterface
try {
$data = $this
->getMapping(['index' => $index, 'type' => $type]);
$mapping = $data[$index]['mappings'][$type];
return Mapping::fromArray($mapping)->setType(RootType::ID);
} catch (Missing404Exception $e) {
return null;