user3494047
user3494047

Reputation: 1693

elasticsearch-php create index returns \BadRequest400Exception

I have a fresh installation of elasticsearch 5.0.0 and elasticsearch-php . I am trying to create an index.

I run the code from this index management documentation:

$client = ClientBuilder::create()->build();
$params = [
    'index' => 'my_index'
];

// Create the index
$response = $client->indices()->create($params);

and it works. I create an index successfully.

I try the next code snippet:

$client = ClientBuilder::create()->build();
$params = [
    'index' => 'my_index',
    'body' => [
        'settings' => [
            'number_of_shards' => 3,
            'number_of_replicas' => 2
        ],
        'mappings' => [
            'my_type' => [
                '_source' => [
                    'enabled' => true
                ],
                'properties' => [
                    'first_name' => [
                        'type' => 'string',
                        'analyzer' => 'standard'
                    ],
                    'age' => [
                        'type' => 'integer'
                    ]
                ]
            ]
        ]
    ]
];


// Create the index with mappings and settings now
$response = $client->indices()->create($params);

and I get:

Elasticsearch\Common\Exceptions\BadRequest400Exception with message 'No handler found for uri [/my_index] and method [POST]'

any ideas why?

This code used to work when I used elasticsearch 2.0

EDIT: I found this question so either it is a problem with elasticsearch-php or I need to update it I guess

I am using elasticquent which I have just realized requires elasticsearch-php version <2.2 so this is what is causing the problem

Upvotes: 1

Views: 1348

Answers (1)

Val
Val

Reputation: 217274

Looking at the error message:

No handler found for uri [/my_index] and method [POST]

This means that your create index call is using an HTTP POST method under the hood. In previous versions (i.e. pre 5.0), the elasticsearch-php client used to create indices with an HTTP POST but since ES 5.0 only HTTP PUT is accepted to create a new index.

This change back in september made this create call compatible with ES 5.0 again.

The only possible explanation is that you have ES 5.0 installed but you don't have the 5.0 version of the elasticsearch-php client installed.

Since you're running Elasticquent which doesn't yet support ES 5, you can temporarily go around this issue by modifying the Endpoints/Indices/Create.getMethod() method to always return PUT instead of POST and your call will work again, but you might run into other incompatibilities.

Upvotes: 1

Related Questions