elasticsearch常用的一些集群命令

查看集群健康状态

get请求
/_cat/health?v

epoch      timestamp cluster status node.total node.data shards     pri             relo  init  unassign  pending_tasks  max_task_wait_time  active_shards_percent
1543918646 18:17:26  haha-elk yellow    1         1       3481      3481             0    0     3480             0                  -                 50.0%
时间戳     utc时间   集群名称 集群状态 总的节点数 储存节点 分片数量 复制分片数量 

主要讲下 status
集群的状态有三种 green,yellow,red
- green 集群状态健康完善
- yellow 所有数据可用,但没有副本,当我们是单点集群的时候,我们就是yellow状态
- red   某些数据由于某种原因不可用。

查看集群的节点列表

get请求
/_cat/nodes?v
通过这个命令我们可以查看我们集群中有几个节点

ip        heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1           72          89   9    0.23    0.26     0.21 mdi       *      haha-elastic-1
地址     堆所占百分比  内存使用的百分比 cpu 负载 1分钟 2分钟 15分钟(top)  是否为主节点     节点名称

查看所有的索引

get请求
/_cat/indices?V

health   status index                                 uuid                   pri    rep         docs.count      docs.deleted    store.size      pri.store.size
yellow   open   ljf-order-service-2018-10-04          XhIN9cfFTO6ZaGLg4Ucuog   5    1            2874                0          1.1mb            1.1mb
yellow   open   ljf-account-service-2018-11-01        1NXXkKZnSxub5quXwNQqUQ   5    1            7603                0          2.4mb            2.4mb

健康状态 状态   索引名称                               id                    主分片 一个副本(默认值) 文档数量      删除文档的数量    大小          副本大小



您可能还注意到客户索引标记了黄色运行状况。回想一下我们之前的讨论,黄色表示某些副本尚未(尚未)分配。此索引发生这种情况的原因是因为默认情况下Elasticsearch为此索引创建了一个副本。由于我们目前只有一个节点在运行,因此在另一个节点加入集群的较晚时间点之前,尚无法分配一个副本(用于高可用性)。将该副本分配到第二个节点后,此索引的运行状况将变为绿色。

删除索引

get请求
XDELETE  /'索引名称'?pretty

删除成功返回值
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size

查询索引的某个文档内容

get请求
 /indexname/type/id

indexname  ---> 索引名称 示例:l1-online-h5-service-2018-12-05

type       ---> 文档类型 (一般为doc)

id         ---> id值

image

更新文档

elasticsearch  更新文档的时候是会删除旧的文档,给新的文档编制索引。

POST  /indexname/type/id/_update?pretty
{
  "doc": { "name": "Jane Doe" }
}

删除文档

DELETE /indexname/type/id?pretty

查看分片的分布和里面文档的大小

get 请求
/_cat/shards?v

返回内容解析

index(索引名称)                      shard(分片位置)   prirep(主分片还是副本) state(状态)    docs(文档数量)    store(储存大小) ip(节点地址)           node(节点名称)
ljf-online-user-service-2018-11-13    2                  p                      STARTED          4189            2.1mb         172.16.2.208         djx-elastic-1
ljf-online-user-service-2018-11-13    2                  r                      STARTED          4189            2.1mb         172.16.2.209         djx-elastic-2
ljf-online-user-service-2018-11-13    3                  p                      STARTED          4172            2.1mb         172.16.2.208         djx-elastic-1
ljf-online-user-service-2018-11-13    3                  r                      STARTED          4172            2.1mb         172.16.2.209         djx-elastic-2
ljf-online-user-service-2018-11-13    1                  p                      STARTED          4110            2.1mb         172.16.2.208         djx-elastic-1

截止LUCENE-5843,最大文档数限制是2,147,483,519(= Integer.MAX_VALUE – 128)文档。

自动创建索引

elasticsearch.yml 下的action.auto_create_index
默认是开启的,如果我们需要关闭的话,我们需要允许x-apck去创建索引。
添加以下内容:

action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*,.ml*

版权声明:本文为operationhome原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/operationhome/p/10097724.html