我重新安装了elasticsearch 5.0.0和elasticsearch-php。我正在尝试创建索引。
我运行this索引管理文档中的代码:
$client = ClientBuilder::create()->build();
$params = [
'index' => 'my_index'
];
// Create the index
$response = $client->indices()->create($params);
而且有效。我成功创建了索引。
我尝试下一个代码片段:
$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);
我得到:
Elasticsearch\Common\Exceptions\BadRequest400Exception with message 'No handler found for uri [/my_index] and method [POST]'
有什么想法吗?
当我使用elasticsearch 2.0时,该代码可以正常工作
编辑:我发现了this问题,所以这可能是elasticsearch-php的问题,或者我需要更新它
我正在使用的elasticquent,我刚刚意识到需要elasticsearch-php版本<2.2,所以这是导致问题的原因
最佳答案
查看错误消息:
No handler found for uri [/my_index] and method [POST]
这意味着您的创建索引调用在后台使用了HTTP POST方法。在以前的版本(即5.0之前的版本)中,elasticsearch-php客户端曾经使用HTTP POST创建索引,但是由于ES 5.0仅接受HTTP PUT来创建新索引。
九月的This change再次使此create调用与ES 5.0兼容。
唯一可能的解释是,您已经安装了ES 5.0,但是没有安装Elasticsearch-php客户端的5.0版本。
由于您正在运行Elasticquent的doesn't yet support ES 5,因此可以通过修改
Endpoints/Indices/Create.getMethod()
方法以始终返回PUT
而不是POST
来暂时解决此问题,并且您的调用将再次起作用,但是您可能会遇到其他不兼容问题。
关于php - elasticsearch-php创建索引返回\BadRequest400Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40619182/