1

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

2
  • Can you try changing to put ? $response = $client->indices()->putSettings($params); Commented Nov 15, 2016 at 20:43
  • that returns Elasticsearch\Common\Exceptions\Missing404Exception with message '{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"my_index","index_uuid":"_na_","index":"my_index"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"my_index","index_uuid":"_na_","index":"my_index"},"status":404}' Commented Nov 15, 2016 at 20:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.