一:基础环境
elasticsearch:6.6.0
二:下载
https://github.com/KennFalcon/elasticsearch-analysis-hanlp
下载elasticsearch对于的elasticsearch-analysis-hanlp
完全匹配 6.6.0
三:解压
elasticsearch-6.6.0\plugins下创建analysis-hanlp文件夹
解压elasticsearch-analysis-hanlp-6.6.0.zip到analysis-hanlp中
四:配置
1.elasticsearch-6.6.0/plugins/analysis-hanlp/config/hanlp.properties
下篇配置具体路径
root=/opt/elasticsearch/elasticsearch-6.6.0/plugins/analysis-hanlp/
2.elasticsearch-6.6.0/config/jvm.options
-Djava.security.policy=/opt/elasticsearch/elasticsearch-6.6.0/plugins/analysis-hanlp/plugin-security.policy
五:重启 elasticsearch
六:问题
如果启动报加载到hanlp可以将hanlp.properties,hanlp-remote.xml拷贝到指定报错目录下
七:测试
GET /_analyze
{
"text":"华为 HUAWEI Mate 30 Pro 5G 麒麟990 OLED环幕屏双4000万徕卡电影四摄8GB+256GB丹霞橙5G全网通游戏手机",
"analyzer":"hanlp"
}
结果
{
"tokens" : [
{
"token" : "华为",
"start_offset" : 0,
"end_offset" : 2,
"type" : "nt",
"position" : 0
},
{
"token" : "HUAWEI",
"start_offset" : 0,
"end_offset" : 6,
"type" : "nx",
"position" : 1
},
{
"token" : "Mate",
"start_offset" : 0,
"end_offset" : 4,
"type" : "nx",
"position" : 2
},
{
"token" : "30",
"start_offset" : 0,
"end_offset" : 2,
"type" : "m",
"position" : 3
},
{
"token" : "Pro",
"start_offset" : 0,
"end_offset" : 3,
"type" : "nx",
"position" : 4
},
{
"token" : "5",
"start_offset" : 0,
"end_offset" : 1,
"type" : "m",
"position" : 5
},
{
"token" : "G",
"start_offset" : 0,
"end_offset" : 1,
"type" : "nx",
"position" : 6
},
{
"token" : "麒麟",
"start_offset" : 0,
"end_offset" : 2,
"type" : "n",
"position" : 7
},
{
"token" : "990",
"start_offset" : 0,
"end_offset" : 3,
"type" : "m",
"position" : 8
},
{
"token" : "OLED",
"start_offset" : 0,
"end_offset" : 4,
"type" : "nx",
"position" : 9
},
{
"token" : "环幕",
"start_offset" : 0,
"end_offset" : 2,
"type" : "n",
"position" : 10
},
{
"token" : "屏",
"start_offset" : 0,
"end_offset" : 1,
"type" : "ng",
"position" : 11
},
{
"token" : "双",
"start_offset" : 0,
"end_offset" : 1,
"type" : "q",
"position" : 12
},
{
"token" : "4000",
"start_offset" : 0,
"end_offset" : 4,
"type" : "m",
"position" : 13
},
{
"token" : "万",
"start_offset" : 0,
"end_offset" : 1,
"type" : "m",
"position" : 14
},
{
"token" : "徕",
"start_offset" : 0,
"end_offset" : 1,
"type" : "x",
"position" : 15
},
{
"token" : "卡",
"start_offset" : 0,
"end_offset" : 1,
"type" : "n",
"position" : 16
},
{
"token" : "电影",
"start_offset" : 0,
"end_offset" : 2,
"type" : "n",
"position" : 17
},
{
"token" : "四",
"start_offset" : 0,
"end_offset" : 1,
"type" : "m",
"position" : 18
},
{
"token" : "摄",
"start_offset" : 0,
"end_offset" : 1,
"type" : "vg",
"position" : 19
},
{
"token" : "8",
"start_offset" : 0,
"end_offset" : 1,
"type" : "m",
"position" : 20
},
{
"token" : "GB",
"start_offset" : 0,
"end_offset" : 2,
"type" : "nx",
"position" : 21
},
{
"token" : "+",
"start_offset" : 0,
"end_offset" : 1,
"type" : "w",
"position" : 22
},
{
"token" : "256",
"start_offset" : 0,
"end_offset" : 3,
"type" : "m",
"position" : 23
},
{
"token" : "GB",
"start_offset" : 0,
"end_offset" : 2,
"type" : "nx",
"position" : 24
},
{
"token" : "丹霞",
"start_offset" : 0,
"end_offset" : 2,
"type" : "nz",
"position" : 25
},
{
"token" : "橙",
"start_offset" : 0,
"end_offset" : 1,
"type" : "ag",
"position" : 26
},
{
"token" : "5",
"start_offset" : 0,
"end_offset" : 1,
"type" : "m",
"position" : 27
},
{
"token" : "G",
"start_offset" : 0,
"end_offset" : 1,
"type" : "nx",
"position" : 28
},
{
"token" : "全",
"start_offset" : 0,
"end_offset" : 1,
"type" : "a",
"position" : 29
},
{
"token" : "网通",
"start_offset" : 0,
"end_offset" : 2,
"type" : "ntc",
"position" : 30
},
{
"token" : "游戏",
"start_offset" : 0,
"end_offset" : 2,
"type" : "n",
"position" : 31
},
{
"token" : "手机",
"start_offset" : 0,
"end_offset" : 2,
"type" : "n",
"position" : 32
}
]
}