关于es:init报错
来源:9-7 使用laravel的Command实现搜索引擎索引和模版的建立
TypeMoon
2017-12-31
如果注释掉 2个 $client->put($url,$param); 会正常

如果去掉注释 则会失败
Client error: `PUT http://127.0.0.1:9200/template/tmp` resulted in a `400 Bad Request` response:
No handler found for uri [/template/tmp] and method [PUT]

其他同学的问题我也看了 貌似解决不了!
这是 es:init的代码!
<?php
namespace App\Console\Commands;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
class ESInit extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
//protected $signature = 'command:name';
protected $signature = 'es:init';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Inir Laravel es for post';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
* 实际要做的事
* @return mixed
*/
public function handle()
{
// TO DO
//创建template
$client = new Client();
$url = config('scout.elasticsearch.hosts')[0].'/template/tmp';
//$client->delete($url);
$param = [
'json'=>[
'template'=>config('scout.elasticsearch.index'),
'mappings'=>[
'_default_'=>[
'dynamic_templates'=>[
[
'strings'=>[
'match_mapping_type'=>'string',
'mapping'=>[
'type'=>'text',
'analyzer'=>'ik_max_word',
'fields'=>[
'keyword'=>[
'type'=>'keyword'
]
]
]
]
]
]
]
],
],
];
$client->put($url,$param);
$this->info("=========Template Successful!=========");
// 创建index
$url = config('scout.elasticsearch.hosts')[0].'/'.config('scout.elasticsearch.index');
//$client->delete($url);
$param = [
'json'=>[
'settings'=>[
'refresh_interval'=>'5s',//更新时间
'number_of_shards'=>1,
'number_of_replicas'=>0
],
'mappings'=>[
'_default_'=>[
'_all'=>[
'enabled'=>true//是否显示
]
]
]
]
];
$client->put($url,$param);
$this->info("=========Index Successful!=========");
}
}写回答
2回答
-
你好,留一下你的qq,我联系你具体看下,这个我也看不出来是什么问题,不知道是否和环境有关
012018-03-28 -
TypeMoon
提问者
2018-03-28
已解决
00
相似问题