索引index常用操作

手动创建索引:
// 语法:
PUT /索引名
{
    index的配置(primary shard的数量等)
}


// 例子(不带配置信息的话以默认配置创建)【请不要复制这个注释!】
PUT /product

// 例子(带配置信息的话以配置信息创建)【请不要复制这个注释!】
PUT /product
{
    "settings":{
        "index":{
            "number_of_shards":3,
            "number_of_replicas":1
          }
     }
}


查看单个索引
语法:
GET /索引名

例子:
GET /product


查看所有索引,命令:
GET /_cat/indices?v


删除索引
语法:
DELETE /索引名

同时删除多个索引,以逗号分割,如 
DELETE /testindex1,testindex2


修改副本分片数量例子:
PUT /product/_settings
{
  "index":{
    "number_of_replicas":2
  }
}


关闭索引:
POST /索引名/_close


打开索引:
POST /索引名/_open


增加索引别名:
语法:
POST /_aliases
{
    "actions":[
        {
            "add":{
                "index":"索引名",
                "alias":"索引别名"
            }
        }
    ]
}


例子:
POST /_aliases
{
  "actions":[
    {
      "add":{
        "index":"product",
        "alias":"pdt"
      }
    }
    ]
}



查看索引别名:
方法一:通过查看索引来查看索引别名:
GET /product

方式二:
GET /product/_alias


删除索引别名:
语法:
POST /_aliases
{
    "actions":[
        {
            "remove":{
                "index":"索引名",
                "alias":"索引别名"
            }
        }
    ]
}

例子:
POST /_aliases
{
  "actions":[
    {
      "remove":{
        "index":"product",
        "alias":"pdt"
      }
    }
    ]
}

 

posted @ 2025-09-04 11:04  屠魔的少年  阅读(6)  评论(0)    收藏  举报