ES详解 - 索引:索引管理详解

索引管理的引入

PUT /customer/_doc/1
{
  "name": "John Doe"
}

而这个index实际上已经自动创建了它里面的字段(name)的类型。我们不妨看下它自动创建的mapping:

{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    }
  }
}

第一个禁止自动创建索引,第二个是手动创建索引。

  • 禁止自动创建索引
    vi config/elasticsearch.yml
action.auto_create_index: false

索引的格式

在请求体里面传入设置或类型映射,如下所示:

PUT /my_index
{
    "settings": { ... any settings ... },
    "mappings": {
        "properties": { ... any properties ... }
    }
}
  • settings: 用来设置分片,副本等配置信息
  • mappings: 字段映射,类型等

索引管理操作

创建索引

PUT /test-index-users
{
  "settings": {
		"number_of_shards": 1,
		"number_of_replicas": 1
	},
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "age": {
        "type": "long"
      },
      "remarks": {
        "type": "text"
      }
    }
  }
}

修改索引

修改副本为0

PUT /test-index-users/_settings
{
  "settings": {
    "number_of_replicas": 0
  }
}

打开/关闭索引

  • 关闭索引

一旦索引被关闭,那么这个索引只能显示元数据信息,不能够进行读写操作。
POST /test-index/_close

  • 开启索引

POST /test-index/_open

删除索引

DELETE /test-index

查看索引

  • 查看mapping

GET /index/_mapping

  • 查看setting

GET /index/_setting

  • 查看所有

GET /index

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值