Elasticsearch 常用命令 总结

做了近半年的公司ES集群维护及开发,开始转入别的项目组,所有对曾经的这段技术使用 做个总结,主要是一些运维经验,还有常用命令!

常见问题(FAQ)

1、集群Red

首先查看集群所在机器进程是否还在(jps),如果不存在则启动所有进程,如果存在则查看日志是否存在GC事件过长导致集群不可用

2、集群存在未分配shard,手动执行命令触发分片移动

参考:https://www.jianshu.com/p/2bb42eb49515

3、集群节点cpu 使用率过高

参考:https://www.jianshu.com/p/a930fa53764d

4、微服务 sql 查询出错

首先查看插件是否安装 http://ip:port/_plugin/sql,如果看不到sql 查询界面说明么有安装插件不支持sql 查询,如果存在则直接执行sql查看执行结果

5、根据时间范围查不出数据

首先查看日志是否有报错信息,然后根据查询字段时间格式与mapping 中定义格式是否一致

ES 涉及集群问题 看日志!看日志!看日志 三遍

常用命令(请替换自定义端口)

1、查看集群健康状态

curl -XGET hostname -i:9200/_cluster/health?pretty

curl -XGET hostname -i:9200/_cat/health?v

curl -XGET hostname -i:9200/_cluster/health?pretty

2、查看索引级别健康状态

curl -XGET hostname -i:9200/_cluster/health?level=indices

3、查看集群设置

curl -XGET hostname -i:9200/_settings

curl -XGET  hostname -i:9200/_cluster/settings

4、查看节点信息

curl -XGET hostname -i:9200/_cat/nodes?v

curl -XGET hostname -i:9200/_cluster/health?level=shards'

curl -XGET hostname -i:9200/_cat/allocation?v

5、创建索引指定分片副本

curl -XPUT hostname -i -H 'Content-Type: application/json' -d'

{

   "settings" : {

      "number_of_shards" : 3,

      "number_of_replicas" : 1

   }

}

'

6、删除索引

curl -XDELETE hostname -i:9200/test

7、索引文档

curl -XPUT hostname -i:9200/test/article/10 -H 'Content-Type: application/json' -d'

{

    "first_name" : "simon",

    "last_name" :  "Smith",

    "age" :        23,

    "hello" :        "world",

    "note" :        "2018-12-12",

    "about" :      "洪荒之力",

    "interests": [ "sports", "music" ]

}

'

8、修改副本分片

curl -XPUT hostname -i:9200/test/_settings -H 'Content-Type: application/json' -d'

{

  "number_of_replicas": 0

}'

9、查看索引设置

curl -XGET hostname -i:9200/blogs/_settings?pretty

10、查看索引下所有文档

curl -XGET hostname -i:9200/blogs/_search

curl -XPOST hostname -i:9200/bank/_search?pretty -d '

{

    "query": { "match_all": {} }

}

'

11、修改集群exclude节点,persistent 重启后仍生效

curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'

{

  "persistent": {

    "cluster.routing.allocation.exclude._name":"node-name"

  }

}'

12、修改集群exclude节点,transient 立即生效,重启失效

curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'

{

  "transient": {

    "cluster.routing.allocation.exclude._name":"node-name"

  }

}'

13、修改集群exclude IP

curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'

{

  "transient": {

    "cluster.routing.allocation.exclude._ip":"your_ip"

  }

}'

14、查询并删除es5.x 后版本支持

curl -XPOST hostname -i:9200/blogs/_delete_by_query -H 'Content-Type: application/json' -d'

{

  "query":{

    "term": {

      "age": {

        "value": 22

      }

    }

  }

}'

15、查看所有模板

curl -XGET hostname -i:9200/_template

16、查看特定模板

curl -XGET hostname -i:9200/_template/template_1 

17、删除特定模板

 

curl -XDELETE hostname -i:9200/_template/template_1

18、创建特定模板

curl -XPUT  hostname -i:9200/_template/template_1 -d '

{

    "template" : "zhouls*",

    "order" : 0,

    "settings" : {

        "number_of_shards" : 1

    },

    "mappings" : {

        "type1" : {

            "_source" : { "enabled" : false }

        }

    }

}

'

19、清除缓存索引

curl -XPOST hostname -i:9200/test/_cache/clear

20、查询索引别名

curl -XGET hostname -i:9200/_cat/aliases

21、新建索引别名

curl -XPOST hostname -i:9200/_aliases -H 'Content-Type: application/json' -d'

{

  "actions": [

    {

      "add": {

        "index": "search4policy_health_20181220000000",

        "alias": "search4policy_health_current_reader"

      }

    }

  ]

}'

22、删除别名

  curl -XPOSThostname -i:9200/_aliases -d '

    {

        "actions": [

            {"remove": {"index": "test1", "alias": "alias1"}}

        ]

    }'

23、获取未分配分片

curl -XGET hostname -i:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason | grep UNASSIGNED

24、设置索引刷新间隔

curl -XPUT hostname -i:9200/blogs/_settings -H 'Content-Type: application/json' -d'

{

  "refresh_interval": "30s"

}'

25、关闭索引

curl -XPOST hostname -i:9200/zipkin-2019*/_close

26、打开索引

curl -XPOST hostname -i:9200/subao-benefit*/_open

27、查看进行中的任务

curl -XGET hostname -i:9200/_cat/pending_tasks

28、查看线程池执行状态

curl -XGET hostname -i:9200/_cat/thread_pool?v&h=ip,bulk.rejected,search.rejected

29、查看安装插件

curl -XGET hostname -i:9200/_cat/plugins

30、执行sql 语句

curl -XPOST hostname -i:9200/_sql -d 'SELECT * FROM audit'

31、查看 es 节点连接数

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

32、查看集群 mlockall 参数设置

curl -X GET `hostname -i`:9200/_nodes?filter_path=**.mlockall&pretty

33、查看集群file_descriptor
curl -X GET `hostname -i`:9200/_nodes/stats/process?filter_path=**.max_file_descriptors&pretty


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 今天看到一位朋友写的mysql笔记总结,觉得写的很详细很用心,这里转载一下,供大家参考下,也希望大家能关注他原文地...
    信仰与初衷阅读 10,179评论 0 30
  • ORA-00001: 违反唯一约束条件 (.) 错误说明:当在唯一索引所对应的列上键入重复值时,会触发此异常。 O...
    我想起个好名字阅读 10,984评论 0 9
  • Zookeeper用于集群主备切换。 YARN让集群具备更好的扩展性。 Spark没有存储能力。 Spark的Ma...
    Yobhel阅读 12,128评论 0 34
  • 1.ElasticSearch的简介 Elasticsearch的特点 1)可以作为一个大型分布式集群(数百台服务...
    __元昊__阅读 31,118评论 3 30
  • 开篇 Elasticsearch以下简称ES,接下来ES将从几个方面进行解释: 1.ES是什么? 2....
    lji_jl阅读 9,962评论 1 3

友情链接更多精彩内容