• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

ElasticSearch 修改字段类型 _reindex

武飞扬头像
擅长憋尿_
帮助1

  • 在日常开发中,可能会疏忽而未指定字段类型,而es会默认根据插入的数据去映射有可能不符合你期望的类型,从而导致后续的某些问题。由于ElasticSearch不支持直接修改字段类型, 因此需要借助中间索引并搭配_reindex来重新索引数据

操作步骤

  1. 创建中间索引
  2. 设置中间索引_mapping
  3. _reindex 重新索引数据
  4. 删除有问题的旧索引
  5. 重新创建同名新索引(_mapping中字段类型正确)
  6. _reindex 中间索引数据至新索引
  7. 删除中间索引

# 创建中间索引
PUT asr_202203_back/

# 创建Mapping
POST asr_202203_back/asr/_mapping
{
  "asr": {
    "_source": {
      "enabled": true
    },
    "properties": {
      "callId": {
        "type": "keyword"
      },
      "fileName": {
        "type": "keyword"
      },
      "level": {
        "type": "integer"
      },
      "enterpriseId": {
        "type": "integer"
      },
      "tag": {
        "type": "keyword"
      },
      "taskId": {
        "type": "keyword"
      }
    }
  }
}

# 向中间索引备份源索引的数据
# 重建索引
POST _reindex
{
  "source": {
    "index": "asr_202203"
  },
  "dest": {
    "index": "asr_202203_back"
  }
}

GET /asr_202203_back/_search

# 删除有问题的索引
DELETE asr_202203

# 重新创建同名的索引
# 创建索引
PUT asr_202203/

# 创建Mapping
POST asr_202203/asr/_mapping
{
  "asr": {
    "_source": {
      "enabled": true
    },
    "properties": {
      "callId": {
        "type": "keyword"
      },
      "fileName": {
        "type": "keyword"
      },
      "level": {
        "type": "integer"
      },
      "enterpriseId": {
        "type": "integer"
      },
      "tag": {
        "type": "keyword"
      },
      "taskId": {
        "type": "keyword"
      }
    }
  }
}

# 从中间索引还原到源索引的数据
# 重建索引
POST _reindex
{
  "source": {
    "index": "asr_202203_back"
  },
  "dest": {
    "index": "asr_202203"
  }
}
# 查询验证是否正确
GET asr_202203_alias/_search
GET asr_202203_alias/_mapping

# 删除中间索引
DELETE asr_202203_back
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhggfjjg
系列文章
更多 icon
同类精品
更多 icon
继续加载