php - elasticsearch-php创建索引返回\BadRequest400Exception

标签 php elasticsearch

我重新安装了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/

相关文章:

php - 智能卡启用在 IIS 6 上托管的 PHP 站点?

elasticsearch - 计算两个地理位置的距离并使用kibana进行可视化

c# - ElasticSearch 查询结果是否缓存?

node.js - 如何将 Winston 日志记录集成到 Logstash-kibana 中

search - ElasticSearch POST with json search body vs GET with json in url

php - 主题更新时,子主题中的 header.php 会更新吗?

javascript - 为什么在以下场景中没有设置 href 属性?

json - 在哪里找到ElasticSearch的数据

php - 如何将一个表中的ID替换为另一表中的相应值?

php - PHP中如何在循环外访问while数组