使用PHP在Elasticsearch中搜索时出现错误 [英] Errors upon searching in Elasticsearch using PHP
问题描述
我正在尝试使用PHP搜索索引.我已经下载了供应商文件,并且已经成功建立了连接.但是,我收到一些错误.这些错误并非总是会发生.如果我刷新浏览器几次,我将获得正确的输出.这是我的代码:
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'];
init.php是Elasticsearch的连接文件.刷新屏幕时可能会发生2种不同的输出.第一个输出是正确的输出.另一个只是错误.错误如下:
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:
致命错误:未捕获的Elasticsearch \ Common \ Exceptions \ Missing404Exception:{"statusCode":404,"error":"未找到}在C:\ wamp64 \ www \ DataAggregation \ vendor \ elasticsearch \ elasticsearch \src \ Elasticsearch \ Connections \ Connection.php在第602行
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}在C:\ wamp64 \ www \ DataAggregation \ vendor \ elasticsearch \ elasticsearch \ src \ Elasticsearch \602行上的Connections \ Connection.php
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 \ BadRequest400Exception:在610行上的C:\ wamp64 \ www \ DataAggregation \ vendor \ elasticsearch \ elasticsearch \ src \ Elasticsearch \ Connections \ Connection.php中
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?
推荐答案
似乎您尚未启动Web服务器,启动ES Web服务器以连接php.
It seems you have not started web server, start ES web server to connect with php.
这篇关于使用PHP在Elasticsearch中搜索时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!