Elasticsearch重建索引

Elasticsearch重建索引,第1张

Elasticsearch重建索引 概述

很多情况下,Elasticsearch是需要重建索引的. 比如主分片数量想修改,加了keyword类型等.

*** 作步骤
1.首先创建一个新索引,结构一致
PUT /myindex_new
{
  "settings": {
    "number_of_shards": 2
    , "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "name":{
        "type": "keyword"
      },
      "age":{
        "type": "long"
      }
    }
  }
}

2.数据迁移
POST /_reindex?wait_for_completion=false
{
  "source": {
    "index": "myindex"
  },
  "dest": {
    "index": "myindex_new"
  }
}

3.删除老索引
DELETE myindex

3.给新索引加别名
POST _aliases 
{
  "actions": [
    {
      "add": {
        "index": "myindex_new",
        "alias": "myindex"
      }
    }
  ]
}
效果


索引名称已经变成myindex_new,为了不影响程序使用,使用别名myindex


name字段改成keyword,已经支持折叠了(collapse)

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5716908.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存