github地址
https://github.com/medcl/elasticsearch-analysis-ik
下载对应的版本
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.2.4/elasticsearch-analysis-ik-6.2.4.zip
移动至es目录下的plugins
mv elasticsearch-analysis-ik-6.2.4.zip ./elasticsearch-6.2.4/plugins/
解压,并重启
unzip elasticsearch-analysis-ik-6.2.4.zip rm elasticsearch-analysis-ik-6.2.4.zip
测试
创建index
curl -XPUT http://localhost:9200/index
创建mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -H 'Content-Type:application/json' -d' { "properties": { "content": { "type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_max_word" } } }'
创建docs
curl -XPOST http://localhost:9200/index/fulltext/1 -H 'Content-Type:application/json' -d' {"content":"中华人民共和国"} '
高亮查询
curl -XPOST http://localhost:9200/index/fulltext/_search -H 'Content-Type:application/json' -d' { "query" : { "match" : { "content" : "中华" }}, "highlight" : { "pre_tags" : ["<tag1>", "<tag2>"], "post_tags" : ["</tag1>", "</tag2>"], "fields" : { "content" : {} } } } '
返回
{ "took": 186, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 1, "max_score": 0.2876821, "hits": [ { "_index": "index", "_type": "fulltext", "_id": "1", "_score": 0.2876821, "_source": { "content": "中华人民共和国" }, "highlight": { "content": [ "<tag1>中华</tag1>人民共和国" ] } } ] } }