首页 > 其他分享 >elastic常用api

elastic常用api

时间:2024-01-05 17:55:21浏览次数:23  
标签:常用 http elastic -- ip cluster api curl port

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": "[email protected]",
                    "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": "[email protected]",                                      "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": "[email protected]",
                    "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": "[email protected]",                                      "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"}}}'
    

标签:常用,http,elastic,--,ip,cluster,api,curl,port
From: https://www.cnblogs.com/pengliblogs/p/17947768

相关文章

  • ChatGPT的中转站 oupuapi,不扶墙也能上楼
    我们在建类似chatgpt聊天站点的时候,只需对服务器进行扶墙代理,便可实现访问。那么我们只需要往深里想一下,不要让整个服务器去访问VPN,而是基于API的代理,或者说API的中转站也就孕育而生了——我不是做产品的,找了一下找到了oupo.top/register?aff=xDgB。TextGenerator中使......
  • 支持API文档生成,API管理工具:Apipost
    随着数字化转型的加速,API(应用程序接口)已经成为企业间沟通和数据交换的关键。而在API开发和管理过程中,API文档、调试、Mock和测试的协作显得尤为重要。Apipost正是这样一款一体化协作平台,旨在解决这些问题,提高API开发效率和质量。Apipost提供API文档管理功能,让后端开发人员可以在开......
  • Springboot 2.7 open api:swagger | knife4j | spring doc
    *[集成SpringDoc接口文档和knife4j|SpringBoot2.7.2实战基础-掘金](https://juejin.cn/post/7201195677128687674)*[Springboot2.7集成Swagger增强版接口框架Knife4j4.3+springdocOpenApi3.0\_knife4jspringboot2.7-CSDN博客](https://blog.csdn.net/Mrqi......
  • 支持API文档生成,API管理工具:Apipost
    随着数字化转型的加速,API(应用程序接口)已经成为企业间沟通和数据交换的关键。而在API开发和管理过程中,API文档、调试、Mock和测试的协作显得尤为重要。Apipost正是这样一款一体化协作平台,旨在解决这些问题,提高API开发效率和质量。 Apipost提供API文档管理功能,让后端开发人员可......
  • 【开源项目】发现一款商业级的免费开源电子合同电子签章、电子合同SDK、电子合同API、
    Mini-Contract......
  • 解决Django Elastic Beanstalk与RDS MySQL连接问题
    根据错误消息,问题在于您的ElasticBeanstalk环境中缺少MySQL配置。这可能是由于缺少所需的软件包或依赖项导致的。解决此问题的步骤如下:在您的项目根目录中创建一个名为.ebextensions的文件夹。在.ebextensions文件夹中创建一个名为packages.config的文件,并在其......
  • Vue中使用API内容渲染的弹出列表的打开方式
    要在Vue中实现点击链接打开一个弹出窗口,你可以按照以下步骤进行操作:首先,为每个链接添加一个点击事件处理程序。你可以使用@click指令来做到这一点。在你的模板中的链接元素上添加该指令,如下所示:<av-for="iinitems"v-bind:key="i.id"class="biblio__item"@click=......
  • Maven基础入门​及与IDEA的集成(下)常用命令、生命周期及与IDEA集成
    Maven基础入门Maven常用命令compile:编译在项目的根目录打开cmd窗口,运行mvncompile命令,Maven即开始进行自动编译项目。Maven会自动开始下载依赖项,然后进行源码的编译,并将生成的编译文件存入target文件中。clean:清理mvnclean命令会清除compile时生成的target文件夹。test:测试自......
  • 数据工程实践:从网络抓取到API调用,解析共享单车所需要的数据
    设想这样一个案例,当前共享单车应用广泛,在很多城市都有大量的投放,一方面解决了人们的短途快速出行问题,一方面对环境保护做出了贡献。但对于单车公司来说,如何确保单车投放在人们需要的地方?大量的共享单车聚集在市中心,且在雨雪等恶劣天气,人们又不会使用。这正是数据工程师可以发挥作用......
  • 常用的 Linux 系统备份、恢复命令
    tar命令使用tar命令备份副本(本机备份整个系统,以后还原还是还原到本机)注意根目录下要有充足的可用空间用于备份。cd/#tar.gz格式tarcvpzfsystem_backup.tar.gz/--exclude=/proc--exclude=/lost+found--exclude=/system_backup.tar.gz--exclude=/mnt--exclude=/sys#tar......