使用laravel的Command实现搜索引擎索引和模板的建立
创建command,初始化es
创建成功后,可通过php artisan 查看到
php artisan make:command ESInit
安装guzzle
composer require guzzlehttp/guzzle
配置
app/console/Commands/ESInit.php
use GuzzleHttp\Client;
...
protected $signature = 'es:init'; //以什么命令来初始化
protected $description = 'elasticsearch init command'; //描述
//实际要做的事情
public function handle()
{
$client = new Client();
// 创建模版
$url = config('scout.elasticsearch.hosts')[0] . '/_template/tmp';
$client->delete($url);
$client->put($url, [
'json' => [
'template' => config('scout.elasticsearch.index'),
'settings' => [
'number_of_shards' => 1
],
'mappings' => [
'_default_' => [
'_all' => [
'enabled' => true
],
'dynamic_templates' => [
[
'strings' => [
'match_mapping_type' => 'string',
'mapping' => [
'type' => 'text',
'analyzer' => 'ik_smart',
'ignore_above' => 256,
'fields' => [
'keyword' => [
'type' => 'keyword'
]
]
]
]
]
]
]
]
]
]);
$this->info('**** 创建模板成功 ****'); $url = config('scout.elasticsearch.hosts')[0] . '/' . config('scout.elasticsearch.index');
$client->delete($url);
$client->put($url, [
'json' => [
'settings' => [
'refresh_interval' => '5s',
'number_of_shards' => 1,
'number_of_replicas' => 0,
],
'mappings' => [
'_default_' => [
'_all' => [
'enabled' => false
]
]
]
]
]);
$this->info('**** 创建index成功 ****');
}
挂载
app/console/Kernel.php
$commands = [\App\Console\Commands\ESInit::class];
使用laravel的Command实现搜索引擎索引和模板的建立的更多相关文章
- 最全BT磁力搜索引擎索引(整理分享,不断更新...)
最全BT磁力搜索引擎索引(整理分享,不断更新...) btkitty:http://cnbtkitty.com/(知名的BT磁力搜索,资源很多) idope.se:https://idope.se/( ...
- 解决HubbleDotNet搜索引擎索引数据不全的问题
HubbleDotnet是国产.NET平台搜索引擎的翘楚,开放源代码,使用方便,不过我一直在非生产环境下使用.官方网页在HubbleDotNet开源全文搜索数据库项目--技术详解. 以前当数据库使用M ...
- 最全BT磁力搜索引擎索引(整理分享,每日更新)
btaa.xyz:http://www.veee.xyz/(可以访问,知名的BT磁力搜索,资源多,建议手机访问) 以下无法访问 idope.se:https://idope.se/(无法访问,资源丰富 ...
- Python—一个简单搜索引擎索引库
因为课业要求,搭建一个简单的搜索引擎,找了一些相关资料并进行了部分优化(坑有点多) 一.数据 数据是网络上爬取的旅游相关的攻略页面 这个是travels表,在索引中主要用到id和url两个字段. 页面 ...
- Laravel 中使用 swoole 项目实战开发案例一 (建立 swoole 和前端通信)
1 开发需要环境 工欲善其事,必先利其器.在正式开发之前我们检查好需要安装的拓展,不要开发中发现这些问题,打断思路影响我们的开发效率. 安装 swoole 拓展包 安装 redis 拓展包 安装 la ...
- sqlserver查看索引使用情况以及建立丢失的索引
--查看表的索引使用情况SELECT TOP 1000o.name AS 表名, i.name AS 索引名, i.index_id AS 索引id, dm_ius.user_seeks AS 搜索次 ...
- poj 3164 Command Network(最小树形图模板)
Command Network http://poj.org/problem?id=3164 Time Limit: 1000MS Memory Limit: 131072K Total Subm ...
- es的索引库模板
在实际的生产中,如果要插入大批量数据的时候需要使用多个索引库,如果我们还是手工指定每个索引的配置信息settings和mappings,是非常耗时的: 针对这种情况,es有index template ...
- POJ 3164 Command Network(最小树形图模板题+详解)
http://poj.org/problem?id=3164 题意: 求最小树形图. 思路: 套模板. 引用一下来自大神博客的讲解:http://www.cnblogs.com/acjiumeng/p ...
随机推荐
- sublime text3的安装使用
1.下载网址:https://www.sublimetext.com/3 2.编译环境配置:https://jingyan.baidu.com/article/6f2f55a155a7d1b5b93e ...
- BDB c++例子,从源码编译到运行
第一步先下载源码,解压后 ./dist/configure --enable-cxx编译,然后make, make install --enable-cxx To build the Berkeley ...
- LA-4356&&hdu-2469 (极角排序+扫描线)
题目链接: Fire-Control System Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- Asp.net MVC 使用PagedList(新的已更名 为X.PagedList.Mvc) 分页
在asp.net mvc 中,可以bootstrap来作为界面,自己来写分页程序.也可以使用PagedList(作者已更名为 X.PagedList.Mvc)来分页. 1.首先,在NuGet程序包管理 ...
- NOI前总结:点分治
点分治: 点分治的题目基本一样,都是路径计数. 其复杂度的保证是依靠 $O(n)$ 找重心的,每一次至少将问题规模减小为原先的$1/2$. 找重心我喜欢$BFS$防止爆栈. int Root(int ...
- eclipse与maven配置
一.配置maven环境 电脑上需安装java环境,安装JDK1.7 + 版本 (将JAVA_HOME/bin 配置环境变量path ) 配置 MAVEN_HOME 将 %MAVEN_HOME%/bin ...
- 任务27:Middleware管道介绍
任务27:Middleware管道介绍 HttpContext 图中注册了三个中间件,所有httpContext就会在这三个管道上都执行HttpContext,会在Reponse里面写一些东西.所有东 ...
- Go语言中的代码重用 - 继承还是组合?
故事要从我在一个项目中,想要假装的专业一点而遇到的一个陷阱说起. 代码重用 在这个项目中,我们已经有了类似如下的代码: package main import ( "fmt" ) ...
- 洛谷 - P1379 - 八数码难题 - bfs
https://www.luogu.org/problemnew/show/P1379 #include <bits/stdc++.h> using namespace std; #def ...
- Swift3.0 字符串(string)
string常用的一些操作方式 //字符串 //1.初始化字符串 //1.1通过字面量赋值的方式初始化字符串 let tempStrig = "this is temp string&quo ...