2016-11-15 89 views
1

我有全新安装的elasticsearch 5.0.0和elasticsearch-php。我正在尝试创建索引。elasticsearch-php创建索引返回 BadRequest400Exception

我跑从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,所以这是什么原因造成的问题

+0

你可以尝试改变放? ''“error”:{“root_cause”:[{“type”:} - > putSettings($ params);' –

+0

返回Elasticsearch \ Common \ Exceptions \ Missing404Exception。 “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}' ' – user3494047

回答

1

望着错误消息:

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

这意味着您的create index调用在引擎盖下使用HTTP POST方法。在以前的版本(即5.0之前版本)中,elasticsearch-php客户端用于使用HTTP POST创建索引,但自ES 5.0以来,仅接受HTTP PUT以创建新索引。

This change回到9月再次使这个创建调用与ES 5.0兼容。

唯一可能的解释是您已经安装了ES 5.0,但是您没有安装5.0版本的elasticsearch-php客户端。

既然你正在运行Elasticquent其中doesn't yet support ES 5,您可以暂时去解决这个问题,通过修改Endpoints/Indices/Create.getMethod()方法总是返回PUT,而不是POST和您的通话将重新工作,但你可能会遇到其他的不兼容。