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客户端的中文分词的更多相关文章

  1. Ubuntu16.04下安装xunsearch+opencc实现php客户端的中文分词

    1.准备服务器环境 apt-get install apache2 php mysql-server apt-get install mysql-client phpmyadmin apt-get i ...

  2. Ubuntu16.04下安装数据库oracle客户端

    在Ubuntu16.04下安装oracle数据库客户端,使Django项目连接到远程Oracle数据库. 1.下载oracle客户端安装包: 进入官网http://www.oracle.com/tec ...

  3. Ubuntu16.04下安装redis

    Ubuntu16.04下安装redis 保证网络畅通,选定好下载工作路径,执行以下命令下载redis-3.2.6: sudo wget http://download.redis.io/release ...

  4. docker学习笔记(一)—— ubuntu16.04下安装docker

    docker学习笔记(一)—— ubuntu16.04下安装docker 原创 2018年03月01日 14:53:00 标签: docker / ubuntu 1682 本文开发环境为Ubuntu ...

  5. ubuntu16.04下安装artoolkit5

    目前对AR技术的常见理解就是CV(Computer Vision)+CG(Computer Graphic).CV的方法很多,简单些比如FREAK+ICP(ARToolKit中的NFT),复杂些就是S ...

  6. Ubuntu16.04下安装多版本cuda和cudnn

    Ubuntu16.04下安装多版本cuda和cudnn 原文 https://blog.csdn.net/tunhuzhuang1836/article/details/79545625 前言 因为之 ...

  7. Ubuntu18.04下安装Sublime Text3并解决不能输入中文

    Ubuntu18.04下安装Sublime Text3并解决不能输入中文! 废话不多说,直接按顺序执行下面命令开始安装! wget -qO - https://download.sublimetext ...

  8. Ubuntu16.04下安装Hadoop

    一.记录理由 刚开始只是想要学习怎么使用Hive的.想着安装应该很简单,没想到花了整整一天的时间来安装,为了避免下次犯同样的错误,特此记录. 二.安装Hadoop 网上教你怎么安装Hadoop的文章有 ...

  9. Ubuntu16.04下安装texlive

    Ubuntu 16.04下安装texlive的步骤如下: 1.下载texlive 打开终端输入:sudo apt-get install texlive-full  #下载这一过程会持续10-20分钟 ...

随机推荐

  1. java导出pdf

    //导出          public void ScoringAnnouncementdownLoad() throws MalformedURLException, IOException, D ...

  2. 闪付卡(QuickPass)隐私泄露原理

    0×00 前言 说到闪付卡,首先要从EMV开始,EMV是由Europay,MasterCard和VISA制定的基于IC卡的支付标准规范.目前基于EMV卡的非接触式支付的实现有三个:VISA的payWa ...

  3. FCC JS基础算法题(5):Return Largest Numbers in Arrays(找出多个数组中的最大数)

    题目描述: 找出多个数组中的最大数右边大数组中包含了4个小数组,分别找到每个小数组中的最大值,然后把它们串联起来,形成一个新数组.提示:你可以用for循环来迭代数组,并通过arr[i]的方式来访问数组 ...

  4. org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.zhuoshi.entity.Dep#1]

    报错信息: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.zhuoshi.e ...

  5. 在执行hadoop fs命令时,出现WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable错误

    错误呈现: 解决过程: (参考链接:https://www.cnblogs.com/kevinq/p/5103653.html) 1.输出hadoop的详细日志,并执行hadoop fs命令来查看错误 ...

  6. KMP算法详细分解

    1. 引言 给定一个主串(以 S 代替)和模式串(以 P 代替),要求找出 P 在 S 中出现的位置,此即串的模式匹配问题. Knuth-Morris-Pratt 算法(简称 KMP)是解决这一问题的 ...

  7. 浅谈ES6新增数据类型:Symbol

    面试中喜闻乐见的问题就是问我们的ES6新增了哪些个新特性 这篇文章一起学习一下新增的数据类型:Symbol JS的原始数据类型:6种Boolean,String,Undefined,NULL,Numb ...

  8. 《Machine Learning Yearing》读书笔记

    ——深度学习的建模.调参思路整合. 写在前面 最近偶尔从师兄那里获取到了吴恩达教授的新书<Machine Learning Yearing>(手稿),该书主要分享了神经网络建模.训练.调节 ...

  9. 在Java中用 . 深层访问JSON数据

    本文介绍Java中解析JSON的一种方法,可以让我们在Java程序中也用x.x.x的形式访问JSON数据中的值. 代码大部分来源非本人,本人在源代码基础上加以修改以使正常运行. 代码: // 将提取方 ...

  10. 神州数码DEIGRP路由协议配置

    实验要求:了解DEIGRP及其配置方法 拓扑如下 R1 enable 进入特权模式 config 进入全局模式 hostname R1 修改名称 interface l0 进入端口 ip addres ...