elasticsearch别名VS索引名称

ElasticSearch常用命令
场景:随着项目版本迭代,导致ES索引结构也会跟着变动,而ES又没有重命名这一说,所以每次修改索引结构原有字段就需要重新建索引,然后再做数据迁移。

如果直接使用索引名称,在做数据迁移的时候会变得很繁琐,可以看我上篇文章,这么繁琐的步骤操作起来就容易出错。而如果使用ES别名,直接操作别名就方便很多了。

#查看所有索引
GET _cat/indices
{}

#查看索引结构
GET live_new/_mapping
{}

#查看指定索引别名
GET live_new/_alias/*
{
}
GET live_new/_mapping
{}

#给索引添加别名
POST /_aliases
{
    "actions": [
       { "add":{ "index": "live_new", "alias": "datacube_live" }}
    ]
}

POST _reindex
{
  "source": {
    "index": "live"
  },
  "dest": {
    "index": "live_new"
  }
}

#移除就索引添加新索引
POST /_aliases
{
    "actions": [
        { "remove": { "index": "live_new", "alias": "datacube_live" }},
        { "add":    { "index": "live_new_v2", "alias": "datacube_live" }}
    ]
}

PUT live_new
{
  "mappings": {
    "properties": {
      "room_id": {
        "type": "keyword"
      },
      "room_name": {
        "type": "text",
        "analyzer": "ik_max_word",
        "search_analyzer": "ik_smart"
      },
      "shop_ids": {
        "type": "keyword"
      },
      "live_date": {
        "type": "keyword"
      },
      "start_time": {
        "type": "keyword"
      },
      "end_time": {
        "type": "keyword"
      },
      "goods_list": {
        "type": "nested",
        "properties": {
          "goods_id": {
            "type": "keyword"
          },
          "goods_name": {
            "type": "text"
          },
          "sku_code": {
            "type": "keyword"
          },
          "category_id": {
            "type": "keyword"
          },
          "activity_type": {
            "type": "keyword"
          },
          "lecture_type": {
            "type": "keyword"
          },
          "area_ids": {
            "type": "keyword"
          }
        }
      },
      "is_empty": {
        "type": "boolean"
      },
      "is_callback": {
        "type": "boolean"
      },
      "is_pal_15": {
        "type": "boolean"
      },
      "creator_id": {
        "type": "keyword"
      },
      "push_type": {
        "type": "keyword"
      },
      "create_at": {
        "type": "keyword"
      },
      "is_del": {
        "type": "boolean"
      }
    }
  }
}

你可能感兴趣的:(elasticsearch)