继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Laravel开发简书es一章问题:access_control_exception

轩脉刃
关注TA
已关注
手记 3
粉丝 381
获赞 135

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

$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'
                                            ]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],
            ],
        ];

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

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

解决的方法:

<?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 es 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';

        try {
            $client->delete($url);
        } catch (\Exception $e) {
            $this->info("===delete模版出现错误==" . $e->getMessage());
        }

        $param = [
            'json' => [
                'template' => config('scout.elasticsearch.index'),
                'mappings' => [
                    'posts' => [
                        'properties' => [
                            'title' => [
                                'type' => 'text',
                                'analyzer' => 'ik_max_word',
                            ],
                            'content' => [
                                'type' => 'text',
                                'analyzer' => 'ik_max_word',
                            ]
                        ]
                    ]
                ],
            ],
        ];
        try {
            $client->put($url, $param);
        } catch (\Exception $e) {
            $this->info("===put模版出现错误==" . $e->getMessage());
        }

        $this->info("========= 创建模版成功 ========");

        // 创建index
        $url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index');
        try {
            $client->delete($url);
        } catch (\Exception $e) {
            $this->info("===delete索引出现错误==" . $e->getMessage());
        }
        $param = [
            'json' => [
                'settings' => [
                    'refresh_interval' => '5s',
                    'number_of_shards' => 1,
                    'number_of_replicas' => 0,
                ],
                'mappings' => [
                    'posts' => [
                        '_all' => [
                            'enabled' => false
                        ]
                    ]
                ]
            ]
        ];
        try {
            $client->put($url, $param);
        } catch (\Exception $e) {
            $this->info("===put索引出现错误==" . $e->getMessage());
        }

        $this->info("========= 创建索引成功 ========");
    }
}
打开App,阅读手记
4人推荐
发表评论
随时随地看视频慕课网APP

热门评论

老师就算改成了你这个样子,还是不可以啊,还是提示access_control_exception,这要怎么办啊

我的jdk版本是1.8的,https://img4.mukewang.com/5d6335de0001ece911230090.jpg

改成了你的样子以为也不行,

https://img4.mukewang.com/5d6336bd000153a911070378.jpg

又一次php artisan es:init,

https://img.mukewang.com/5d63371300010ae303070112.jpg

这样算成功吧,老师。


我看了es 那个 插件 ,如果数据量庞大的情况下 from size 好像不行了   怎么使用scroll 处理分页

查看全部评论