ES常用基础操作命令
目录
-u xxx:xxx 为访问时序库的账号名/密码 格式 -u 用户名:密码
ip:port 为时序库节点的IP地址和端口号
?后面接查询的参数、\&
拼接多个参数,如v为显示表头、s为按字段排序、format为数据格式,例子:GET _cat/nodes?v\&s=ip
查询所有metric
curl -u xxx:xxx -H 'Content-Type:application/json' -X GET ip:port/_metrics
查询metric信息
curl -u xxx:xxx -H 'Content-Type:application/json' -X GET ip:port/_metric/new_test // 表名
查询索引信息
curl -u xxx:xxx -H 'Content-Type:application/json' -X GET ip:port/new_test@xxx // 子表名
metric数据查询
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/my_es_test02/_search
metric数据条件查询,查询条件适配ES原生查询条件
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/my_es_test02/_search -d '{}'
metric数据量查询
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/my_es_test02/_count
metric类SQL查询
curl -u xxx:xxx -H 'Content-Type: application/json' -XGET ip:port/_nlpcn/sql?pretty -d 'select count(*) from my_es_test02'
创建metric
curl -u xxx:xxx -H 'Content-Type:application/json' -X PUT ip:port/_metric/nw_test -d'
{
"tags" : {
"id" : "string",
"dev_id" : "string"
},
"time" : {
"name" : "timestamp",
"format" : "epoch_second"
},
"fields" : {
"monitor_value" : "string"
}
}'
数据写入
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/my_es_test01/_doc -d'{"id":"1","dev_id":"did1","monitor_value":"1","timestamp":1699669981}';
批量数据写入
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/new_test/_doc/_bulk -d'
{"index":{}}
{"id":"1","dev_id":"0055ed6e-4506-43af-a1ae-cf72b8ec413f","dev_name":"配电房水浸","getway_name":"紫南沙边配电房","monitor_project":"serviceWater","monitor_type":"tgStatus","monitor_value":"1","timestamp":1618070412}
{"index":{}}
{"id":"2","dev_id":"0055ed6e-4506-43af-a1ae-cf72b8ec413f","dev_name":"配电房水浸","getway_name":"紫南沙边配电房","monitor_project":"serviceWater","monitor_type":"tgStatus","monitor_value":"0","timestamp":1618070414}
'
删除metric
curl -u xxx:xxx -XDELETE ip:port/_metric/del_test
删除子表(索引)
curl -u xxx:xxx -H 'Content-Type:application/json' -X DELETE ip:port/new_test@xxx
删除metric数据
curl -u xxx:xxx -H 'Content-Type:application/json' -X POST ip:port/my_es_test01/_delete_by_query -d '{}'
查询分片数据
curl -u xxx:xxx ip:port/_cat/shards?v\&s=docs
查询index
curl -u xxx:xxx ip:port/_cat/indices?v
curl -u xxx:xxx ip:port/_cat/indices/xxx?v
查询集群状态
curl -u xxx:xxx ip:port/_cat/health
curl -u xxx:xxx ip:port/_cluster/health?v
查询集群节点
curl -u xxx:xxx ip:port/_cat/nodes?v\&s=ip
查询初始化中的分片
curl -u xxx:xxx ip:port/_cat/recovery?active_only