凡事都在事上磨,这样才能精进,成长进步提高! ------ 博客园首页

ES 基本操作

0.查看集群是否健康
GET /_cluster/health

1.查询所有索引
GET /_cat/indices?v

 

2.查询单个索引的映射
GET /index_trans_detail/_mapping


3.删除index
DELETE /index_trans_detail,index_two

4. 添加字段映射
PUT /index_trans_detail/_mapping/type_trans_detail
{
"properties": {
"tags":{
"type": "text"
}
}
}


5. 索引的别名
5.1 创建索引的别名
PUT /index_trans_detail/_alias/index_trans_detail_alias

5.2 查询索引的别名
GET /index_trans_detail/_alias/*

5.3 查询别名指向哪一个索引
GET /*/_alias/index_trans_detail_alias

5.4 删除别名
DELETE /index_trans_detail/_alias/index_trans_detail_alias


6. 添加一个索引(通过mapping)
PUT /people
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  },
  "mappings": {
    "man": {
      "dynamic": "strict",
      "properties": {
        "name": {
          "type": "text"
        },
        "age": {
          "type": "integer"
        },
        "birthday": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
        },
        "address":{
          "dynamic": "true",
          "type": "object"
        }
      }
    }
  }
}
"dynamic": "strict"  表示如果遇到陌生field会报错
"dynamic": "true"   表示如果遇到陌生字段,就进行dynamic mapping
"dynamic": "false"   表示如果遇到陌生字段,就忽略

 

7.修改字段可以排序
PUT index_trans_detail/_mapping/activity_dictionary
{
"properties": {
"type_code":{
"type": "text",
"fielddata": true
}
}
}

7.1 添加字段
PUT /index_trans_detail/_mapping/type_trans_detail
{
"properties": {
"tags":{
"type": "text"
}
}
}

 

通过别名更换索引
==========================================================
8.创建别名
POST _aliases
{
"actions": [
{
"add": {
"index": "old_index",
"alias": "old_index_alias"
}
}
]
}

9.将老的索引中的数据复制到新的索引中:
POST _reindex
{
"source": {
"index": "old_index"(老的索引名)
},
"dest": {
"index": "new_index"(新的索引名)
}
}


10,创建映射
POST _aliases
{
"actions": [
{
"remove": {
"index": "old_index",
"alias": "old_index_alias"
}},
{
"add": {
"index": "new_index",
"alias": "old_index_alias"
}
}
]
}

11.删除旧索引
DELETE old_index

posted @   追风fc  阅读(2743)  评论(0编辑  收藏  举报
编辑推荐:
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示