Trying to create an elasticsearch index via the PHP client throws this exception:
Exception: {"error":"Incorrect HTTP method for uri [//main_index] and method [PUT], allowed: [POST]","status":405} in [/var/www/html/project/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php, line 615]
use Elasticsearch\ClientBuilder;
...
$index = ['index' => Configure::read('Elasticsearch.mainIndex')];
$client = ClientBuilder::create()->setHosts(['http://elastic:password@localhost/'])->build();
$client->indices()->create($index);
I had the same problem.
The problem is the trailing / in your host URL. The error message is not helpful at this point. I think the setHosts() method should handle this better. The URL is not validated hard enough.
Thanks a lot @toki030 . Removing the trailing forward-slash worked!
@toki030 Thanks! That worked.
My issue was specifying a body with the get. removed that and it worked
Most helpful comment
I had the same problem.
The problem is the trailing
/in your host URL. The error message is not helpful at this point. I think thesetHosts()method should handle this better. The URL is not validated hard enough.