简单的认为是能够在命令行下面访问url的一个工具,使用curl能够简单实现常见的get/post请求。curl命令详解node
curl 命令:linux
-X 指定http的请求方法 有HEAD GET POST PUT DELETE -d 指定要传输的数据 -H 指定http请求头信息 -i 获取响应头
用于获取Elasticsearch集群状态接口json
curl -XGET 'http://localhost:9200/_cat'
接口展现:app
=^.^= /_cat/allocation /_cat/shards /_cat/shards/{index} /_cat/master /_cat/nodes /_cat/tasks /_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/thread_pool/{thread_pools} /_cat/plugins /_cat/fielddata /_cat/fielddata/{fields} /_cat/nodeattrs /_cat/repositories /_cat/snapshots/{repository} /_cat/templates
1.集群系统信息,包括CPU JVM等curl
curl -XGET 'https://localhost:9200/_cluster/stats?pretty=true'
2.集群的详细信息,节点、分片等elasticsearch
curl -XGET 'http://localhost:9200/_cluster/state?pretty=true'
3.集群堆积的任务工具
curl -XGET 'http://localhost:9200/_cluster/pending_tasks?pretty=true'
1.关闭集群节点post
curl -XPOST 'http://localhost:9200/_cluster/nodes/127.0.0.1/_shutdown'
2.关闭主节点url
curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown'
3.关闭整个集群spa
curl -XPOST 'http://localhost:9200/_cluster/nodes/_all/_shutdown'
curl -XGET 'http://localhost:9200/_cat/indices?v'
1.命令建立:
curl -XPUT 'http://localhost:9200/city' 结果: { "acknowledged": true, "shards_acknowledged": true, "index": "city" }
2.elasticsearch-head建立:
3.删除索引
curl -XDELETE 'http://localhost:9200/account'
curl -H 'Content-Type: application/json' -XPOST 'http://localhost:9200/city/south/1' -d '{"cityName":"guangzhou"}'
结果
{ "_index":"city", "_type":"south", "_id":"1", "_version":1, "result":"created", "_shards":{ "total":2, "successful":2, "failed":0 }, "_seq_no":0, "_primary_term":1 }
curl -i -XGET 'http://localhost:9200/city/south/1'
结果
{ "_index":"city", "_type":"south", "_id":"1", "_version":1, "found":true, "_source":{ "cityName":"guangzhou" } }
curl -XDELETE 'http://localhost:9200/city/south/1'
结果
{ "_index":"city", "_type":"south", "_id":"1", "_version":2, "result":"deleted", "_shards":{ "total":2, "successful":2, "failed":0 }, "_seq_no":1, "_primary_term":1 }
curl -i -H 'Content-Type: application/json' -XPUT 'http://localhost:9200/city/south/1' -d '{"cityName":"HUNAN"}'
结果
HTTP/1.1 200 OK content-type: application/json; charset=UTF-8 content-length: 153 { "_index":"city", "_type":"south", "_id":"1", "_version":2, "result":"updated", "_shards":{ "total":2, "successful":2, "failed":0 }, "_seq_no":3, "_primary_term":2 }