[英]Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception
所以我正在使用彈性搜索。
我有這個代碼:
<?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 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
];
(去掉逗號)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.