예제 #1
0
 /**
  * performs sending the request
  *
  * @param RequestInterface $request
  *
  * @throws Exception\ClientException
  * @throws Exception\RequestException
  * @return ResponseInterface
  * @author Daniel Wendlandt
  */
 public function send(RequestInterface $request)
 {
     $this->logger->info('request: ' . get_class($request), $this->generateLogRequestData($request));
     try {
         $timeTaken = microtime(true);
         $response = $this->client->send($request);
         $this->logger->debug('time taken: ' . (microtime(true) - $timeTaken) . 's (' . get_class($request) . ')');
         $this->logger->debug('response: ' . get_class($response), $this->generateLogResponseData($response));
         return $response;
     } catch (ClientException $exception) {
         $this->logger->error($exception->getMessage(), array('code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'message' => $exception->getMessage()));
         throw $exception;
     }
 }
 /**
  * performs sending the request
  *
  * @param RequestInterface $request
  *
  * @throws ClientException
  * @throws RequestException
  * @return ResponseInterface
  * @author Daniel Wendlandt
  */
 public function send(RequestInterface $request)
 {
     $timeTaken = microtime(true);
     try {
         $response = $this->client->send($request);
         if (null !== $this->dataCollector) {
             $this->dataCollector->add(ElasticsearchDataCollector::TYPE_SUCCESS, (microtime(true) - $timeTaken) * 1000, $request, $response);
         }
         return $response;
     } catch (ClientException $exception) {
         if (null !== $this->dataCollector) {
             $this->dataCollector->add(ElasticsearchDataCollector::TYPE_ERROR, (microtime(true) - $timeTaken) * 1000, $request);
         }
         throw $exception;
     }
 }
예제 #3
0
 /**
  * Gets the source of a single document
  *
  * @param string $index
  * @param string $type
  * @param string $id
  * @return array|object
  * @throws \Elastification\Client\Exception\RequestException
  * @throws \Elastification\Client\Exception\ResponseException
  */
 protected function getDocument($index, $type, $id)
 {
     $getDocumentRequest = new GetDocumentRequest($index, $type, $this->serializer);
     $getDocumentRequest->setId($id);
     /** @var DocumentResponse $response */
     $response = $this->client->send($getDocumentRequest);
     return $response->getSource();
 }