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. Python 潮流周刊#21:如何提升及测量 Python 代码的性能?

    你好,我是猫哥.这里每周分享优质的 Python.AI 及通用技术内容,大部分为英文.标题取自其中三则分享,不代表全部内容都是该主题,特此声明. 本周刊由 Python猫 出品,精心筛选国内外的 25 ...

  2. 【Redis】SpringBoot集成Redis事务-亲测

    大家好,我是mep.今天一起来探讨一下Redis缓存的问题,SpringBoot如何集成Redis网上文章很多,基本都是介绍如何配置redisTemplate,如何调用,本文就不过多介绍了.这次我们研 ...

  3. Abp vNext 模块加载机制

    文章目录 生命周期 PreConfigureServices 添加依赖注入或者其它配置之前 ConfigureServices 添加依赖注入或者其它配置 PostConfigureServices 添 ...

  4. Destoon模板存放及调用规则

    一.模板存放及调用规则 模板存放于系统 template 目录,template 目录下的一个目录例如 template/default/ 即为一套模板模板文件以 .htm 为扩展名,可直接存放于模板 ...

  5. Factors 分解质因数

    package com.yourself.yours; import java.util.Scanner; /** ****************************************** ...

  6. 使用Docker buildx 为 .NET 构建多平台镜像

    .NET 团队有一篇博客 改进多平台容器支持, 详细介绍了.NET 7 以上的平台可以轻松的使用Docker buildx 工具构建多平台的镜像. buildx 是 Docker 官方提供的一个构建工 ...

  7. Linux CMake编译kwindowsystem错误汇总

    1.APPSTREAMCLI-NOTFOUND 安装appstream apt-get install appstream 2.FISH_EXECUTABLE 安装fish apt-get insta ...

  8. js执行过程之上下文对象(Context)

    在js的学习中,我们已经不满足于仅了解js的基础知识,而是开始追求更深层次的学习.因为你会发现,仅了解js的基础知识,在开发项目的过程中是远远不够的.今天就来介绍一下在js执行过程中的一些相关内容了. ...

  9. NanoPI常用命令

    更新 sudo apt-get update 安装 CURL sudo apt install curl

  10. Gmail如何开启SMTP/POP

    1. 登录Gmail账号,右上角点击设置图标 -> 查看所有设置,如图 2. 点击"转发和POP/IMAP",如图 3. 开启IMAP和POP,选择"对所有邮件启用 ...