致命错误:未被捕获的Elasticsearch \ Common \ Exceptions \ BadRequest400Exception

时间:2019-02-08 14:56:51

标签: 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);

我收到此错误:

致命错误:未捕获的Elasticsearch \ Common \ Exceptions \ BadRequest400Exception:405不允许使用方法

不允许使用方法

URL / my_index / my_type不允许使用请求的方法PUT / my_id。

在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 \ elast第615

行上的icsearch \ elasticsearch \ src \ Elasticsearch \ Connections \ Connection.php

1 个答案:

答案 0 :(得分:1)

我知道了! 我只需要更改

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

收件人

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

(删除逗号)