php - fatal error : Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception

标签 php elasticsearch runtime-error fatal-error

所以我正在使用 Elasticsearch 。

我有这个代码:

    <?php

     error_reporting(E_ALL);ini_set('display_errors', 1);

   require 'vendor/autoload.php';
    use Elasticsearch\ClientBuilder;

  $hosts = [
    'http://localhost:80',        // SSL to localhost
];
$clientBuilder = ClientBuilder::create();   // Instantiate a new ClientBuilder
$clientBuilder->setHosts($hosts);           // Set the hosts
$client = $clientBuilder->build();    
    $params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);

我收到此错误:

fatal error :未捕获 Elasticsearch\Common\Exceptions\BadRequest400Exception: 405 Method Not Allowed Method Not Allowed URL/my_index/my_type/my_id 不允许使用请求的方法 PUT。在 C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php:615 堆栈跟踪:#0 C:\Bitnami\wampstack-7.0.0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php(279): Elasticsearch\Connections\Connection->process4xxError(Array, Array, Array) #1 C:\Bitnami\wampstack-7.0. 0RC7-\apache2\htdocs\vendor\react\promise\src\FulfilledPromise.php(25): Elasticsearch\Connections\Connection->Elasticsearch\Connections{closure}(Array) #2 C:\Bitnami\wampstack-7.0.0RC7 -\apache2\htdocs\vendor\guzzlehttp\ringphp\src\Future\CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NU in C:\Bitnami\wampstack-7.0. 0RC7-\apache2\htdocs\vendor\elasticsearch\elasticsearch\src\Elasticsearch\Connections\Connection.php 行 615

最佳答案

我得到了它!
我只需要改变

  $hosts = [
    'http://localhost:80',        // SSL to localhost
];


  $hosts = [
    'http://localhost:80'        // SSL to localhost
];

(去掉逗号)

关于php - fatal error : Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54595019/

相关文章:

php - 选择介于两次之间的行

elasticsearch - 用kafka接收器在elasticsearch中重命名索引

java - 为什么 Class.newInstance 总是抛出异常?

javascript - 抛出错误后,console.log语句无法打印?

c - 循环中的 opencl 运行时错误 (Clenqueuewritebuffer)

java - 您如何使用 Java 制作网站?

php - 带有 PHPABTest 的 CodeIgniter

php - 静态关键字在 PHP 生成器函数中不起作用

Azure ElasticSearch 配置文件以及如何添加安全性

elasticsearch - Elasticsearch Index Lifecycle Policy无法滚动的问题