1、到github网站下载源代码,网站地址为: https://github.com/medcl/elasticsearch-analysis-ik 2 、将解压目录文件中config/ik文件夹复制到ES安装目录config文件夹下。 3、将打包得到的zip文件解压, 复制 elasticsearch-analysis-ik-1.6.0.jar、 httpclient-4.4.1.jar、httpcore-4.4.1.jar(仓库拷贝) 到ES安装目录的lib目录下。 4、在ES的 plugins目录下建立ik文件夹,将打包文件中的plugin-descriptor.properties(elasticsearch-analysis-ik-master\src\main\resources )拷贝进去 重新启动elasticsearch服务,这样就完成配置了,收入命令: [html] view plain copy
- curl -XPOST "http://localhost:9200/userinfo/_analyze?analyzer=ik&pretty=true&text=我是中国人"
测试结果如下: [html] view plain copy
- {
- tokens: [
- {
- token: text
- start_offset: 2
- end_offset: 6
- type: ENGLISH
- position: 1
- }
- {
- token: 我
- start_offset: 9
- end_offset: 10
- type: CN_CHAR
- position: 2
- }
- {
- token: 中国人
- start_offset: 11
- end_offset: 14
- type: CN_WORD
- position: 3
- }
- {
- token: 中国
- start_offset: 11
- end_offset: 13
- type: CN_WORD
- position: 4
- }
- {
- token: 国人
- start_offset: 12
- end_offset: 14
- type: CN_WORD
- position: 5
- }
- ]
- }
Quick Example
1.create a index
curl -XPUT http://localhost:9200/index
2.create a mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'
{
"fulltext": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'
3.index some docs
curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
4.query with highlighting
curl -XPOST http://localhost:9200/index/fulltext/_search -d'
{
"query" : { "term" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}
'