ElasticSearch 常用API操作

  • 别名查看
curl -s IP:9200/performance_v1_20200225/_alias?pretty
  • 创建别名
curl -XPOST "IP:9200/_aliases"  -H 'Content-Type: application/json'  -d 
	'{"actions" : [{ "add" : { "index" : "index_par_rel_v4", "alias" : "index_par_rel2" } }]}'
  • 删除别名
curl -XPOST "IP:9200/_aliases"  -H 'Content-Type: application/json'  -d 
	'{"actions" : [{ "remove" : { "index" : "index_par_rel_v4",  "alias" : "index_par_rel" } }]}'
  • 查询分片大小
curl -XGET http://192.168.92.128:9201/_cat/shards
curl -XGET http://192.168.92.128:9201/_cat/shards |grep gb
  • 查看未分配的分片
curl -s -XGET http://192.168.0.12:9200/_cat/shards|grep -v START
  • 查看索引信息
curl -s ip:9200/_cat/indices/index_name  
[green open name id 主分片数 副本数 doc条数 doc删除过的条数 store大小 主分片大小]
  • 模板查看
curl -XGET localhost:9200/_cat/templates  查看所有模板名称
curl -XGET localhost:9200/_template/template_1  查看 template_1 模板的内容
  • 查看集群任务
curl -s -XGET http://191.168.92.128:9200/_cat/tasks?v|grep -Ev ''monitor|write"
  • 查看等待执行的任务
curl -s -XGET http://191.168.92.128:9200/_cat/pening_task?v
  • 查看节点的热线程
curl -s -XGET http://191.168.92.128:9200/_node/hot_threads|less
  • 查询节点资源使用情况 ,查看nodes的的属性
curl -s -XGET "http://192.168.92.129:9200/_cat/nodes?v
ip            heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.21.50           52          99   6    0.12    0.29     0.28 mdi       *      IRQAfVp

ip:集群中节点的ip地址
heap.percent:  堆内存的占用百分比
ram.percent:   总内存的占用百分比,其实这个不是很准确,因为 buff/cache和available 也被当作使用内存
cpu:            cpu占用百分比
load_1m:        1分钟内cpu负载
load_5m:        5分钟内cpu负载
load_15m:       15分钟内cpu负载
node.role:      mdi分别表示 master、data、ingest
master:*        *代表是master节点,- 代表普通节点
name:           节点的名称
  • 修改索引settings
-- 索引分片不分配到192.168.0.x的主机
curl -s -XPUT http://192.168.92.128:9200/logindex-2019-09-21/_settings -H 'Content-Type:application/json' -d '
    { "settings":{"index.routing.allocation.exclude._ip":"192.168.0.*"}}'
-- 每个节点可以分配3个相同的分片
curl -s -XPUT http://192.168.92.128:9200/logindex-2019-09-21/_settings -H 'Content-Type:application/json' -d '
    { "routing.allocation.total_shards_per_node":"3"}'
  • 查询ES聚合脚本内容
curl -s -XGET http://192.168.92.128:9200/_scripts/脚本名字?pretty    
  • 查看所有聚合脚本名称以及内容
curl -s "http://192.168.92.128:9200/_cluster/state/metadata?pretty&filter_path=metadata.stored_scripts"
  • 集群健康查看, 使用带有用户名密码的方式
curl -s 'https://nginx:123456@192.168.92.128:92/00/_cluster/health?pretty'
  • 查看分片状态,使用带有用户名密码的方式
curl -kg -XGET https://logstash:logstash@localhost:9200/_cat/shards?v
  • 查看分片不分配的原因
curl -s -XPOST -H 'Content-Type: application/json' http://192.168.92.128:9201/_cluster/allocation/explain?pretty -d '
{
    "index": "test",
    "shard": 4,
    "primary": false
}
  • 分片自动分配重试次数超出默认次数后报错
# 如果出现 类似 报错 "explanation": "shard has exceeded the maximum number of retries [5] on failed allocation attempts - manually call
# curl -s -H 'Content-Type:application/json' -XPOST 192.168.1.63:9200/_cluster/reroute?retry_failed=true
即可将这类分片重新分配
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值