protected function createElasticsearchClient(ContainerBuilder $container, $name, $config)
    {
        $definitionId = 'm6web_elasticsearch.client.'.$name;

        $handlerId = $this->createHandler($container, $config, $definitionId);

        $clientConfig = [
            'hosts'   => $config['hosts'],
            'handler' => new Reference($handlerId),
        ];

        if (isset($config['retries'])) {
            $clientConfig['retries'] = $config['retries'];
        }

        if (isset($config['logger'])) {
            $clientConfig['logger'] = new Reference($config['logger']);
        }

        if (!empty($config['connectionPoolClass'])) {
            $clientConfig['connectionPool'] = $config['connectionPoolClass'];
        }

        if (!empty($config['selectorClass'])) {
            $clientConfig['selector'] = $config['selectorClass'];
        }

        if (!empty($config['connectionParams'])) {
            $clientConfig['connectionParams'] = $config['connectionParams'];
        }

        $definition = (new Definition($config['client_class']))
            ->setArguments([$clientConfig]);
        $this->setFactoryToDefinition($config['clientBuilderClass'], 'fromConfig', $definition);

        $container->setDefinition($definitionId, $definition);

        if ($container->getParameter('kernel.debug')) {
            $this->createDataCollector($container);
        }
    }