Elasticsearch--索引管理

创建索引

创建索引的时候可以通过修改number_of_shardsnumber_of_replicas参数的数量来修改分片和副本的数量。再默认情况下分片的数量是5个,副本的数量是1个。

例如:

PUT /myindex/
{
  "settings": {
    "index": {
      "number_of_shards": 3,
      "number_of_replicas": 2
    }
  }
}

GET _cat/indices

在这里插入图片描述

修改索引

可以通过update-index-settingsAPI完成对索引的修改。
例如:

PUT /myindex/_settings
{
  "number_of_replicas": 1
}

在这里插入图片描述

获取索引

获取索引接口允许从一个或多个索引中获取信息。
例如:

GET /myindex/

返回:

{
  "myindex": {
    "aliases": {},
    "mappings": {},
    "settings": {
      "index": {
        "creation_date": "1583836099378",
        "number_of_shards": "3",
        "number_of_replicas": "1",
        "uuid": "DR5uuEYMStiqpFtQ4hK8tA",
        "version": {
          "created": "5060899"
        },
        "provided_name": "myindex"
      }
    }
  }
}

打开/关闭索引

打开/关闭索引接口允许关闭一个打开的索引,或打开一个已经关闭的索引。关闭的索引只能显示索引元数据信息,不能够进行读写操作。

打开/关闭索引的方式是:

/{索引名}/_clost或者/{索引名}/_open

示例:关闭索引

POST /myindex/_close

返回:

扫描二维码关注公众号,回复: 10018429 查看本文章
{
  "acknowledged": true
}

示例:打开索引

POST /myindex/_open

返回:

{
  "acknowledged": true
}

注意:可以同时打开或关闭多个索引。如果指向不存在的索引会抛出错误。可以使用配置:

ignore_unavailavle=true

压制异常。

全部索引可以使用_all打开或者关闭,或者使用通配符表示全部(*)。

设置config/elasticsearch.yml属性action.destructive_requires_name为true,禁止使用通配符或者_all标识索引。

关闭的索引会继续占用磁盘空间而不能使用,所以关闭索引接口可能造成磁盘空间的浪费。

禁止使用关闭索引功能,可以设置settingscluster.indices.close.enable为false,默认为true。

发布了842 篇原创文章 · 获赞 2256 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/cold___play/article/details/104780092
今日推荐