Every day to be a little better

elasticsearch IK分词插件安装

插件安装

### 当前版本elasticsearch-5.5.1
./elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.1/elasticsearch-analysis-ik-5.5.1.zip
### 安装完重启
./elasticsearch-5.5.1/bin/elasticsearch -d

创建索引测试分词

  • 创建elasticsearch索引
curl -XPUT http://localhost:9200/my_index
  • 设置索引映射关系制定分词组件
curl -XPOST http://localhost:9200/my_index/fulltext/_mapping -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }

}'
  • 添加测试数据
curl -XPOST http://localhost:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
'
curl -XPOST http://localhost:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
'
curl -XPOST http://localhost:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
'
  • 查询测试
curl -XPOST http://localhost:9200/index/fulltext/_search  -d'
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
'

参考地址

  • https://github.com/medcl/elasticsearch-analysis-ik

未经允许不得转载:奇葩菌博客 » elasticsearch IK分词插件安装

分享到:更多 ()