ES新建模板时的错误?
来源:9-7 使用laravel的Command实现搜索引擎索引和模版的建立

大礻神
2017-07-04
$ php artisan es:init
报错:
[GuzzleHttp\Exception\ClientException]
Client error: `DELETE http://127.0.0.1:9200/_templete/tmp` resulted in a `400 Bad Request` re
sponse:
No handler found for uri [/_templete/tmp] and method [DELETE]
如果注释$client->delete($url);,又会报错:
[GuzzleHttp\Exception\ClientException]
Client error: `PUT http://127.0.0.1:9200/_templete/tmp` resulted in a `400 Bad Request` respo
nse:
No handler found for uri [/_templete/tmp] and method [PUT]
请问什么原因?
2回答
-
ailyfeng
2017-08-17
<?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 = 'es:init';
/**
* The console command description.
*
* @var string
*/
protected $description = 'init laravel as for post';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//创建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_smart',
'fields' => [
'keyword' => [
'type' => 'keyword'
]
]
]
]
]
]
]
]
];
$client->put($url, $param);
$this->info('===============创建模版成功===============');
//创建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' => [
'enable' => FALSE
]
]
]
]
];
$client->put($url, $param);
$this->info('===============创建索引成功===============');
}
}20 -
轩脉刃
2017-07-07
能贴下你的es:init里面的代码么?感觉是代码有点问题
212017-08-17
相似问题