/**
  * Get a new ElasticSearch client with configuration
  * 
  * @author xhinliang
  * @param array $config
  * @return ElasticSearchClient
  * @throws ElasticSearchException
  */
 public static function connection($config = array())
 {
     if (!$config && ($url = getenv('ELASTICSEARCH_URL'))) {
         $config = $url;
     }
     if (is_string($config)) {
         $config = self::parseDsn($config);
     }
     $config = array_merge(self::$_defaults, $config);
     $protocol = $config['protocol'];
     if (!isset(self::$_protocols[$protocol])) {
         throw new ElasticSearchException("Tried to use unknown protocol: {$protocol}");
     }
     $class = self::$_protocols[$protocol];
     if (null !== $config['timeout'] && !is_numeric($config['timeout'])) {
         throw new ElasticSearchException("HTTP timeout should have a numeric value when specified.");
     }
     $server = is_array($config['servers']) ? $config['servers'][0] : $config['servers'];
     list($host, $port) = explode(':', $server);
     $transport = new $class($host, $port, $config['timeout']);
     $client = new self();
     $client->transConstruct($transport, $config['index'], $config['type']);
     $client->configuration($config);
     return $client;
 }