D
D
Drum Kit2015-10-31 08:58:05
elasticsearch
Drum Kit, 2015-10-31 08:58:05

How to catch exceptions in Elasticsearch?

I need to catch the errors that elasticsaerch gives,
for example, this and create a log file

Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response [status code] 400 [reason phrase] Bad Request [url] 192.168.1.45:9200/_all/_search ' in vendor/guzzle/guzzle /src/Guzzle/Http/Exception/BadResponseException.php:43 Stack trace: #0 factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response)) #1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event) , 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher)) #2
vendor/symfony/event-dispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher)) #3
vendor/symfony /event-dispatcher/EventDispatcher.php(53): Symfony\Component\EventDispatcher\Event in vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php on line 282

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Keliorw, 2021-11-26
@Keliorw

try {
  $result = $elastic->search($query);
  print_r($result);
}catch (Exception $e){
    print '<pre>';
    print_r($e);
}

Do you want to file file_put_content('file.name', $e);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question