zoukankan      html  css  js  c++  java
  • elasticsearch 管理常用命令集合

    elasticsearch rest api遵循的格式为:

    curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>

    1、检查es版本信息

    curl IP:9200

    2、查看集群是否健康

    http://IP:9200/_cat/health?v
    curl -s -XGET 'http://IP:9200/_cat/health?v'
    1 绿色,最健康的状态,代表所有的分片包括备份都可用
    2 黄色,预警状态,所有主分片功能正常,但至少有一个副本是不能正常工作的。此时集群是可以正常工作的,但是高可用性在某种程度上会受影响。
    3 红色,集群不可正常使用。某个或某些分片及其副本异常不可用,这时集群的查询操作还能执行,但是返回的结果会不准确。对于分配到这个分片的写入请求将会报错,最终会导致数据的丢失。 

    3、查看节点列表

    http://IP:9200/_cat/nodes?v
    curl 'IP:9200/_cat/nodes?v'

    4、列出所有索引及存储大小

    http://IP:9200/_cat/indices?v
    curl 'IP:9200/_cat/indices?v'--查询所有索引及数据大小

    5、创建索引

    创建索引名为XX,默认会有5个分片,1个索引
    curl -XPUT 'IP:9200/XX?pretty'

    6、添加一个类型

    curl -XPUT 'IP:9200/XX/external/2?pretty' -d '
    {
       "gwyy": "John"
    }'

    7、更新一个类型

    curl -XPOST 'IP:9200/XX/external/1/_update?pretty' -d '
    {
       "doc": {"name": "Jaf"}
    }'

    8、删除指定索引

    curl -XDELETE 'IP:9200/_index?pretty' 

    9、ES数据定期删除

    如果不删除ES数据,将会导致ES存储的数据越来越多,磁盘满了之后将无法写入新的数据。这时可以使用脚本定时删除过期数据。

    #/bin/bash
    #es-index-clear
    #只保留15天内的日志索引
    LAST_DATA=`date -d "-15 days" "+%Y.%m.%d"`
    #删除上个月份所有的索引(根据自己的所有格式编写)
    curl -XDELETE 'http://ip:port/*-'${LAST_DATA}'*'
    

    crontab -e添加定时任务:每天的凌晨一点清除索引。

    0 1 * * * /search/odin/elasticsearch/scripts/es-index-clear.sh

    10、查看分片状态

    curl -XGET http://localhost:9200/_cat/shards

    11、查看群集状态

    curl -s -XGET 'http://localhost:9200/_cluster/stats?pretty'

    12、索引管理

    查询全部索引状态
    curl 'localhost:9200/_cat/indices?v'
    查询状态为red的索引
    curl -s -XGET 'http://IP:9200/_cat/indices?health=red

    13、创建索引

    curl -XPUT 'localhost:9200/goods_v1?pretty' 

    14、查看索引

    curl '172.31.15.228:9200/goods_v1?pretty'

    15、删除索引

    curl -XDELETE 'localhost:9200/goods_v1?pretty'

    16、优化索引

    curl -XPOST "http://127.0.0.1:9200/logstash-2015.10.28/_optimize"
    
    curl -XGET 'http://localhost:9200/logstash-2015.10.28/_search?pretty=true' -d '
    {
        "query" : {
            "matchAll" : {}
        }
    }' 

    索引刷新

    curl -XPOST 'http://127.0.0.1:9200/index_name/_refresh'  #单个索引刷新
    curl -XPOST 'http://127.0.0.1:9200/_refresh'             #全部索引刷新
    

    flush释放该索引所占用的内存,并将索引数据保存在磁盘

    curl -XPOST 'http://127.0.0.1:9200/index_name/_flush?force'
    

    清理缓存

    curl  -XPOST 'http://127.0.0.1:9200/_cache/clear'

      

    17、创建别名

    curl -XPOST localhost:9200/_aliases -d '
    {
        "actions": [
            { "add": {
                "alias": "goods",
                "index": "goods_v1"
            }}
        ]
    }'

    18、删除并更新别名

    curl -XPOST 'http://localhost:9200/_aliases' -d '
    {
        "actions" : [
            { "remove" : { "index" : "goods_v2", "alias" : "goods" } },
            { "add" : { "index" : "goods_v1", "alias" : "goods" } }
        ]
    }'

    19、查看已有别名

    curl -XGET 'localhost:9200/_cat/aliases'

    20、查看别名对应的索引

    curl -XGET 'localhost:9200/_alias/help'
    

    21、查看文件描述符打开数量

    curl -s -XGET '127.0.0.1:9200/_nodes/stats/process/?pretty'

    22、查看分片状态

    curl -XGET "http://127.0.0.1:9200/_cat/shards"
    

    23、查看热点线程 

    curl -XGET 'http://127.0.0.1:9200/_nodes/hot_threads'
    

    24、针对不使用的index,进行close。我们需要的时候再进行open,可以节约内存和减轻系统的压力

    curl -XPOST 127.0.0.1:9200/index_name/_close 
    curl -XPOST 127.0.0.1:9200/index_name/_open 25 18520796770

    25、查看线程状态

    curl -XGET "http://127.0.0.1:9200/_nodes/thread_pool/"
    

      

  • 相关阅读:
    一、left
    padding溢出
    一、
    Python创建、删除桌面、启动组快捷方式的例子分享
    openstack常见问题解决方法总结
    __attribute__ 详解
    __ATTRIBUTE__ 知多少?
    CentOS如何设置终端显示字符界面区域的大小
    shell使用技巧
    openstack 安全策略权限控制等api接口
  • 原文地址:https://www.cnblogs.com/zhangan/p/11338310.html
Copyright © 2011-2022 走看看