一. 汇总
查看某个索引下所有文档:curl 'http://localhost:9200/index/_search?q=*&pretty'
搜索某个索引下的某个文档,精确匹配
curl http://localhost:9200/index/_doc/id?pretty
curl http://localhost:9200/index/_search?pretty&q=key:value
curl -H 'Content-Type:application/json' 'http://localhost:9200/index/_search?pretty' -d '{"query":{"match":{"key":"value"}}}'
二. 详细
1. 查看es整体情况
http://host:port/_cat/indices?v
在浏览器中输入第三个地址,(v表示结果中返回表头)就会出现下图的表头和相关索引信息
health有三种状态:
green:最佳状态
yellow:数据和集群可用,但集群备份是坏的,一般单个节点的es就是yellow
red:数据和集群不可用
2. 添加索引&向索引中添加文档
索引名:yuhantest(索引不能有大写字母,否则会报错)
curl -X PUT http://host:port/yuhantest?pretty
curl -X PUT 'http://host:port/yuhantest/_doc/id?pretty' -H 'Content-Type:application/json' -d '{"key":"value"}'
3. 查询索引中文档信息
查询索引中所有文档信息(pretty的作用是将返回参数以json格式展示)
curl 'http://host:port/index/_search'
curl 'http://host:port/index/_search?q=*'
curl 'http://host:port/index/_search?q=*&pretty'
查询某个文档的信息
已知id:
curl ‘http://host:port/{id}?pretty’
已知:doc中的key/value值
curl http://host:port/index/_search?pretty&q=key:value
curl -H 'Content-Type:application/json' 'http://host:port/index/_search?pretty' -d '{"query":{"match":{"key":"value"}}}'
4. 删除索引
curl -X DELETE http://host:port/yuhantest
三. curl命令简介
常用指令:
-X :设置请求方式,默认为GET,还有POST, 还有PUT,DELETE
-I:打印返回报文的http头信息
-H:设置请求头,最常见的有-H 'Content-Type:application/json'
-d:POST请求方式下设置参数