查看集群健康状态

  1. curl -XGET http://ip|hostname:http_port/_cluster/health?pretty

查看集群数据完整性,其中返回active_shards_percent至为分片数据恢复的百分比,非数据量大小

  1. curl -XGET ip|hostname:http_port/_cat/health?v

查看集群信息

  1. curl 'ip|hostname:http_port/_cat/nodes?v&h=n,ip,r,m,http,port'

查看分片信息

  1. curl -XGET http://ip|hostname:http_port/_cat/shards

查询单个节点分片分配情况

  1. curl -XGET 'http://ip|hostname:http_port/_cat/allocation?v&pretty'

查询分片未分配原因

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

查看集群是否在做recovery

  1. curl --silent 'ip|hostname:http_port/_recovery?human&detailed=true&pretty&filter_path=*.shards.start_time'

Recovery是指将一个索引的shard分配到另外一个节点的过程。 在快照恢复,更改索引复制片数量,结点故障或者结点启动时发生。Recovery过程要消耗CPU、内存、结点之间的网络带宽等额外的资源,有可能会导致集群的服务能力降级,或者一部分功能暂时不可用。

修改指定模板下索引副本数分片数

  1. curl -H "Content-Type: application/json" -XPUT ip|hostname:http_port/_template/temName -d '{"index_patterns": ["indexName"],"settings": {"index": {"number_of_shards": "Num","number_of_replicas": "Num"}}}'

6.0版本之后使用使用index_patterns替代了template作为指定索引的key
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/breaking_60_indices_changes.html#breaking_60_indices_changes

索引

打开关闭

  1. curl -XPOST ip|hostname:http_port/{indexName}/_close
  2. curl -XPOST ip|hostname:http_port/{indexName}/_open

创建删除

  1. curl -X PUT "ip|hostname:http_port/indexName" -H 'Content-Type: application/json' -d'
  2. {
  3. "settings" : {
  4. "index" : {
  5. "number_of_shards" : 3,
  6. "number_of_replicas" : 2
  7. }
  8. }
  9. }
  10. curl -X DELETE "ip|hostname:http_port/indexName"

清理缓存

指定单个索引

  1. curl -XPOST 'http://localhost:9200/indexName/_cache/clear'

全部索引

  1. curl -XPOST 'http://localhost:9200/_cache/clear'
  2. curl -H "Content-Type: application/json" -XPOST 'http://localhost:9200/_cache/clear' -d '{ "fielddata": "true" }'

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html

修改已创建索引配置

  1. curl -XPUT 'localhost:9200/dtlog-1-tdx_pc-forever-2017.10.16-000001/_settings' -H 'Content-Type: application/json' -d '{"index" : {"refresh_interval" : "120s"}}'
  2. for i in `curl -s localhost:9200/_cat/indices?h=i |grep 2019 |grep tdx`;do curl -XPUT localhost:9200/$i/_settings -H 'Content-Type: application/json' -d '{"index" : {"refresh_interval" : "120s"}}' ; done
  1. curl -XPUT localhost:9200/$i/_settings -H 'Content-Type: application/json' -d '{"index.translog": {"durability": "async","sync_interval": "30s"}}'
  1. for i in `curl -s localhost:9200/_cat/indices?h=i |grep 2019 |grep tdx`;do curl -XPOST localhost:9200/$i/_close;done
  2. for i in `curl -s localhost:9200/_cat/indices?h=i |grep 2019 |grep tdx`;do curl -XPUT localhost:9200/$i/_settings -H 'Content-Type: application/json' -d '{"index.translog": {"durability": "async","sync_interval": "30s"}}';done
  3. for i in `curl -s localhost:9200/_cat/indices?h=i |grep 2019 |grep tdx`;do curl -XPOST localhost:9200/$i/_open;done

修改指定索引副本数

  1. for i in `curl http://10.129.82.129:9200/_cat/indices?h=i | grep 06.04`;do curl -XPUT http://10.129.82.129:9200/$i/_settings -H "Content-Type: application/json" -d '{
  2. "settings" : {
  3. "index" : {
  4. "number_of_replicas" : 0
  5. }
  6. }
  7. }' ; done

将指定索引重新路由到cold节点

  1. for i in `curl http://10.129.82.129:9200/_cat/indices?h=i | grep 06.04`;do curl -H "Content-Type: application/json" -XPUT http://10.129.82.129:9200/$i/_settings -d '{"index.routing.allocation.require.box_type":"cold"}';done