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. k8s添加节点报[WARNING SystemVerification]: missing optional cgroups: blkio

    环境信息: ubuntu-master01  192.1681.195.128 ubuntu-work01    192.168.195.129 k8s版本 1.25.2 背景描述:初始环境是一个ma ...

  2. Machine Learning for NetFlow Anomaly Detection With Human-Readable Annotations 笔记

    Machine Learning for NetFlow Anomaly Detection With Human-Readable Annotations 关键摘要 我们开发了一个复杂企业网络中的异 ...

  3. JS深入学习笔记 - 第三章.变量作用域与内存

    1.原始值和引用值 ECMScript变量包含两种不同类型是数据:原始值和引用值. 原始值:最简单的数据.有6中原始值:Undefined.Null.Boolean.Number.String和Sym ...

  4. 【稳定性】关于缩短MTTR的探索

    一.什么是 MTTR ? 当系统出现系统故障时,我们需要通过一些指标来衡量故障的严重程度和影响范围.其中MTTR(Mean Time To Repair 名为_平均修复时间_)是一个非常重要的指标,它 ...

  5. c语言代码练习3改进

    #define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> int main() { int x = 0; printf("请输入一 ...

  6. Django——后台添加的用户密码错误

    django项目中,当我们创建了user模型类,并生成了超级管理员,之后我们进入到admin后台页面中,添加一个用户,再去login页面登陆时,会提示我们 用户名或密码错误. 这时,我们第一时间会想到 ...

  7. 自研、好用、够快、稳定、代码可读性强的ORM

    Fast Framework 作者 Mr-zhong 代码改变世界.... 一.前言 Fast Framework 基于NET6.0 封装的轻量级 ORM 框架 支持多种数据库 SqlServer O ...

  8. Atcoder Regular Contest 167

    卡 B 下大分了. A. Toasts for Breakfast Party 发现题意是让方差尽可能小,就是让 \(A\) 里的值尽可能接近. 所以从小到大排个序,把 \(A_{N,\dots,N- ...

  9. 【实践篇】一次Paas化热部署实践分享

    前言 本文是早些年,Paas化刚刚提出不久时,基于部门内第一次Paas化热部署落地经验所写,主要内容是如何构建一些热部署代码以及一些避雷经验. 一.设计-领域模型设计 1.首先,确定领域服务所属的领域 ...

  10. Util应用框架基础(七) - 缓存

    本节介绍Util应用框架如何操作缓存. 概述 缓存是提升性能的关键手段之一. 除了提升性能,缓存对系统健壮性和安全性也有影响. 不同类型的系统对缓存的依赖程度不同. 对于后台管理系统,由于是给管理人员 ...