ES2: elasticsearch 索引index

安装请看: https://www.cnblogs.com/abel-he/p/11071778.html

1、查看健康命令:

GET _cat/health

status: green/yellow/red

  green: 每个索引的primary shard和replica shard 都是active的

  yellow: 每个索引的primary shard都是active的,部分replica shard不是active的

  red: 不是所有的primary shard都是active的

2、检查分片信息 (需要有索引才能看出效果)

GET _cat/shards?v

health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size

yellow open   test_index yu5HjAt0RS-qSFtrCj-emQ   5   1          0            0      1.1kb          1.1kb

3、设置磁盘限制

PUT _cluster/settings
{
  "transient": {
    "cluster.routing.allocation.disk.watermark.low": "85%",
    "cluster.routing.allocation.disk.watermark.high": "90%"
  }
}

  

注意:配置磁盘空间限制的时候,要求low必须比high大。可以使用百分比或gb的方式设置。且ES要求low至少满足磁盘95%的容量。

此处配置的百分比都是磁盘的使用百分比,如85%,代表磁盘使用了85%后如何限制。配置的GB绝对值都是剩余空间多少。

low - 对磁盘空闲容量的最低限制。默认85%

high - 对磁盘空闲容量的最高限制。默认90%

如:low50gbhigh10gb。则当磁盘空闲容量不足50gb时停止分配replica shard。当磁盘空闲容量不足10gb时,停止分配shard,并将应该在当前结点中分配的shard分配到其他结点中。

强调:red问题。因为ESprimary shard是主分片,要求必须全部活动才能正常使用。

4、查看索引信息

GET _cat/indices?v

health  status   index          uuid                          pri  rep   docs.count   docs.deleted       store.size        pri.store.size

green    open     test_index   2PJFQBtzTwOUhcy-QjfYmQ   5    1          0          0             460b           460b

5、新增索引

PUT /test_index1
{
  "settings": {
    "number_of_shards": 2,  // 主分片
    "number_of_replicas": 1 // 每个主分片对应的备份分片
  }
}

ES中,默认的创建索引的时候,会分配5primary shard,并为每个primary shard分配一个replica shard。在ES中,默认的限制是:如果磁盘空间不足15%的时候,不分配replica shard。如果磁盘空间不足5%的时候,不再分配任何的primary shard

6、修改索引

注意:索引一旦创建、primary shard 数量不可改变、可以改变replica shard数量

 

PUT test_index1/_settings
{
  "number_of_replicas":2
}

 

ES中对shard的分布是有要求的。有其内置的特殊算法。ES尽可能保证primary shard平均分布在多个节点上。Replica shard会保证不和他备份的那个primary shard分配在同一个节点上。

7、删除索引

 

DELETE test_index

 

8、总结

  索引不可变的原因是倒排索引不可变

  8.1 倒排索引不变的好处:

    不需要锁,提升并发能力,避免锁问题。数据不变,可以缓存在OS cache中(前提是cache足够大)。filter cache始终在内存中,因为数据是不可变的。可以通过压缩技术来节省CPUIO的开销。

  8.2 倒排索引不可变的坏处:

    倒排索引不可变,导致ES中中的index不可变,只要index的结构发生任何变化,都必须重建索引。

 

 

          

 

posted @ 2020-08-17 16:51  译林  阅读(339)  评论(0编辑  收藏  举报