美文网首页
es修改索引数据类型

es修改索引数据类型

作者: 愤愤的有痣青年 | 来源:发表于2020-07-16 17:29 被阅读0次

    es中是不允许对索引修改,所以只有先创建一个新索引,将旧索引数据移动到新索引中,然后再删除旧索引,再将新索引的数据迁移到旧索引名下,操作方式如下:

    # 删除原有的template
    DELETE _template/app_template
    
    # 创建新template
    POST _template/app_template
    {
      "index_patterns": [
        "app-*"
      ],
      "settings": {
        "number_of_shards": 5,
        "refresh_interval": "60s"
      },
      "mappings": {
        "_source": {
          "enabled": true
        },
        "properties": {
          "time": {
            "type": "long"
          },
          "element": {
            "properties": {
              "element_id": {
                "type": "keyword"
              }
            }
          },
          "uuid": {
            "type": "keyword"
          },
          "app_user_id": {
            "type": "keyword"
          },
          "event_type": {
            "type": "keyword"
          },
          "event_name": {
            "type": "keyword"
          },
          "path": {
            "type": "keyword"
          },
          "sdk_version": {
            "type": "integer"
          },
          "app_verison": {
            "type": "keyword"
          }
        }
      }
    }
    
    # 创建新索引
    PUT /app-9e66e6c0-new
    
    # 将旧索引迁移到新索引下
    POST /_reindex
    {
      "source": {
        "index": "app-9e66e6c0"
      },
      "dest": {
        "index": "app-9e66e6c0-new"
      }
    }
    
    # 删除旧索引
    DELETE /app-9e66e6c0
    
    # 将新索引数据迁移到旧索引名下
    POST /_reindex
    {
      "source": {
        "index": "app-9e66e6c0-new"
      },
      "dest": {
        "index": "app-9e66e6c0"
      }
    }
    
    # 删除新索引
    DELETE /app-9e66e6c0-new
    
    # 查看索引结构
    GET app-9e66e6c0
    

    相关文章

      网友评论

          本文标题:es修改索引数据类型

          本文链接:https://www.haomeiwen.com/subject/schmhktx.html