索引设置

索引初始化操作

创建索引之前可以对索引做初始化操作

比如指定shards数量以及replicas的数量

  1. PUT /library
  2. {
  3. "settings" : {
  4. "index" : {
  5. "number_of_shards" : 3,
  6. "number_of_replicas" : 2
  7. }
  8. }
  9. }
  10. # 上面的number_of_replicas还可以换成:
  11. # blocks.read_only: 设为true,则当前索引只允许读,不允许写或更新
  12. # blocks.read : 设为true,则禁止读操作
  13. # blocks.write: 设为true,则禁止写操作设置
  14. # blocks.metadata: 设为true,则禁止对metadata操作

查询配置信息

可以通过GET带上参数_settings可以获得该索引详细的配置信息

GET /library/_settings
# 这种也可以查看索引是否存在
HEAD /library

同时获取2个索引信息

GET /library,blog/_settings

获取所有的索引信息

GET /_all/_settings

查看索引分配情况

GET /_cat/indices?v

image.png
health健康状态

  • 绿色:索引的所有分片都正常分配。
  • 黄色:至少有一个副本没有得到正确的分配。
  • 红色:至少有一个主分片没有得到正确的分配。

status是索引打开状态

开/关索引

关闭的索引就不能用来搜索了

POST /索引名称/_open

# 返回
{
  "acknowledged" : true,
  "shards_acknowledged" : true
}
POST /索引名称/_close

删除索引

DELETE /索引名称1,索引名称2,索引名称3...