请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

laravel5.4 GuzzleHttp\Client 请求中的 get delete 不存在

                                                                                                                                      
在 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

3回答

轩脉刃 2017-08-22 20:52:05

你先把delete的这个代码注释掉运行试一下行不行

1 回复 有任何疑惑可以回复我~
  • delete方法和put方法都不能用啊,,,delete方法注释掉,因为本来就没有模板,是可行的,但是put方法要写入啊,如果也注释掉的话,这段代码就没有意义了
    回复 有任何疑惑可以回复我~ 2017-11-27 10:33:01
  • put不注释掉。这里的代码忘记考虑第一次没有模版的时候的异常处理。先把delete注释掉,然后运行一次put,然后就有模版了,后面再把delete的注释去掉,就可以运行了
    回复 有任何疑惑可以回复我~ 2017-11-28 07:28:35
慕粉3877875 2019-04-02 00:03:08

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...)

我是出现这个问题,你上面的我也碰到

0 回复 有任何疑惑可以回复我~
  • http://www.imooc.com/article/22449 这个看看
    回复 有任何疑惑可以回复我~ 2019-04-04 16:17:20
  • 不行呢。老师
    回复 有任何疑惑可以回复我~ 2019-12-03 23:08:48
提问者 ailyfeng 2017-08-17 16:58:19

<?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('===============创建索引成功===============');
   }
 }

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信