es常用命令小结

查看索引

curl -XGET localhost:9200/_cat
获取所有_cat系列的操作
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
以上的命令中,你也可以后面加一个v,让输出内容表格显示表头

删除索引

curl -X DELETE 'http://server_ip:port/*索引名*'

# 注:新版本es5以后,get获取索引不支持*正则,delete操作支持
# curl -X GET 'http://server_ip:port/*索引名*' 

操作索引

1、获取索引
curl -XGET 'http://localhost:9200/{index}/{type}/{id}'
2、索引数据
curl -XPOST 'http://localhost:9200/{index}/{type}/{id}’ -d’{“a”:”avalue”,”b”:”bvalue”}'
3、删除索引
curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'
4、设置mapping
curl -XPUT http://localhost:9200/{index}/{type}/_mapping -d ‘{
“{type}” : {
“properties” : {
“date” : {
“type” : “long”
},
“name” : {
“type” : “string”,
“index” : “not_analyzed”
},
“status” : {
“type” : “integer”
},
“type” : {
“type” : “integer”
}
}
}
}’
5、获取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping
6、搜索

curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
“query” : {
“term” : { “user” : “kimchy” } //查所有 “match_all”: {}
},
“sort” : [{ “age” : {“order” : “asc”}},{ “name” : “desc” } ],
“from”:0,
“size”:100
}
curl -XGET 'http://localhost:9200/{index}/{type}/_search' -d '{
“filter”: {“and”:{“filters”:[{“term”:{“age”:“123”}},{“term”:{“name”:“张三”}}]},
“sort” : [{ “age” : {“order” : “asc”}},{ “name” : “desc” } ],
“from”:0,
“size”:100
}
7. 追加索引字段
curl -XPUT 'http://localhost:9200/index/_mapping' -d '{"properties":{"tb_name":{"type": "keyword"}}}' -H "Content-Type: application/json"

你可能感兴趣的:(es常用命令小结)