创建索引
创建索引的时候可以通过修改number_of_shards和number_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
返回:
{
"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。
本文详细介绍了如何在Elasticsearch中创建、修改、获取和开关索引,包括通过设置number_of_shards和number_of_replicas参数来调整索引的分片和副本数量,以及使用特定API进行索引的更新和状态切换。
2194

被折叠的 条评论
为什么被折叠?



