/**
  * Constructor
  *
  * @param Client  $client    The elastic search client.
  * @param string  $indexName The elastic search index name.
  * @param boolean $delete    Delete the index if already exist (default = false).
  */
 public function __construct(Client $client, $indexName, $delete = false)
 {
     $this->client = $client;
     $this->index = $client->getIndex($indexName);
     // Checks if the given index is already created
     if (!$this->index->exists($indexName)) {
         // Create the index.
         $this->index->create(array(), $delete);
     }
 }
 /**
  *
  * Create single index
  * @param \Elastica\Client $client
  * @param string $indexName
  * @param array $params
  * @param boolean $recreate
  * @throws Exception
  */
 protected function createSingleIndex(\Elastica\Client $client, $indexName, $params = array(), $recreate = false)
 {
     try {
         // create an elastic index
         $settings = $this->getIndexSetting($indexName, $params);
         $index = new \Elastica\Index($client, $indexName);
         $index->create($settings, $recreate);
     } catch (Exception $e) {
         // ignore the IndexAlreadyExistsException exception
         if (strpos($e->getMessage(), 'IndexAlreadyExistsException') === false) {
             throw $e;
         }
     }
     return $index;
 }