IK分词插件的安装

ES集群环境

  • VMWare下三台虚拟机Ubuntu 14.04.2 LTS
  • JDK 1.8.0_66
  • Elasticsearch 2.3.1
  • elasticsearch-jdbc-2.3.1.0
  • IK分词器1.9.1
  • clustername:my-application

    分配如下表:

    虚拟机 | IP | node-x

    ----|----

    search1 | 192.168.235.133 | node-1

    search2 |192.168.235.134 | node-2

    search3 |192.168.235.135 | node-3

IK分词器下载与编译

在github下载IK分词器zip包:

https://github.com/myitroad/elasticsearch-analysis-ik

解压后导入IntelliJ IDEA为maven工程。

生成jar包

使用IntelliJ IDEA maven的terminal工具,执行:

mvn clean
mvn compile
mvn package

在F:\workspace_idea\elasticsearch-analysis-ik-master\target\releases生成:

elasticsearch-analysis-ik-1.9.1.zip

上传IK分词器

将上述zip包上传Elasticsearch的node-x(择一即可,如node-1),解压到:

/home/es/cluster/elasticsearch-2.3.1/plugins/ik目录,

最终的ik文件夹内目录为:

ik
│ ├── commons-codec-1.9.jar
│ ├── commons-logging-1.2.jar
│ ├── config
│ │ └── ik
│ │ ├── custom
│ │ │ ├── ext_stopword.dic
│ │ │ ├── mydict.dic
│ │ │ ├── single_word.dic
│ │ │ ├── single_word_full.dic
│ │ │ ├── single_word_low_freq.dic
│ │ │ └── sougou.dic
│ │ ├── IKAnalyzer.cfg.xml
│ │ ├── main.dic
│ │ ├── preposition.dic
│ │ ├── quantifier.dic
│ │ ├── stopword.dic
│ │ ├── suffix.dic
│ │ └── surname.dic
│ ├── elasticsearch-analysis-ik-1.9.1.jar
│ ├── httpclient-4.4.1.jar
│ ├── httpcore-4.4.1.jar
│ └── plugin-descriptor.properties

配置词库(ik自带搜狗词库)

配置:$ES_HOME/plugins/ik/config/ik/IKAnalyzer.cfg.xml

添加以下配置:

<entry key="ext_dict">custom/mydict.dic;custom/single_word_low_freq.dic;custom/sougou.dic</entry>

重启节点node-1

测试IK分词效果

默认_analyze分析命令可能造成中文乱码,因此对中文使用URL编码。

%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA是“我是中国人”的URL转码。

若直接使用“我是中国人”测试分词,则可能会返回乱码。

使用IK的ik_max_word最大分词

es@search1:~/cluster/elasticsearch-2.3.1$ curl -XGET 'localhost:9200/myindex/_analyze?analyzer=ik_max_word&text=%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA&pretty'

返回分词结果:

{
"tokens" : [ {
"token" : "我是",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
}, {
"token" : "我",
"start_offset" : 0,
"end_offset" : 1,
"type" : "CN_WORD",
"position" : 1
}, {
"token" : "是中国人",
"start_offset" : 1,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 2
}, {
"token" : "中国人",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "中国",
"start_offset" : 2,
"end_offset" : 4,
"type" : "CN_WORD",
"position" : 4
}, {
"token" : "国人",
"start_offset" : 3,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 5
}, {
"token" : "人",
"start_offset" : 4,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 6
} ]
}

使用IK的ik_smart最小分词

es@search1:~/cluster/elasticsearch-2.3.1$ curl -XGET 'localhost:9200/myindex/_analyze?analyzer=ik_smart&text=%E6%88%91%E6%98%AF%E4%B8%AD%E5%9B%BD%E4%BA%BA&pretty'

返回:

{
"tokens" : [ {
"token" : "我是",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
}, {
"token" : "中国人",
"start_offset" : 2,
"end_offset" : 5,
"type" : "CN_WORD",
"position" : 1
} ]
}

使用IK分词器导入MySQL数据

建立myindex索引

在node-1上执行:

curl -XPUT 'localhost:9200/myindex?pretty'

编写MySQL导入es脚本mysql-es-all.sh:(存放位置可任意)

#!/bin/sh
bin=/home/es/cluster/elasticsearch-2.3.1/elasticsearch-jdbc-2.3.1.0/bin
lib=/home/es/cluster/elasticsearch-2.3.1/elasticsearch-jdbc-2.3.1.0/lib
echo '
{
"type" : "jdbc",
"jdbc" : {
"locale" : "zh_CN",
"statefile" : "statefile.json",
"timezone" : "GMT+8",
"autocommit" : true,
"elasticsearch" : {
"cluster" : "my-application",
"host" : "192.168.235.133",
"port" : "9300"
},
"index" : "myindex",
"type" : "mytype",
"url" : "jdbc:mysql://10.110.1.47:3306/ispider_data",
"user" : "root",
"password" : "xxx",
"sql" : "select uuid as _id,title,content,release_time from JCY_VOICE_NEWS_INFO",
"metrics" : {
"enabled" : true,
"interval" : "5m"
},
"index_settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" : 2
}
},
"type_mapping": {
"mytype" : {
"properties" : {
"title" : {
"type" : "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true"
},
"content" : {
"type" : "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true"
},
"release_time":{
"type":"date",
"store":"no",
"format":"YYYY-MM-dd HH:mm:ss",
"index":"not_analyzed",
"include_in_all":"true"
}
}
}
}
}
}
' | java \
-cp "${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter

添加运行权限并运行脚本

es@search1:~/cluster/elasticsearch-2.3.1$chmod +x mysql-es-all.sh
es@search1:~/cluster/elasticsearch-2.3.1$./mysql-es-all.sh

参考资料

Elasticsearch集群使用ik分词器的更多相关文章

  1. 【ELK】【docker】【elasticsearch】1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安装ik分词器

    系列文章:[建议从第二章开始] [ELK][docker][elasticsearch]1. 使用Docker和Elasticsearch+ kibana 5.6.9 搭建全文本搜索引擎应用 集群,安 ...

  2. 使用Docker 安装Elasticsearch、Elasticsearch-head、IK分词器 和使用

    原文:使用Docker 安装Elasticsearch.Elasticsearch-head.IK分词器 和使用 Elasticsearch的安装 一.elasticsearch的安装 1.镜像拉取 ...

  3. Docker 下Elasticsearch 的安装 和ik分词器

    (1)docker镜像下载 docker pull elasticsearch:5.6.8 (2)安装es容器 docker run -di --name=changgou_elasticsearch ...

  4. 【ELK】【docker】6.Elasticsearch 集群启动多节点 + 解决ES节点集群状态为yellow

    本章其实是ELK第二章的插入章节. 本章ES集群的多节点是docker启动在同一个虚拟机上 ====================================================== ...

  5. Elasticsearch之文档的增删改查以及ik分词器

    文档的增删改查 增加文档 使用elasticsearch-head查看 修改文档 使用elasticsearch-head查看 删除文档 使用elasticsearch-head查看 查看文档的三种方 ...

  6. (2)ElasticSearch在linux环境中集成IK分词器

    1.简介 ElasticSearch默认自带的分词器,是标准分词器,对英文分词比较友好,但是对中文,只能把汉字一个个拆分.而elasticsearch-analysis-ik分词器能针对中文词项颗粒度 ...

  7. 【杂记】docker搭建ELK 集群6.4.0版本 + elasticsearch-head IK分词器与拼音分词器整合

    大佬博客地址:https://blog.csdn.net/supermao1013/article/category/8269552 docker elasticsearch 集群启动命令 docke ...

  8. Elasticsearch下安装ik分词器

    安装ik分词器(必须安装maven) 上传相应jar包 解压到相应目录 unzip elasticsearch-analysis-ik-master.zip(zip包) cp -r elasticse ...

  9. 【ELK】【docker】【elasticsearch】2.使用elasticSearch+kibana+logstash+ik分词器+pinyin分词器+繁简体转化分词器 6.5.4 启动 ELK+logstash概念描述

    官网地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod ...

随机推荐

  1. Docker DNS

    从 Docker 1.10 版本开始,docker daemon 实现了一个内嵌的 DNS server,使容器可以直接通过“容器名”通信. 方法很简单,只要在启动时用 --name 为容器命名并且连 ...

  2. 百度编辑器 Ueditor 如何增加字体 ?

    在百度编辑器 Ueditor 如何增加字体 ? 要修改两个文件: 第一个文件:editor-config.js: ,'fontfamily':[             { label:'',name ...

  3. 大话设计模式--抽象工厂模式 Abstract Factory -- C++实现实例

    1. 抽象工厂模式: 提供一个创建一系列相关或者相互依赖对象的接口,而无需指定他们具体的类. 下面是工厂方法模式: 下面是抽象工厂模式: 和工厂方法模式相比 抽象工厂模式可以有多个Product抽象, ...

  4. (转)edm注意事项

    格式编码 1.页面宽度请设定在600到800px以内,长度1024px以内. 2.HTML编码请使用utf-8. 3.HTML代码在15KB以内.(各个邮箱的收件标准不一样,如果超出15KB您的邮件很 ...

  5. MySQL常用方法

    1.INSTR,例:INSTR(content,'\"SHOP_DES\"')>0,返回字符串在某一个字段的内容中第一次出现位置,没有为0 2.REPLACE,例:conte ...

  6. 理解WCF(第二部分,部分參考他人)

    該篇的主題:wcf到底是怎工作的? 一.什么是分布式: 首先看一张图: 由上图对比我们可以发现,区别就是前者把服务器放在了一台电脑上,而后者把服务器放在了多台电脑上.这样多台电脑处理起来的速度比一台电 ...

  7. IBM V3500存储恢复步骤实例(linux)

    本环境是一有台IBM3500存储,将存储挂载至linux的/data目录,模拟测试当主服务器挂了,将数据恢复到另一台服务器,存储有两个地址,我配置的是192.168.80.59是用于web管理,192 ...

  8. codeforces 707C C. Pythagorean Triples(数学)

    题目链接: C. Pythagorean Triples time limit per test 1 second memory limit per test 256 megabytes input ...

  9. 利用Python进行文章特征提取(二)

    本篇blog是利用Python进行文章特征提取的续篇,主要介绍构建带TF-IDF权重的文章特征向量. In [1]: # 带TF-IDF权重的扩展词库 # 在第一篇文档里 主要是利用词库模型简单判断单 ...

  10. NYOJ-小猴子下落

    描述 有一颗二叉树,最大深度为D,且所有叶子的深度都相同.所有结点从左到右从上到下的编号为1,2,3,·····,2的D次方减1.在结点1处放一个小猴子,它会往下跑.每个内结点上都有一个开关,初始全部 ...