HanLP 中文分词器是一个开源的分词器,是专为Elasticsearch而设计的。它是基于HanLP,并提供了HanLP中大部分的分词方式。它的源码位于:

https://github.com/KennFalcon/elasticsearch-analysis-hanl

从Elasticsearch 5.2.2开始,一直有跟随Elasticsearch的不同发行版而更新。

安装

1) 方式一:

a. 下载对应的release安装包,最新release包可从baidu盘下载(链接:https://pan.baidu.com/s/1mFPNJXgiTPzZeqEjH_zifw 密码:i0o7)

b. 执行如下命令安装,其中PATH为插件包绝对路径:

./bin/elasticsearch-plugin install file://${PATH}

2)方式二:

a. 使用elasticsearch插件脚本安装command如下:

./bin/elasticsearch-plugin install https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.4.2/elasticsearch-analysis-hanlp-7.4.2.zip

安装完后,我们可以使用如下的方式来验证我们的安装是否成功:

    $ ./bin/elasticsearch-plugin list
analysis-hanlp

如果我们安装时成功的话,我们可以看到上面的输出。

安装数据包

release包中存放的为HanLP源码中默认的分词数据,若要下载完整版数据包,请查看HanLP Release。

数据包目录:ES_HOME/plugins/analysis-hanlp

注:因原版数据包自定义词典部分文件名为中文,这里的hanlp.properties中已修改为英文,请对应修改文件名

重启Elasticsearch

注:上述说明中的ES_HOME为自己的ES安装路径,需要绝对路径。

这一步非常重要。如果我们不重新启动,新安装的分词器将不会工作。

热更新

在本版本中,增加了词典热更新,修改步骤如下:

a. 在ES_HOME/plugins/analysis-hanlp/data/dictionary/custom目录中新增自定义词典

b. 修改hanlp.properties,修改CustomDictionaryPath,增加自定义词典配置

c. 等待1分钟后,词典自动加载

注:每个节点都需要做上述更改

提供的分词方式说明

  • hanlp: hanlp默认分词
  • hanlp_standard: 标准分词
  • hanlp_index: 索引分词
  • hanlp_nlp: NLP分词
  • hanlp_n_short: N-最短路分词
  • hanlp_dijkstra: 最短路分词
  • hanlp_crf: CRF分词(已有最新方式)
  • hanlp_speed: 极速词典分词

我们来做一个简单的例子:

    GET _analyze
{
"text": "美国阿拉斯加州发生8.0级地震",
"tokenizer": "hanlp"
}

那么显示的结果为:

    {
"tokens" : [
{
"token" : "美国",
"start_offset" : 0,
"end_offset" : 2,
"type" : "nsf",
"position" : 0
},
{
"token" : "阿拉斯加州",
"start_offset" : 2,
"end_offset" : 7,
"type" : "nsf",
"position" : 1
},
{
"token" : "发生",
"start_offset" : 7,
"end_offset" : 9,
"type" : "v",
"position" : 2
},
{
"token" : "8.0",
"start_offset" : 9,
"end_offset" : 12,
"type" : "m",
"position" : 3
},
{
"token" : "级",
"start_offset" : 12,
"end_offset" : 13,
"type" : "q",
"position" : 4
},
{
"token" : "地震",
"start_offset" : 13,
"end_offset" : 15,
"type" : "n",
"position" : 5
}
]
}

更多详细阅读,请参阅链接https://github.com/KennFalcon/elasticsearch-analysis-hanlp

Elasticsearch:hanlp 中文分词器的更多相关文章

  1. elasticsearch教程--中文分词器作用和使用

    概述   本文都是基于elasticsearch安装教程 中的elasticsearch安装目录(/opt/environment/elasticsearch-6.4.0)为范例 环境准备 ·全新最小 ...

  2. 如何给Elasticsearch安装中文分词器IK

    安装Elasticsearch安装中文分词器IK的步骤: 1. 停止elasticsearch 2.2的服务 2. 在以下地址下载对应的elasticsearch-analysis-ik插件安装包(版 ...

  3. 【自定义IK词典】Elasticsearch之中文分词器插件es-ik的自定义词库

    Elasticsearch之中文分词器插件es-ik 针对一些特殊的词语在分词的时候也需要能够识别 有人会问,那么,例如: 如果我想根据自己的本家姓氏来查询,如zhouls,姓氏“周”.      如 ...

  4. Elasticsearch之中文分词器插件es-ik(博主推荐)

    前提 什么是倒排索引? Elasticsearch之分词器的作用 Elasticsearch之分词器的工作流程 Elasticsearch之停用词 Elasticsearch之中文分词器 Elasti ...

  5. 沉淀再出发:ElasticSearch的中文分词器ik

    沉淀再出发:ElasticSearch的中文分词器ik 一.前言   为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了 ...

  6. Elasticsearch之中文分词器

    前提 什么是倒排索引? Elasticsearch之分词器的作用 Elasticsearch之分词器的工作流程 Elasticsearch之停用词 Elasticsearch的中文分词器 1.单字分词 ...

  7. Elasticsearch之中文分词器插件es-ik的自定义热更新词库

    不多说,直接上干货! 欢迎大家,关注微信扫码并加入我的4个微信公众号:   大数据躺过的坑      Java从入门到架构师      人工智能躺过的坑         Java全栈大联盟       ...

  8. elasticsearch安装中文分词器插件smartcn

    原文:http://blog.java1234.com/blog/articles/373.html elasticsearch安装中文分词器插件smartcn elasticsearch默认分词器比 ...

  9. ElasticSearch安装中文分词器IKAnalyzer

    # ElasticSearch安装中文分词器IKAnalyzer  本篇主要讲解如何在ElasticSearch中安装中文分词器IKAnalyzer,拆分的每个词都是我们熟知的词语,从而建立词汇与文档 ...

随机推荐

  1. vue路由在keep-alive下的刷新问题

    问题描述: 在keep-alive中的在跳转到指定的路由时刷新对应的路由,其余不刷新. <transition name="fade" mode="out-in&q ...

  2. 自定义ListView实现下拉刷新,下拉加载的功能

    package com.loaderman.myrefreshlistviewdemo; import android.content.Context; import android.util.Att ...

  3. JavaEE-实验四 HTML与JSP基础编程

    1.使用HTML的表单以及表格标签,完成以下的注册界面(验证码不做) html代码(css写于其中) <!DOCTYPE html> <html> <head> & ...

  4. Selenium 2自动化测试实战17(警告框处理)

    一.警告框处理 在WebDriver中处理JavaScript所生成的alert.confirm以及prompt十分简单,只需要使用switch_to_alert()方法定位到alert/confir ...

  5. MySQL 树形结构 根据指定节点 获取其所有父节点序列

    背景说明 需求:MySQL树形结构, 根据指定的节点,获取其所有父节点序列. 问题分析 1.可以使用类似Java这种面向对象的语言,对节点集合进行逻辑处理,获取父节点. 2.直接自定义MySQL函数  ...

  6. 取长文本 READ_TEXT

    ****取长文本  FORM GET_TEXT USING TDID TDNAME. SELECT SINGLE mandt tdobject tdname tdid tdspras    INTO  ...

  7. Web03_JavaScript

    案例一:使用JS完成注册页面表单校验 <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...

  8. python基础语法之字符串

    1 字符串中*的使用 *可以使字符串重复n次 print('hello world ' * 2) # hello world hello world 2 索引获取字符串的字符元素 print('hel ...

  9. vue父子组件相互传值的实例

    当子组件需要向父组件传递数据时,就要用到自定义事件 子组件用 $emit()来触发事件,父组件用$on()来监昕子组件的事件 父组件也可以直接在子组件的自定义标签上使用 v-on 来监昕子组件触发的自 ...

  10. python 爬取网页内的代理服务器列表(需调整优化)

    #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-08-30 20:38:23 # @Author : EnderZhou (z ...