IK官网:https://github.com/medcl/elasticsearch-analysis-ik/releases如下图:下载对应版本即可
1、进入elasticsearch安装目录,执行以下命令(elasticsearch-analysis-ik可以下载对应版本):
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.1/elasticsearch-analysis-ik-6.3.1.zip
2、安装完毕之后 重启elasticsearch
3、使用:查询是要带: -H 'Content-Type: application/json'
查看集群中所有的索引:
curl -X GET 'http://192.168.1.107:9200/_cat/indices?v'
查看集群的所有节点
curl -X GET 'http://192.168.1.107:9200/_cat/nodes?v'
查看集群的健康情况
curl -X GET 'http://192.168.1.107:9200/_cat/health?v'
1.create a index:创建索引
curl -XPUT http://localhost:9200/index
2.create a 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" } }}'
3.index some docs
curl -XPOST http://localhost:9200/index/fulltext/1 -H 'Content-Type:application/json' -d'{"content":"美国留给伊拉克的是个烂摊子吗"}'
curl -XPOST http://localhost:9200/index/fulltext/2 -H 'Content-Type:application/json' -d'{"content":"公安部:各地校车将享最高路权"}'
curl -XPOST http://localhost:9200/index/fulltext/3 -H 'Content-Type:application/json' -d'{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}'
curl -XPOST http://localhost:9200/index/fulltext/4 -H 'Content-Type:application/json' -d'{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}'
4.query with highlighting
curl -XPOST http://localhost:9200/index/fulltext/_search -H 'Content-Type:application/json' -d'{ "query" : { "match" : { "content" : "中国" }}, "highlight" : { "pre_tags" : ["", ""], "post_tags" : ["", ""], "fields" : { "content" : {} } }}'
-- Elastic 默认一次返回10条结果,可以通过size字段改变这个设置
curl 'localhost:9200/index/fulltext/_search' -H 'Content-Type: application/json' -d '
{
"query" : { "match" : { "content" : "中国" }},
"size": 1
}'
-- 还可以通过from字段,指定位移
curl 'localhost:9200/index/fulltext/_search' -H 'content-Type: application/json' -d '
{
"query" : { "match" : { "content" : "中国" }},
"from": 1,
"size": 1
}'
-- Elastic or 操作
curl 'localhost:9200/index/fulltext/_search' -H 'content-Type: application/json' -d '
{
"query" : { "match" : { "content" : "中国 公安" }}
}'
-- and搜索
curl 'localhost:9200/index/fulltext/_search' -H 'content-Type: application/json' -d '
{
"query": {
"bool": {
"must": [
{ "match": { "content": "渔船" } },
{ "match": { "content": "中国" } }
]
}
}
}'
向/Index/Type/Id发出 GET 请求,就可以查看这条记录,URL 的参数pretty=true表示以易读的格式返回,found字段表示查询成功,_source字段返回原始记录,如果 Id 不正确,就查不到数据,found字段就是false
curl -XGET localhost:9200/index/fulltext/2?pretty=true
查询所有记录:curl -XGET localhost:9200/index/fulltext/_search?pretty=true
删除记录就是发出 DELETE 请求