elasticsearch 通过curl的操作

1:curl

curl -h来查看请求参数的含义
-v 显示请求的信息
-X 选项指定其它协议

get:
    curl -v 127.0.0.1:8080/users/age/18
    
post:
    curl -v 127.0.0.1:8080/users -d 'age=14&cupSize=C'
    curl -v -X POST 127.0.0.1:8080/users -d 'age=14&cupSize=C'
    
put:
    curl -v -X PUT -d "age=19&cupSize=C" 127.0.0.1:8080/users/3

delete:
    curl -v -X DELETE 127.0.0.1:8080/users/3

2:elasticsearch 

检查运行

root@micro-node3:/opt/application# curl http://localhost:9200/
{
  "name" : "micro-node3",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "B6DsBJbGSp6UMc-uxKC1zg",
  "version" : {
    "number" : "7.3.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "de777fa",
    "build_date" : "2019-07-24T18:30:11.767338Z",
    "build_snapshot" : false,
    "lucene_version" : "8.1.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

集群健康

root@micro-node3:/opt/application# curl -X GET localhost:9200/_cat/health?v
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1634371100 07:58:20  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0%

请求集群健康时,会得到green, yellow, 或者 red 这三种状态。

  • Green : everything is good(一切都很好)(所有功能正常)
  • Yellow : 所有数据都是可用的,但有些副本还没有分配(所有功能正常)
  • Red : 有些数据不可用(部分功能正常)

节点列表

root@micro-node3:/opt/application# curl -X GET "localhost:9200/_cat/nodes?v"
ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           25          59   0    0.00    0.00     0.00 dim       *      micro-node3

查看全部索引
curl 127.0.0.1:9200/_cat/indices?v
创建一个索引
curl -X PUT "localhost:9200/js_goods?pretty"
查看一个索引
curl 127.0.0.1:9200/js_goods?pretty
创建一个索引
curl -v -X DELETE 127.0.0.1:9200/js_goods 

上一篇:gRPC详细入门介绍


下一篇:分布式之gRPC概念+.net core 鉴权授权