0
votes

I am trying to search through my index using PHP. I have downloaded the vendor files and I have built the connection successfully. However, I am receiving some errors. These errors don't always occur though. If I refresh the browser a couple of times, I will get the correct output. Here's my code:

require_once 'init.php';

$json = '{"aggs": { "group_by_date": { "terms": { "field": "arrivalDate" } } } }';

    $params = [
        'index' => 'pickups',
        'type' => 'external',
        'body' => $json 
        ];
    
$results = $es->search($params);

echo $results['hits']['total'];

The init.php is the connection file to Elasticsearch. There are 2 different outputs that may occur upon refreshing the screen. The first output is the correct output. The other is just errors. Here are the errors:

Fatal error: Uncaught Elasticsearch\Common\Exceptions\Missing404Exception: {"statusCode":404,"error":"Not Found"} in C:\wamp64\www\DataAggregation\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php on line 602

Elasticsearch\Common\Exceptions\Missing404Exception: {"statusCode":404,"error":"Not Found"} in C:\wamp64\www\DataAggregation\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php on line 602

Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: in C:\wamp64\www\DataAggregation\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php on line 610

What are the cause of these errors and how can I fix them?

1

1 Answers

0
votes

It seems you have not started web server, start ES web server to connect with php.