ES不提供修改索引字段类型的操作,只能新建索引再将数据同步过去。

  1. 原索引

    PUT old_index
    {
      "mappings": {
        "_doc": {
          "properties": {
            "create_date": {
              "type": "data",
              "format": "yyy-MM-dd ||yyyy/MM/dd"
            }
          }
        }
      }
    }
    
  2. 新索引

    PUT new_index
    {
      "mappings": {
        "_doc": {
          "properties": {
            "create_date": {
              "type": "text"
            }
          }
        }
      }
    }
    
  3. 同步数据

    POST _reindex
    {
      "source": {
        "index": "old_index"
      },
      "dest": {
        "index": "new_index"
      }
    }
    
  4. 查询索引

    GET new_index/_search
    
  5. 删除原索引

    DELETE old_index
    
  6. 设置别名

    POST /_aliases
    {
      "actions": [
        {
          "add": {
            "index": "new_index",
            "alias": "old_index"
          }
        }
      ]
    }