环境介绍

集群环境如下:

  • Ubuntu14.04
  • ElasticSearch 2.3.1(3节点)
  • JDK1.8.0_60

开发环境:

  • Windows10
  • JDK 1.8.0_66
  • Maven 3.3.3
  • Intellij IDEA 2016.1

下载编译Pinyin

  • clone elasticsearch-analysis-pinyin
    通过IntelliJ从git上克隆elasticsearch-analysis-pinyin工程
  • 修改ES版本
    下载完项目后修改项目根目录下pom.xml文件中的properties/elasticsearch.version节点值为2.3.1,以确保编译后的版本兼容ES2.3.1版本;
  • 编译
    打开IntelliJ Terminal工具,输入以下命令:
    mvn clean install -Dmaven.test.skip
    可以在项目目录elasticsearch-analysis-pinyin\target\releases看到编译后的结果elasticsearch-analysis-pinyin-1.7.4.zip,以及elasticsearch-analysis-pinyin\target目录下的elasticsearch-analysis-pinyin-1.7.4.jar。
    这里我们主要使用zip包。

安装部署

  • 安装
    在ES服务器每个节点的${ES_HOME}/plugins目录下新建文件夹,名为pinyin;
    解压上述zip压缩包,可见三个文件elasticsearch-analysis-pinyin-1.7.4.jar、plugin-descriptor.properties、pinyin4j-2.5.0.jar,将其上传到ES服务器pinyin文件夹内即可;
  • 重启
    节点安装完pinyin插件后,需要重启生效。
  • 多节点集群
    ES集群每个节点都进行上述安装。

测试

分词测试

  • 建立测试索引
    建立一个测试分词效果的索引medcl,在节点终端执行如下代码:
  1. curl -XPUT http://localhost:9200/medcl/-d'
  2. {
  3. "index" : {
  4. "analysis" : {
  5. "analyzer" : {
  6. "pinyin_analyzer" : {
  7. "tokenizer" : "my_pinyin",
  8. "filter" : ["standard"]
  9. }
  10. },
  11. "tokenizer" : {
  12. "my_pinyin" : {
  13. "type" : "pinyin",
  14. "first_letter" : "none",
  15. "padding_char" : " "
  16. }
  17. }
  18. }
  19. }
  20. }'
  • 通过浏览器测试分词
  1. http://10.110.13.144:9200/medcl/_analyze?text=%E5%88%98%E5%BE%B7%E5%8D%8E&analyzer=pinyin_analyzer

若测试成功,浏览器返回结果如下:

  1. {"tokens":[{"token":"liudehua","start_offset":0,"end_offset":3,"type":"word","position":0}]}

建立拼音索引

  • 建立索引并设置分词
  1. curl -XPOST http://localhost:9200/medcl/_close
  2. curl -XPUT http://localhost:9200/medcl/_settings -d'
  3. {
  4. "index" : {
  5. "analysis" : {
  6. "analyzer" : {
  7. "pinyin_analyzer" : {
  8. "tokenizer" : "my_pinyin",
  9. "filter" : ["standard"],
  10. "type":"pinyin"
  11. }
  12. },
  13. "tokenizer" : {
  14. "my_pinyin" : {
  15. "type" : "pinyin",
  16. "first_letter" : "none",
  17. "padding_char" : " "
  18. }
  19. }
  20. }
  21. }
  22. }'
  23. curl -XPOST http://localhost:9200/medcl/_open
  • 建立mapping
  1. curl -XPOST http://localhost:9200/medcl/folks/_mapping -d'
  2. {
  3. "folks": {
  4. "properties": {
  5. "name": {
  6. "type": "multi_field",
  7. "fields": {
  8. "name": {
  9. "type": "string",
  10. "store": "no",
  11. "term_vector": "with_positions_offsets",
  12. "analyzer": "pinyin_analyzer",
  13. "boost": 10
  14. },
  15. "primitive": {
  16. "type": "string",
  17. "store": "yes",
  18. "analyzer": "keyword"
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }'
  • 上传数据
  1. curl -XPOST http://localhost:9200/medcl/folks/andy -d'{"name":"刘德华"}'
  • 在浏览器请求检索
  1. http://10.110.13.144:9200/medcl/folks/_search?q=name:liudehua

若检索成功,浏览器返回以下结果:

  1. {"took":9,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":3.0685282,"hits":[{"_index":"pinyin","_type":"test","_id":"andy","_score":3.0685282,"_source":{"name":"刘德华"}}]}}

参考资料

附件列表

ElasticSearch安装拼音插件(pinyin)的更多相关文章

  1. ElasticSearch安装拼音插件 elasticsearch-analysis-pinyin

    elasticsearch-analysis-pinyin 是 ElasticSearch的拼音插件.强大的功能支持拼音等的搜索 1.下载源代码 源码地址https://github.com/medc ...

  2. ElasticSearch搜索引擎安装配置拼音插件pinyin

    近几篇ElasticSearch系列: 1.阿里云服务器Linux系统安装配置ElasticSearch搜索引擎 2.Linux系统中ElasticSearch搜索引擎安装配置Head插件 3.Ela ...

  3. ElasticSearch安装SQL插件

    ElasticSearch安装SQL插件下载地址(中国大佬开发的,膜拜ing):https://github.com/NLPchina/elasticsearch-sql 1.记得选择和自己Elast ...

  4. Elasticsearch安装X-Pack插件

    Elasticsearch安装X-Pack插件, 基于已经安装好的6.2.2版本的Elasticsearch, 安装6.2.2版本的X-Pack插件. 1.下载x-pack的zip包到本地 https ...

  5. elasticsearch安装head插件

    安装Head插件 由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包. <1>安装Node.js 下载解压 wget https://node ...

  6. elasticsearch 安装 head插件

    head插件 切换到Elasticsearch的安装目录 cd ~/demo/elasticsearch/es1 执行安装命令 [root@localhost es1]# bin/plugin ins ...

  7. Elasticsearch安装 + Head插件安装 + Bigdesk插件安装

    一.Elasticsearch安装 1.官网下载zip包:https://www.elastic.co/downloads/elasticsearch 2.解压到自己指定的文件夹 3.运行\bin\e ...

  8. Elasticsearch 安装 Head 插件

    引子:在上一篇文章Elasticsearch入门(一):CentOS 7.6 安装ES 7.0.0中,我们讲了如何在CentOS 7.6环境下安装 Elasticsearch 7.0.下面,我将讲一讲 ...

  9. Elasticsearch 安装head插件

    一.简介 elasticsearch-head是一个界面化的集群操作和管理工具,可以对集群进行傻瓜式操作.你可以通过插件把它集成到es(首选方式),也可以安装成一个独立webapp. Elastics ...

随机推荐

  1. CodeForces - 794C:Naming Company(博弈&简单贪心)

    Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little thi ...

  2. HDU4585 Shaolin (STL和treap)

    Shaolin HDU - 4585       Shaolin temple is very famous for its Kongfu monks.A lot of young men go to ...

  3. SaaS模式实现架构

    SaaS模式实现架构 https://blog.csdn.net/xwq911/article/details/50630266 1. 数据库层: 数据库这一层的设计模式是很清晰的,无外乎只有3种方案 ...

  4. Broken Keyboard(模拟数组或者双重链表的运用)

    这题我是大写的服气,辛辛苦苦搞了个双重链表结果还一直不对,不对就算了,书上源代码打进去还是不对,我能怎么办我也很无奈.不过这题还是让我对双重链表更加了解和运用了!还是可以的! You’re typin ...

  5. mysql时间随笔

    SELECT FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%s') FROM `order`; select date_add(FROM_UNIXTIME(cr ...

  6. unity 联机调试(android ios)

    http://blog.csdn.net/OnafioO/article/details/44903491 (这种没用,只是在手机看到画面而已) 手机安装unityRemote并运行,unity中设置 ...

  7. C# 使用API检查域用户名和密码是否正确

    添加引用: using System.Runtime.InteropServices; public class VerifyUserByDomain { ; ; ); [DllImport(&quo ...

  8. 第一章计算机网络和因特网-day02

    1.互联网中的时延:处理时延.排队时延.传输时延.传播时延. 处理时延:检查分组首部和决定该分组导向何处的时间. 排队时延:分组在链路上等待传输的时延. 传输时延:分组经过路由器与交换机的过程的时延. ...

  9. Azure VM复制

    目前Azure上复制VM可以有多种方法: 1 创建User Image,可以快速复制多台VM,但目前托管磁盘只支持Generalized的模式,需要对User和配置进行重置. 2 从VHD或托管磁盘复 ...

  10. bash 中的行处理命令 awk

    转自:http://blog.chinaunix.net/uid-23302288-id-3785105.html