一、原索引

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "create_date": {
          "type":   "date",
          "format": "yyyy-MM-dd ||yyyy/MM/dd"
           
        }
      }
    }
  }
}

二、创建新索引

PUT my_index2
{
  "mappings": {
    "_doc": {
      "properties": {
        "create_date": {
          "type":   "text"
           
        }
      }
    }
  }
}

三、同步数据

POST _reindex                   
{
  "source": {
    "index": "my_index"
  },
  "dest": {
    "index": "my_index2"
  }
}

四、删除原索引

DELETE my_index

五、设置别名

POST /_aliases
  {
        "actions": [
            {"add": {"index": "my_index2", "alias": "my_index"}}
        ]
  }

遇到问题:
PUT my_index2 的时候,mapping没有自动生成,需要自己手动创建mapping:

先创建空的索引:

PUT /my_index2
{
}

再创建mapping:

POST /sku_vec_32_sync2/_doc/_mapping?pretty&include_type_name=true
{
    "_doc": {
      "properties": {
        "vec": {
          "type": "dense_vector",
          "dims": 32
        }
      }
}

}

这里要加include_type_name=true,有的版本高的 es 会判断,否则会报错误:

Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.