laravel5.4 GuzzleHttp\Client 请求中的 get delete 不存在
来源:9-7 使用laravel的Command实现搜索引擎索引和模版的建立

ailyfeng
2017-08-17
在 App\Console\Commands\ESInit中添加handle
运行时报一下错误,这是为什么呢?
[GuzzleHttp\Exception\ClientException]
Client error: `DELETE http://127.0.0.1:9200/_template/tmp` resulted in a `404 Not Found` response:
{"error":{"root_cause":[{"type":"index_template_missing_exception","reason":"index_template [tmp] missing"}],"type":"ind (truncated...)
3回答
-
轩脉刃
2017-08-22
你先把delete的这个代码注释掉运行试一下行不行
122017-11-28 -
慕粉3877875
2019-04-02
php artisan es:init
In RequestException.php line 113:
Server error: `PUT http://127.0.0.1:9200/_template/tmp` resulted in a `500 Internal Server Error` response:
{"error":{"root_cause":[{"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"C:
\\Pro (truncated...)
我是出现这个问题,你上面的我也碰到
022019-12-03 -
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('===============创建索引成功===============');
}
}00
相似问题