Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词
1.下载安装java, elasticsearch和kibana
apt-get install default-jre default-jdk
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.2.deb
dpkg -i elasticsearch-5.4..deb
wget https://artifacts.elastic.co/downloads/kibana/kibana-5.4.2-amd64.deb
dpkg -i kibana-5.4.-amd64.deb
2.安装中文分词插件,包括elasticsearch原生的中文分词icu和smartcn,以及第三方中文分词ik、拼音分词pinyin、繁简转换stconvert。
/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-icu
/usr/share/elasticsearch/bin/elasticsearch-plugin install analysis-smartcn
wget https://github.com/medcl/elasticsearch-analysisi-stconvert/releases/download/v5.4.2/elasticsearch-analysisi-stconvert-5.4.2.zip
/usr/share/elasticsearch/bin/elasticsearch-plugin install file:///{path}/elasticsearch-analysis-stconvert-5.4.2.zip
wget https://github.com/medcl/elasticsearch-analysisi-ik/releases/download/v5.4.2/elasticsearch-analysis-ik-5.4.2.zip
unzip elasticsearch-analysis-ik-5.4..zip -d /usr/share/elasticsearch/plugins/analysis-ik
wget https://github.com/medcl/elasticsearch-analysisi-pinyin/releases/download/v5.4.2/elasticsearch-analysis-pinyin-5.4.2.zip
unzip elasticsearch-analysis-pinyin-5.4..zip -d /usr/share/elasticsearch/plugins/analysis-pinyin
3.启动服务器
service elasticsearch start
service kibana start
4.在kibana的Dev Tools中测试,地址为http://localhost:5601
大体上可以将Elasticsearch理解为一个RDBMS(关系型数据库,比如MySQL),那么index 就相当于数据库实例,type可以理解为表。
Mapping定义了type中的诸多字段的数据类型以及这些字段如何被Elasticsearch处理,比如一个字段是否可以查询以及如何分词等。
analyzer=char_filter+tokenizer+token_filter按顺序执行
icu提供tokenizer: icu_tokenizer
smartcn提供analyzer: smartcn and tokenizer: smartcn_tokenizer
ik提供analyzer: ik_smart , ik_max_word and tokenizer: ik_smart , ik_max_word
pinyin提供analyzer: pinyin , tokenizer: pinyin and token-filter: pinyin
stconvert提供analyzer: stconvert, tokenizer: stconvert, token-filter: stconvert, and char-filter: stconvert
PUT /stconvert/
{
"settings" : {
"analysis" : {
"analyzer" : {
"tsconvert" : {
"tokenizer" : "tsconvert"
}
"tsconvert_icu_pinyin" : {
"char_filter" : ["tsconvert"],
"tokenizer" : "icu_tokenizer",
"filter" : ["pinyin"]
}
},
"tokenizer" : {
"tsconvert" : {
"type" : "stconvert",
"delimiter" : "#",
"keep_both" : false,
"convert_type" : "t2s"
}
},
"char_filter" : {
"tsconvert" : {
"type" : "stconvert",
"delimiter" : "#",
"keep_both" : false,
"convert_type" : "t2s"
}
}
}
},
"mappings":{
"test":{
"properties":{
"title": {
"type":"text",
"analyzer":"tsconvert_icu_pinyin"
}
}
}
}
}
}
GET /stconvert/_analyze?pretty
{
"analyzer": "tsconvert_icu_pinyin",
"text": ["狼藉藉口,北京国際電視檯"]
}
PUT /stconvert/test/
{
"title":"狼藉藉口,北京国际电视台"
}
PUT /stconvert/test/
{
"title":"狼藉借口,中央國際電視檯"
}
GET /stconvert/test/_search
{
"query":{
"match":{
"title":"北京ds"
}
}
}
5.安装composer, elasticsearch-php和php的curl扩展
cd /var/www/html
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php composer.phar require "elasticsearch/elasticsearch": "~5.0"
apt-get install php-curl
在/etc/php/7.0/fpm/php.ini中去掉 ;extension=php_curl.dll 前的分号,重启服务
6.测试php搜索elasticsearch
<?php
require 'vendor/autoload.php';
use Elasticsearch\ClientBuilder;
$hosts=['localhost'];
$client = ClientBuilder::create() // Instantiate a new ClientBuilder
->setHosts($hosts) // Set the hosts
->build(); // Build the client object
$searchParams = [
'index' => 'stconvert',
'type' => 'test',
'body' => [
'query' => [
'match' => [
'title' => '北京ds'
]
]
]
];
try {
$results = $client->search($searchParams);
} catch (Elasticsearch\Common\Exceptions\TransportException $e) {
$previous = $e->getPrevious();
if ($previous instanceof Elasticsearch\Common\Exceptions\MaxRetriesException) {
echo "Max retries!";
}
}
print_r($results);
?>
elasticsearch的帮助文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
elasticsearch-php的帮助文档:https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
Ubuntu16.04下安装elasticsearch+kibana实现php客户端的中文分词的更多相关文章
- Ubuntu16.04下安装xunsearch+opencc实现php客户端的中文分词
1.准备服务器环境 apt-get install apache2 php mysql-server apt-get install mysql-client phpmyadmin apt-get i ...
- Ubuntu16.04下安装数据库oracle客户端
在Ubuntu16.04下安装oracle数据库客户端,使Django项目连接到远程Oracle数据库. 1.下载oracle客户端安装包: 进入官网http://www.oracle.com/tec ...
- Ubuntu16.04下安装redis
Ubuntu16.04下安装redis 保证网络畅通,选定好下载工作路径,执行以下命令下载redis-3.2.6: sudo wget http://download.redis.io/release ...
- docker学习笔记(一)—— ubuntu16.04下安装docker
docker学习笔记(一)—— ubuntu16.04下安装docker 原创 2018年03月01日 14:53:00 标签: docker / ubuntu 1682 本文开发环境为Ubuntu ...
- ubuntu16.04下安装artoolkit5
目前对AR技术的常见理解就是CV(Computer Vision)+CG(Computer Graphic).CV的方法很多,简单些比如FREAK+ICP(ARToolKit中的NFT),复杂些就是S ...
- Ubuntu16.04下安装多版本cuda和cudnn
Ubuntu16.04下安装多版本cuda和cudnn 原文 https://blog.csdn.net/tunhuzhuang1836/article/details/79545625 前言 因为之 ...
- Ubuntu18.04下安装Sublime Text3并解决不能输入中文
Ubuntu18.04下安装Sublime Text3并解决不能输入中文! 废话不多说,直接按顺序执行下面命令开始安装! wget -qO - https://download.sublimetext ...
- Ubuntu16.04下安装Hadoop
一.记录理由 刚开始只是想要学习怎么使用Hive的.想着安装应该很简单,没想到花了整整一天的时间来安装,为了避免下次犯同样的错误,特此记录. 二.安装Hadoop 网上教你怎么安装Hadoop的文章有 ...
- Ubuntu16.04下安装texlive
Ubuntu 16.04下安装texlive的步骤如下: 1.下载texlive 打开终端输入:sudo apt-get install texlive-full #下载这一过程会持续10-20分钟 ...
随机推荐
- Python01(linux基础)
聊一聊计算机 CPU,电源相关,时钟部分(主频),存储器,输入输出系统 计算机记忆装置:存储器分两大类:1.内存Ram(速度快,容量小(相对),断电后内容丢失) 非持久性记忆存储器2.如:硬盘,(速度 ...
- 汉诺塔III
题目描述: 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下.由小到大顺序串着由64个圆盘构成的塔.目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动 ...
- (原创)Spice 网表范例
一.常规网表 Inverter .lib "D:\lib\l0040ll_v1p4_1r.lib" TT .param SUPPLY=.1V .param T=10ns .para ...
- jq常用
1.文本框.密码框.隐藏域.文本域(id换成对应的,value属性存在,才能利用attr(‘value’) 获取值,否则返回undefined): 1.1 获取—>$(“#text”).val( ...
- @RequestParam 和 @ PathVariable 的区别
@RequestParam 和 @ PathVariable 的区别http://localhost:8080/Springmvc/user/page.do?pageSize=3&pageNo ...
- php中的内存管理的介绍(转)
本篇文章给大家带来的内容是关于php中的内存管理的介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助. 一.php内存管理概述——Zend引擎 由于计算机的内存由操作系统进行管理,所以 ...
- AI之旅(2):初识线性回归
前置知识 矩阵.求导 知识地图 学习一个新事物之前,先问两个问题,我在哪里?我要去哪里?这两个问题可以避免我们迷失在知识的海洋里,所以在开始之前先看看地图. 此前我们已经为了解线性回归做了 ...
- [ 随手记6 ] C/C++ 形参、实参、按值传参、指针传参、引用传参
个人原创: 1. 形参:形式上的参数,一般多在函数声明.函数定义的参数上: 2. 实参:实体参数,有实际的值,在运算上被循环使用的值: 3. 按值传参:按值,就是把实际的值传给函数内部: 4. 指针传 ...
- JAVA日常之三
一.Main方法的args参数 args[] 是程序运行前可传入的参数,比如 java HelloWorld a,那么在HelloWorld的main方法里面 args就是{"a" ...
- 利用Python中的for循环和while循环,打印各种方向的九九乘法表。
哈喽大家好,今天,可乐来给大家分享一下Python中用for循环和while循环打印九九乘法表的操作.由于本人也是刚刚接触Python不长时间,代码也是自己编写的,所以有什么不足之处还请大家多多指教. ...