Exemplo n.º 1
0
 /**
  * send a request to elasticsearch
  * @param array $params
  *
  * @return array
  */
 protected function sendRequest(array $params)
 {
     /**
      * @var $esClient \Elasticsearch\Client
      */
     // ElasticSearch Client
     //        $esClient = $this->tenantConfig->getTenantWorker()->getElasticSearchClient();
     // Zend HTTP Client
     $config = $this->tenantConfig->getElasticSearchClientParams();
     $esClient = new Zend_Http_Client(sprintf('http://%s:9200/%s/%s/_search?%s', $config['hosts'][0], $params['index'], $params['type'], $params['search_type'] ?: ''));
     if ($esClient instanceof \Elasticsearch\Client) {
         $result = $esClient->search($params);
     } else {
         if ($esClient instanceof Zend_Http_Client) {
             $esClient->setMethod(Zend_Http_Client::GET);
             $esClient->setRawData(json_encode($params['body']));
             $result = $esClient->request();
             $result = json_decode($result->getBody(), true);
         }
     }
     return $result;
 }