elasticsearch运维常用API

查看集群状态

  1. 查询集群状态命令:

    curl -XGET "http://ip:port/_cluster/health?pretty"
    # ?pretty json打印结果
  2. 查询集群JVM状态

    curl -XGET "http://ip:port/_nodes/stats/jvm?pretty"
    
    #查看具体某一个
    curl -XGET "http://ip:port/_nodes/nodeName/stats/jvm?pretty"
  3. 查询Es全局状态:

    curl -XGET "http://ip:port/_cluster/stats?pretty"
  4. 查看集群分配情况

    curl -XGET "http://ip:port/_cluster/allocation/explain?pretty"
  5. 查询集群设置

    curl -XGET "http://ip:port/_cluster/settings?pretty"
  6. 查询所有索引

    # ?v 输出统计信息表头
    curl -XGET "http://ip:port/_cat/indices?v"
    # 如果通配符过滤
    curl -XGET "http://ip:port/_cat/indices/*2022*?v"
  7. 查看集群文档总数

    curl -XGET "http://ip:port/_cat/count?v"
    #  仅输入`_cat/` 会返回所有可输入命令。
  8. 查看集群别名组

    curl -XGET "http://ip:port/_cat/aliases"
  9. 查看当前集群索引分片信息

    curl -XGET "http://ip:port/_cat/shards?v"
    # 注:查看某一个索引可用shards/索引名?v
  10. 查看集群实例存储详细信息

    curl -XGET "http://ip:port/_cat/allocation?v"
  11. 查看当前集群的所有实例

    curl -XGET "http://ip:port/_cat/nodes?v"
    
    - nodes.role角色
    c : cold node
    d : data node
    f : frozen node
    h : hot node
    i : ingest node
    l : machine learning node
    m : master eligible node
    r : remote cluster client node
    s : content node
    t : transform node
    v : voting-only node
    w : warm node
  12. 查看某索引分片转移进度

    curl -XGET "http://ip:port/_cat/recovery/索引名?v"
  13. 查看当前集群等待任务

    curl -XGET "http://ip:port/_cat/pending_tasks?v"
  14. 查看集群写入线程池任务

    curl -XGET "http://ip:port/_cat/thread_pool/bulk?v"
  15. 查看集群查询线程池任务

    curl -XGET "http://ip:port/_cat/thread_pool/search?v"
  16. 查看分片未分配的原因

    curl -XGET "http://ip:port/_cat/shards?v&h=index,shard,prirep,state,node,unassigned.reason" | grep UNASSIGNED
  17. 查看集群所有的默认配置

    curl -XGET 'http://ip:port/cluster/settings?pretty&include_defaults=true&filter_path=**.index'

集群相关操作

  1. 设置集群分片恢复参数

    curl --request PUT \
    --url http://ip:port/_cluster/settings \
    --header 'content-type: application/json' \
    --data '{
    "transient": {
    "cluster.routing.allocation.node_initial_primaries_recoveries": 60,
    "cluster.routing.allocation.node_concurrent_recoveries": 30,
    "cluster.routing.allocation.cluster_concurrent_rebalance": 30
    }
    }' # 或者
    curl -XPUT "http://ip:port/_cluster/settings" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.exclude._name": "EsNode2@ip" } }'
  2. 根据实例名称使EsNodeX实例下线

    curl --request PUT \
    --url http://ip:port/_cluster/settings \
    --header 'content-type: application/json' \
    --data '{
    "transient": {
    "cluster.routing.allocation.exclude._name": "EsNode2@ip"
    }
    }' # 或者
    curl -XPUT "http://ip:port/_cluster/settings" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.exclude._name": "EsNode2@ip" } }'
  3. 根据ip使ES数据节点下线:

    curl --request PUT \
    --url http://ip:port/_cluster/settings \
    --header 'content-type: application/json' \
    --data '{
    "transient": {
    "cluster.routing.allocation.exclude._ip": "ip1,ip2,ip3"
    }
    }'
    # 或者
    curl -XPUT "http://ip:port/_cluster/settings" -H 'Content-Type: application/json' -d' { "transient": { "cluster.routing.allocation.exclude._ip": "ip1,ip2,ip3" } }'
  4. 设置分片恢复过程中的最大带宽速度:

    curl --request PUT \
    --url http:/ip:port/_cluster/settings \
    --header 'content-type: application/json' \
    --data '{
    "transient": {
    "indices.recovery.max_bytes_per_sec": "500mb"
    }
    }' # 或者
    curl -XPUT "http://ip:port/_cluster/settings" -H 'Content-Type: application/json' -d'{ "transient":{ "indices.recovery.max_bytes_per_sec":"500mb" }}'
  5. 重新分配索引到 分片数为空的节点上(恢复数据)

    curl --request PUT \
    --url http://47.93.55.229:8118/_cluster/reroute \
    --header 'content-type: application/json' \
    --data '{
    "commands": [
    {
    "allocate_empty_primary": {
    "index": "indexname",
    "shard": 2,
    "node": "EsNode1@81.20.5.24",
    "accept_data_loss": true
    }
    }
    ]
    }' # 或者
    curl -XPOST "http://ip:port/_cluster/reroute?pretty" -H 'Content-Type:application/json' -d '{ "commands": [{ "allocate_empty_primary": { "index": "indexname", "shard": 2, "node": "EsNode1@81.20.5.24", "accept_data_loss":true } }]}'
  6. 重新分配索引到 副本分片所在的节点上(恢复数据)

    curl --request PUT \
    --url http://47.93.55.229:8118/_cluster/reroute \
    --header 'content-type: application/json' \
    --data '{
    "commands": [
    {
    "allocate_stale_primary": {
    "index": "indexname",
    "shard": 2,
    "node": "EsNode1@81.20.5.24",
    "accept_data_loss": true
    }
    }
    ]
    }' # 或者
    curl -XPOST "http://ip:port/_cluster/reroute?pretty" -H 'Content-Type:application/json' -d '{ "commands": [{ "allocate_stale_primary": { "index": "indexname", "shard": 2, "node": "EsNode1@81.20.5.24", "accept_data_loss":true }
  7. 清理ES所有缓存

    curl -XPOST "http://ip:port/_cache/clear"
  8. 关闭分片自动平衡

    curl -XPUT "http://ip:port/_cluster/settings" -H 'Content-Type:application/json' -d '{   "transient":{   "cluster.routing.rebalance.enable":"none" }}'
  9. 手动刷新未分配的分片

    curl -XPOST "http://ip:port/_cluster/reroute?retry_failed=true"
  10. 关闭索引只读状态

    curl -XPUT 'http://127.0.0.1:9200/_all/_settings' -H "Content-Type: application/json"  -d '{"index.blocks.read_only_allow_delete": false}'

查询索引状态、信息

  1. 查看字符串分词情况

    # 查看分词器的分词效果
    curl --request POST \
    --url http://47.93.55.229:8118/_analyze \
    --header 'content-type: application/json' \
    --data '{"analyzer":"standard","text":"这是一个测试"}'
    # 查看索引某个字段的分词效果
    curl --request POST \
    --url http://47.93.55.229:8118/indexName/_analyze \
    --header 'content-type: application/json' \
    --data '{"field": "title","text": "这是一个测试"}'
  2. 查看具体文档中某个字段的分、词情况

    curl -XGET "http://ip:port/index/type/id/_termvectors?fields=${field}""
  3. 查询索引mapping和setting

    # 查询mapping和setting
    curl -XGET 'http://ip:port/my_index_name?pretty' #查询setting
    curl -XGET 'http://ip:port/my_index_name/_settings?pretty' #查询mapping
    curl -XGET 'http://ip:port/my_index_name/_mappings?pretty'
  4. 获取索引所有的配置,包括默认的

    curl -XGET 'http://ip:port/_all/_settings?include_defaults=true'

索引相关操作

  1. 关闭索引

    curl -XPOST 'http://ip:port/my_index/_close?pretty'
  2. 开启索引

    curl -XPOST 'http://ip:port/my_index/_open?pretty'
  3. 修改索引刷新时间refresh_interval

    curl -XPUT 'http://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"refresh_interval" : "60s"}'
  4. 修改translog文件保留时长,默认为12小时

    curl -XPUT 'http://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"index.translog.retention.age" : "30m"}'
  5. 设置索引副本:大量写数据,刷数据,可以临时关闭副本,写完再开启

    curl -XPUT 'http://ip:port/my_index/_settings?pretty' -H 'Content-Type: application/json' -d'{"number_of_replicas" : 1}'
  6. 执行refresh,将内存数据刷新到磁盘缓存

    curl -XPOST 'http://ip:port/myindex/_refresh'
  7. 执行flush,将磁盘缓存刷新到文件系统

    curl -XPOST 'https://ip:port/myindex/_flush'
  8. 执行synced flush,生成syncid

    curl -XPOST  'http://ip:port/_flush/synced'
  9. 强制执行段合并

    curl -XPOST 'http://ip:port/myindex/_forcemerge?only_expunge_deletes=false&max_num_segments=1&flush=true&pretty'
  10. 设置索引在每个esnode上的分片个数

    curl -XPUT 'http://ip:port/myindex/_settings?pretty' -H 'Content-Type: application/json' -d'{"index.routing.allocation.total_shards_per_node" : "2"}'
  11. 配置控制段合并的refresh、merge线程数等

    curl --request PUT \
    --url 'http://ip:port8/my_index/_settings?pretty=' \
    --header 'content-type: application/json' \
    --data '{
    "refresh_interval": "60s",
    "merge": {
    "scheduler": {
    "max_merge_count": "100",
    "max_thread_count": "1"
    },
    "policy": {
    "segments_per_tier": "100",
    "floor_segment": "1m",
    "max_merged_segment": "2g"
    }
    }
    }' # 或者
    curl -XPUT "http://ip:port/my_index/_settings?pretty" -H 'Content-Type: application/json' -d'{"refresh_interval": "60s","merge":{"scheduler":{"max_merge_count" : "100","max_thread_count" : "1"},"policy":{"segments_per_tier" : "100","floor_segment" : "1m","max_merged_segment" : "2g"}}}'
  12. 设置索引的刷新时间和translog配置参数

    # 设置translog参数,必须先关闭索引,设置完成后再打开
    
    curl --request PUT \
    --url 'http://47.93.55.229:8118/my_index/_settings?pretty=' \
    --header 'content-type: application/json' \
    --data '{
    "index": {
    "refresh_interval": "60s",
    "translog": {
    "flush_threshold_size": "1GB",
    "sync_interval": "120s",
    "durability": "async"
    }
    }
    }' # 或者 curl -XPUT "http://ip:httpport/*/_settings" -H 'Content-Type: application/json' -d'{ "index":{ "refresh_interval" : "60s","translog":{ "flush_threshold_size": "1GB", "sync_interval": "120s", "durability": "async"}}}'

elastic常用api的更多相关文章

  1. Elasticsearch-02-入门:集群、节点、分片、索引及常用API

    2. 基础入门 2.1 重要概念 2.1.1 集群和节点 1)cluster Elasticsearch集群是由一个或多个节点组成,通过其集群名称来进行唯一标识.节点在搜索到集群之后,通过判断自身的 ...

  2. html5 canvas常用api总结(一)

    1.监听浏览器加载事件. window.addEventListener("load",eventWindowLoaded,false); load事件在html页面加载结束时发生 ...

  3. compass General 常用api学习[Sass和compass学习笔记]

    compass 中一些常用api 包括一些浏览器hack @import "compass/utilities/general" Clearfix Clearfix 是用来清除浮动 ...

  4. java基础3.0:Java常用API

    本篇介绍Java基础中常用API使用,当然只是简单介绍,围绕重要知识点引入,巩固开发知识,深入了解每个API的使用,查看JavaAPI文档是必不可少的. 一.java.lang包下的API Java常 ...

  5. C++ 中超类化和子类化常用API

    在windows平台上,使用C++实现子类化和超类化常用的API并不多,由于这些API函数的详解和使用方法,网上一大把.本文仅作为笔记,简单的记录一下. 子类化:SetWindowLong,GetWi ...

  6. node.js整理 02文件操作-常用API

    NodeJS不仅能做网络编程,而且能够操作文件. 拷贝 小文件拷贝 var fs = require('fs'); function copy(src, dst) { fs.writeFileSync ...

  7. js的常用api

    JavaScript常用API总结 原创 2016-10-02 story JavaScript 下面是我整理的一些JavaScript常用的API清单. 目录 元素查找 class操作 节点操作 属 ...

  8. JS操作DOM常用API总结

    <JS高程>中的DOM部分写的有些繁琐,还没勇气整理,直到看到了这篇博文 Javascript操作DOM常用API总结,顿时有了一种居高临下,一览全局的感觉.不过有时间还是得自己把书里面的 ...

  9. request对象常用API 获取请求参数的值 request应用 MVC设计模式

    1 request对象常用API   1)表示web浏览器向web服务端的请求   2)url表示访问web应用的完整路径:http://localhost:8080/day06/Demo1     ...

  10. 【OpenGL游戏开发之二】OpenGL常用API

    OpenGL常用API 开发基于OpenGL的应用程序,必须先了解OpenGL的库函数.它采用C语言风格,提供大量的函数来进行图形的处理和显示.OpenGL库函数的命名方式非常有规律.所有OpenGL ...

随机推荐

  1. 【目标检测】Fast R-CNN算法实现

    一.前言 2014年,Ross Girshick提出RCNN,成为目标检测领域的开山之作.一年后,借鉴空间金字塔池化思想,Ross Girshick推出设计更为巧妙的Fast RCNN(https:/ ...

  2. elmentui表单重置初始值问题与解决方法

    背景 在做管理台项目时,我们会经常使用到表单+表格+弹窗表单的组合,以完成对数据的增.删.查.改. 在vue2+elementui项目中,使用弹窗dialog+表单form,实现对数据的添加和修改. ...

  3. Q-REG论文阅读

    Q-REG Jin, S., Barath, D., Pollefeys, M., & Armeni, I. (2023). Q-REG: End-to-End Trainable Point ...

  4. 前端设计模式:工厂模式(Factory)

    00.基础概念 工厂模式封装了对象的创建new(),将消费者(使用)和生产者(实现)解耦. 工厂是干什么的?工厂是生产标准规格的商品的地方,建好工厂,投入原料(参数),产出特定规格的产品.so,工厂模 ...

  5. 低代码平台如何借助Nginx实现网关服务

    摘要:本文由葡萄城技术团队于博客园原创并首发.转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 前言 在典型的系统部署架构中,应用服务器是一种软件或硬件系统, ...

  6. PostgreSQL学习笔记-4.基础知识:空值NULL、别名AS

    NULL 值代表遗漏的未知数据. 默认地,表的列可以存放 NULL 值. 本章讲解 IS NULL 和 IS NOT NULL 操作符. 语法 当创建表时,NULL 的基本语法如下: CREATE T ...

  7. 使用Arduino制作摩尔斯电码收发器

    摩尔斯电码通过不同的排列顺序来表达不同的英文字母.数字和标点符号等.在今天,国际摩尔斯电码依然被使用着.比如,摩尔斯电码最广为人知的用法发送求救信号SOS,SOS信号的组合方式为:.再比如,假设我们通 ...

  8. 【BUU刷题日记】--第二周

    [BUU刷题日记]--第二周 一.[WUSTCTF2020]朴实无华 1 目录爆破 使用dirsearch扫描发现没有结果,因为如果dirsearch请求过快则会导致超出服务器最大请求,扫描不出本来可 ...

  9. 使用 Ant Design Vue 你可能会遇到的14个问题

    公司有一个新需求,在原来项目基础上开发,项目中使用 Ant Design Vue,版本是 1.X ,在此记录下遇到的问题:对于没有使用过或者使用程度不深的同学来说,希望可以帮助你在开发中遇到问题时有个 ...

  10. Unity Yaml文本标量处理

    在做脱离unity处理unity的yaml文档的工具(prefab.material等) unity使用的yaml是YAML的语法子集,主要难点在处理文本标量上,如果用工具修改以后和unity生成的格 ...