Elasticsearch IK分词插件安装

插件安装

1
2
3
4
### 当前版本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索引
    1
    curl -XPUT http://localhost:9200/my_index
  • 设置索引映射关系制定分词组件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    curl -XPOST http://localhost:9200/my_index/fulltext/_mapping -d'
    {
    "properties": {
    "content": {
    "type": "text",
    "analyzer": "ik_max_word",
    "search_analyzer": "ik_max_word"
    }
    }

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

参考地址