关于elasticsearch:elasticsearch别名VS索引名称

2次阅读

共计 1333 个字符,预计需要花费 4 分钟才能阅读完成。

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"}
    }
  }
}
正文完
 0