es:init 报错

来源:9-7 使用laravel的Command实现搜索引擎索引和模版的建立

炜炜炜

2018-02-13

1,按照视频的代码,执行 php artisan es:init   --->404

        http://img.mukewang.com/szimg/5a8254000001d89f18800212.jpg

2,看到其他同学的问题,注释掉 两处的 $client->delete($url)      ---->500

        http://img.mukewang.com/szimg/5a8254720001baf818720226.jpg

浏览器访问上述报错链接

http://img.mukewang.com/szimg/5a8254980001340607480302.jpg

我的打码:

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


写回答

1回答

轩脉刃

2018-02-24

你可以看看这篇文章先:https://www.imooc.com/article/22449

0
1
慕仙1485875
不行呢
2019-12-03
共1条回复

Laravel快速开发简书

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

1218 学习 · 613 问题

查看课程