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的这个代码注释掉运行试一下行不行

1
2
轩脉刃
回复
慕码人3572504
put不注释掉。这里的代码忘记考虑第一次没有模版的时候的异常处理。先把delete注释掉,然后运行一次put,然后就有模版了,后面再把delete的注释去掉,就可以运行了
2017-11-28
共2条回复

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

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

0
2
慕仙1485875
回复
轩脉刃
不行呢。老师
2019-12-03
共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('===============创建索引成功===============');
   }
 }

0
0

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程