Elasticsearch5.5.1安装IK中文分词器

来源:互联网 发布:淘宝虚拟网店要不要钱 编辑:程序博客网 时间:2024/06/06 08:55

安装步骤:


一、参照官方文档安装IK分词器

1、直接到https://github.com/medcl/elasticsearch-analysis-ik/releases下载对应版本zip包

解压到elasticsearch的plugin目录下

unzip elasticsearch-analysis-ik-5.5.1.zip

    2、使用elasticsearch-plugin命令安装

./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip


重新启动elasticsearch

systemctl restart elasticsearch.service


测试一下:

1、创建索引

curl -XPUT http://localhost:9200/index

2、创建一个映射

curl -XPOST http://localhost:9200/index/fulltext/_mapping -d'

{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
}'

3、创建文档

curl -XPOST http://localhost:9200/index/fulltext/1 -d'

{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}

curl -XPOST http://localhost:9200/index/fulltext/2 -d'

{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}’


curl -XPOST 192.168.1.156:9200/test_index/fulltext/3 -d'

{"content":"公安部:各地校车将享最高路权"}


4、查询

curl -XPOST 192.168.1.156:9200/test_index/fulltext/_search -d'

{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
       
"post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}

查询结果如下:

{

  • "took"91,
  • "timed_out"false,
  • "_shards": {
    • "total"5,
    • "successful"5,
    • "failed"0
    },
  • "hits": {
    • "total"2,
    • "max_score"0.6099695,
    • "hits": [
      • {
        • "_index""test_index",
        • "_type""fulltext",
        • "_id""4",
        • "_score"0.6099695,
        • "_source": {
          • "content""中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
          },
        • "highlight": {
          • "content": [
            • "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
            ]
          }
        },
      • {
        • "_index""test_index",
        • "_type""fulltext",
        • "_id""3",
        • "_score"0.27179778,
        • "_source": {
          • "content""中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
          },
        • "highlight": {
          • "content": [
            • "中韩渔警冲突调查:韩警平均每天扣1艘<tag1>中国</tag1>渔船"
            ]
          }
        }
      ]
    }
}


参考资料:

官方文档:https://github.com/medcl/elasticsearch-analysis-ik

原创粉丝点击