elasticSearch curl 语法总结

#创建索引
a.put创建
curl -XPUT http://localhost:9200/shb01/student/1-d'{"name":"jack","age":30,"info":"Ilove you"}'
返回:{"_index":"shb01","_type":"student","_id":"1","_version":1,"created":true}
执行put后有返回值
_index索引名称
_type类型名
_version版本号
created:true表示是新创建的。
上面的命令每执行一次version就会加1,-XPUT必须制定id。

b.post创建
curl -XPOST http://localhost:9200/shb01/student -d'{"name":"tom","age":21,"info":"tom"}'
返回:{"_index":"shb01","_type":"student","_id":"AVadzuNgxskBS1Rg2tdp","_version":1,"created":true}

#查看es集群状态
http://ip:port/_cat/health?v

#集群节点健康查看
http://ip:port/_cat/nodes?v

#查询所有索引,pretty:格式化
curl -XGET 'localhost:9200/_cat/indices?v&pretty'

#查询返回最近10条
curl -XPOST 'localhost:9200/logstash-zhifubao-2018.09.18/_search?pretty' -d '{"query": { "match_all": {} },"from": 10,"size": 10}'

#查询索引状态
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_status

#查询某一个索引
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/message/0ea1b2df-caa4-457c-8cc1-294f5e9284c7/_search?pretty

#根据business_no查询,多个条件用逗号拼接
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_search?q=message:0ea1b2df-caa4-457c-8cc1-294f5e9284c7
#根据business_no查询,只返回特定字段
curl -XGET http://localhost:9200/logstash-zhifubao-2018.08.15/_search?q=message:0ea1b2df-caa4-457c-8cc1-294f5e9284c7?_source=message

#查询集群状态
Curl –XGET http://localhost:9200/_cluster/health?pretty
http://localhost:9200/_cluster/health?pretty

#多索引,多类型查询,分页查询,超时
Curl:curl -XGET http://localhost:9200/shb01,shb02/stu,tea/_search?pretty
curl -XGET http://localhost:9200/_all/stu,tea/_search?pretty

#分页
curl -XGET http://localhost:9200/shb01/stu/_search?size=2&from=0

#更新部分字段
crul –XPUT http:localhost:9200/shb01/student/1/_update?version=1
–d ‘{“doc”:{“name”:”updatename”}

#根据id删除
curl -XDELETE http://localhost:9200/shb01/student/AVad05EExskBS1Rg2tdq

#删除所有的索引库中名称为tom的文档
curl -XDELETE http://localhost:9200/_all/_query?q=name:tom

#批处理
a.在/usr/local/下新建t.txt文件,文件内容为
{"index":{"_index":"shb01","_type":"student","_id":"1"}}
{"name":"st01","age":"10","info":"st01"}
{"create":{"_index":"shb100","_type":"student","_id":"2"}}
{"name":"tea01","age":"10","info":"tea01"}
{"delete":{"_index":"shb01","_type":"student","_id":"AVadzuNgxskBS1Rg2tdp"}
{"update":{"_index":"shb02","_type":"tea","_id":"1"}}
{"doc":{"name":"zszszszs"}}
b.执行批处理命令,关键字_bulk
curl -XPUThttp://localhost:9200/_bulk --data-binary @/usr/local/t


#_cluster系列
1、查询设置集群状态
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true表示格式化输出
level=indices 表示显示索引状态
level=shards 表示显示分片信息
2、curl -XGET localhost:9200/_cluster/stats?pretty=true
显示集群系统信息,包括CPU JVM等等
3、curl -XGET localhost:9200/_cluster/state?pretty=true
集群的详细信息。包括节点、分片等。
3、curl -XGET localhost:9200/_cluster/pending_tasks?pretty=true
获取集群堆积的任务


#索引参数相关
URL 说明
/index/_search 不解释
/_aliases 获取或操作索引的别名
/index/
/index/type/ 创建或操作类型
/index/_mapping 创建或操作mapping
/index/_settings 创建或操作设置(number_of_shards是不可更改的)
/index/_open 打开被关闭的索引
/index/_close 关闭索引
/index/_refresh 刷新索引(使新加内容对搜索可见)
/index/_flush
刷新索引
将变动提交到lucene索引文件中
并清空elasticsearch的transaction log,
与refresh的区别需要继续研究
/index/_optimize 优化segement,个人认为主要是对segement进行合并
/index/_status 获得索引的状态信息
/index/_segments 获得索引的segments的状态信息
/index/_explain 不执行实际搜索,而返回解释信息
/index/_analyze 不执行实际搜索,根据输入的参数进行文本分析
/index/type/id 操作指定文档,不解释
/index/type/id/_create 创建一个文档,如果该文件已经存在,则返回失败
/index/type/id/_update 更新一个文件,如果改文件不存在,则返回失败

#集群参数相关
URL 说明
/_cluster/nodes 获得集群中的节点列表和信息
/_cluster/health 获得集群信息
/_cluster/state 获得集群里的所有信息(集群信息、节点信息、mapping信息等)

#Nodes参数相关
URL 说明
/_nodes/process 我主要看file descriptor 这个信息
/_nodes/process/stats 统计信息(内存、CPU能)
/_nodes/jvm 获得各节点的虚拟机统计和配置信息
/_nodes/jvm/stats 更详细的虚拟机信息
/_nodes/http 获得各个节点的http信息(如ip地址)
/_nodes/http/stats 获得各个节点处理http请求的统计情况
/_nodes/thread_pool
获得各种类型的线程池
(elasticsearch分别对不同的操作提供不同的线程池)的配置信息
/_nodes/thread_pool/stats 获得各种类型的线程池的统计信息

以上这些操作和可以通过如
/_nodes/${nodeId}/jvm/stats
/_nodes/${nodeip}/jvm/stats
/_nodes/${nodeattribute}/jvm/stats
的形式针对指定节点的操作。

猜你喜欢

转载自www.cnblogs.com/jiangds/p/9669838.html