查看: 115|回复: 0

[PHP学习] Laravel开发简书es一章问题:access_control_exception

发表于 3 天前

在我的课程中原本使用下面的template的方法来初始化,里面使用了es的一个动态类型推测

  1. $param = [
  2. 'json' => [
  3. 'template' => config('scout.elasticsearch.index'),
  4. 'mappings' => [
  5. '_default_' => [
  6. 'dynamic_templates' => [
  7. [
  8. 'strings' => [
  9. 'match_mapping_type' => 'string',
  10. 'mapping' => [
  11. 'type' => 'text',
  12. 'analyzer' => 'ik_smart',
  13. 'fields' => [
  14. 'keyword' => [
  15. 'type' => 'keyword'
  16. ]
  17. ]
  18. ]
  19. ]
  20. ]
  21. ]
  22. ]
  23. ],
  24. ],
  25. ];
复制代码

后来发现,在java1.9下会出现权限问题问题:

  1. {"error":{"root_cause":[{"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"/Users/ (truncated...)
复制代码

解决的方法:

  1. <?php
  2. namespace App\Console\Commands;
  3. use GuzzleHttp\Client;
  4. use Illuminate\Console\Command;
  5. class ESInit extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'es:init';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'init laravel es for post';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. // 创建template
  36. $client = new Client();
  37. $url = config('scout.elasticsearch.hosts')[0] . '/_template/tmp';
  38. $client->delete($url);
  39. $param = [
  40. 'json' => [
  41. 'template' => config('scout.elasticsearch.index'),
  42. 'mappings' => [
  43. 'posts' => [
  44. 'properties' => [
  45. 'title' => [
  46. 'type' => 'text',
  47. 'analyzer' => 'ik_smart',
  48. ],
  49. 'content' => [
  50. 'type' => 'text',
  51. 'analyzer' => 'ik_smart',
  52. ]
  53. ]
  54. ]
  55. ],
  56. ],
  57. ];
  58. $client->put($url, $param);
  59. $this->info("========= 创建模版成功 ========");
  60. // 创建index
  61. $url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index');
  62. $client->delete($url);
  63. $param = [
  64. 'json' => [
  65. 'settings' => [
  66. 'refresh_interval' => '5s',
  67. 'number_of_shards' => 1,
  68. 'number_of_replicas' => 0,
  69. ],
  70. 'mappings' => [
  71. 'posts' => [
  72. '_all' => [
  73. 'enabled' => false
  74. ]
  75. ]
  76. ]
  77. ]
  78. ];
  79. $client->put($url, $param);
  80. $this->info("========= 创建索引成功 ========");
  81. }
  82. }
复制代码


回复

使用道具 举报