安装IK分词器
下载对应版本的插件
https://github.com/medcl/elasticsearch-analysis-ik/releases
首先下载es对应版本的ik分词器的zip包,上传到es服务器上,在es的安装目录下有一个plugins的目录,在这个目录下创建一个叫ik的目录
然后将解压好的内容,拷贝到ik目录
将ik目录拷贝到其他的es节点
重新启动所有的es
#创建索引名字叫news
curl -XPUT http://192.168.100.211:9200/news
#创建mapping(相当于数据中的schema信息,表名和字段名以及字段的类型)
curl -XPOST http://192.168.100.211:9200/news/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}'
curl -XPOST http://192.168.100.211:9200/news/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}'
curl -XPOST http://192.168.100.211:9200/news/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}'
curl -XPOST http://192.168.100.211:9200/news/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'
curl -XPOST http://192.168.100.211:9200/news/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'
curl -XPOST http://192.168.100.211:9200/news/fulltext/_search -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<font color='red'>", "<tag2>"],
"post_tags" : ["</font>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}'
-------------------------------------------------------------------
curl -XGET 'http://192.168.100.211:9200/_analyze?pretty&analyzer=ik_max_word' -d '联想是全球最大的笔记本厂商'
curl -XGET 'https://192.168.100.211:9200/_analyze?pretty&analyzer=ik_smart' -d '联想是全球最大的笔记本厂商'
curl -XPUT 'https://192.168.100.211:9200/iktest?pretty' -d '{
"settings" : {
"analysis" : {
"analyzer" : {
"ik" : {
"tokenizer" : "ik_max_word"
}
}
}
},
"mappings" : {
"article" : {
"dynamic" : true,
"properties" : {
"subject" : {
"type" : "string",
"analyzer" : "ik_max_word"
}
}
}
}
}'
curl -XPUT 'https://192.168.100.211:9200/iktest?pretty' -d '{
"settings" : {
"analysis" : {
"analyzer" : {
"ik" : {
"tokenizer" : "ik_max_word"
}
}
}
},
"mappings" : {
"article" : {
"dynamic" : true,
"properties" : {
"subject" : {
"type" : "string",
"analyzer" : "ik_max_word"
}
}
}
}
}'
curl -XGET 'http://192.168.10.16:9200/_analyze?pretty&analyzer=ik_max_word' -d ‘中华人民共和国’

4911

被折叠的 条评论
为什么被折叠?



