Elasticsearch-php: "Incorrect HTTP method for uri" when trying to create an index

Created on 20 Feb 2018  路  4Comments  路  Source: elastic/elasticsearch-php

Summary of problem or feature request

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]

Code snippet of problem

use Elasticsearch\ClientBuilder;

...

$index = ['index' => Configure::read('Elasticsearch.mainIndex')];
$client = ClientBuilder::create()->setHosts(['http://elastic:password@localhost/'])->build();

$client->indices()->create($index);

System details

  • Operating System: Kali GNU/Linux Rolling
  • PHP Version: 7.0.27-1
  • ES-PHP client version: v6.0.1
  • Elasticsearch version: 6.1.2

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 the setHosts() method should handle this better. The URL is not validated hard enough.

All 4 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adoerrES picture adoerrES  路  5Comments

ls
ssanchezromero picture ssanchezromero  路  6Comments

approached picture approached  路  4Comments

thinkspill picture thinkspill  路  3Comments

r0mdau picture r0mdau  路  3Comments